mirror of https://github.com/openspug/spug
加入对proxycommand的支持
parent
4cb86923d6
commit
93728d8038
|
@ -1,6 +1,9 @@
|
||||||
|
#coding:utf-8
|
||||||
# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
|
# Copyright: (c) OpenSpug Organization. https://github.com/openspug/spug
|
||||||
# Copyright: (c) <spug.dev@gmail.com>
|
# Copyright: (c) <spug.dev@gmail.com>
|
||||||
# Released under the AGPL-3.0 License.
|
# Released under the AGPL-3.0 License.
|
||||||
|
from paramiko.config import SSHConfig
|
||||||
|
from paramiko.proxy import ProxyCommand
|
||||||
from paramiko.client import SSHClient, AutoAddPolicy
|
from paramiko.client import SSHClient, AutoAddPolicy
|
||||||
from paramiko.rsakey import RSAKey
|
from paramiko.rsakey import RSAKey
|
||||||
from paramiko.auth_handler import AuthHandler
|
from paramiko.auth_handler import AuthHandler
|
||||||
|
@ -10,7 +13,8 @@ from io import StringIO
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
import os
|
||||||
|
import io
|
||||||
|
|
||||||
def _finalize_pubkey_algorithm(self, key_type):
|
def _finalize_pubkey_algorithm(self, key_type):
|
||||||
if "rsa" not in key_type:
|
if "rsa" not in key_type:
|
||||||
|
@ -61,6 +65,15 @@ class SSH:
|
||||||
self.eof = 'Spug EOF 2108111926'
|
self.eof = 'Spug EOF 2108111926'
|
||||||
self.default_env = default_env
|
self.default_env = default_env
|
||||||
self.regex = re.compile(r'Spug EOF 2108111926 (-?\d+)[\r\n]?')
|
self.regex = re.compile(r'Spug EOF 2108111926 (-?\d+)[\r\n]?')
|
||||||
|
sock = None
|
||||||
|
ssh_config_file = os.path.expanduser("~/.ssh/config")
|
||||||
|
if os.path.exists(ssh_config_file):
|
||||||
|
ssh_config = SSHConfig()
|
||||||
|
with io.open(ssh_config_file, 'rt', encoding='utf-8') as f:
|
||||||
|
ssh_config.parse(f)
|
||||||
|
host_config = ssh_config.lookup(hostname)
|
||||||
|
if 'proxycommand' in host_config:
|
||||||
|
sock = ProxyCommand(host_config['proxycommand'])
|
||||||
self.arguments = {
|
self.arguments = {
|
||||||
'hostname': hostname,
|
'hostname': hostname,
|
||||||
'port': port,
|
'port': port,
|
||||||
|
@ -70,7 +83,9 @@ class SSH:
|
||||||
'timeout': connect_timeout,
|
'timeout': connect_timeout,
|
||||||
'allow_agent': False,
|
'allow_agent': False,
|
||||||
'look_for_keys': False,
|
'look_for_keys': False,
|
||||||
'banner_timeout': 30
|
'banner_timeout': 30,
|
||||||
|
'sock':sock
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -80,6 +95,7 @@ class SSH:
|
||||||
key.write_private_key(key_obj)
|
key.write_private_key(key_obj)
|
||||||
return key_obj.getvalue(), 'ssh-rsa ' + key.get_base64()
|
return key_obj.getvalue(), 'ssh-rsa ' + key.get_base64()
|
||||||
|
|
||||||
|
|
||||||
def get_client(self):
|
def get_client(self):
|
||||||
if self.client is not None:
|
if self.client is not None:
|
||||||
return self.client
|
return self.client
|
||||||
|
|
Loading…
Reference in New Issue