mirror of https://github.com/docker/docker-py.git
Merge pull request #2755 from aiordache/fix_ssh_bug
Fix host trimming and remove quiet flag for the ssh connection
This commit is contained in:
commit
d7b16ef0fb
|
@ -29,26 +29,33 @@ class SSHSocket(socket.socket):
|
||||||
socket.AF_INET, socket.SOCK_STREAM)
|
socket.AF_INET, socket.SOCK_STREAM)
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = None
|
self.port = None
|
||||||
|
self.user = None
|
||||||
if ':' in host:
|
if ':' in host:
|
||||||
self.host, self.port = host.split(':')
|
self.host, self.port = host.split(':')
|
||||||
|
if '@' in self.host:
|
||||||
|
self.user, self.host = host.split('@')
|
||||||
|
|
||||||
self.proc = None
|
self.proc = None
|
||||||
|
|
||||||
def connect(self, **kwargs):
|
def connect(self, **kwargs):
|
||||||
port = '' if not self.port else '-p {}'.format(self.port)
|
args = ['ssh']
|
||||||
args = [
|
if self.user:
|
||||||
'ssh',
|
args = args + ['-l', self.user]
|
||||||
'-q',
|
|
||||||
self.host,
|
if self.port:
|
||||||
port,
|
args = args + ['-p', self.port]
|
||||||
'docker system dial-stdio'
|
|
||||||
]
|
args = args + ['--', self.host, 'docker system dial-stdio']
|
||||||
|
|
||||||
preexec_func = None
|
preexec_func = None
|
||||||
if not constants.IS_WINDOWS_PLATFORM:
|
if not constants.IS_WINDOWS_PLATFORM:
|
||||||
preexec_func = lambda: signal.signal(signal.SIGINT, signal.SIG_IGN)
|
def f():
|
||||||
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
preexec_func = f
|
||||||
|
|
||||||
self.proc = subprocess.Popen(
|
self.proc = subprocess.Popen(
|
||||||
' '.join(args),
|
' '.join(args),
|
||||||
|
env=os.environ,
|
||||||
shell=True,
|
shell=True,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stdin=subprocess.PIPE,
|
stdin=subprocess.PIPE,
|
||||||
|
@ -124,9 +131,6 @@ class SSHConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
|
||||||
if ssh_client:
|
if ssh_client:
|
||||||
self.ssh_transport = ssh_client.get_transport()
|
self.ssh_transport = ssh_client.get_transport()
|
||||||
self.ssh_host = host
|
self.ssh_host = host
|
||||||
self.ssh_port = None
|
|
||||||
if ':' in host:
|
|
||||||
self.ssh_host, self.ssh_port = host.split(':')
|
|
||||||
|
|
||||||
def _new_conn(self):
|
def _new_conn(self):
|
||||||
return SSHConnection(self.ssh_transport, self.timeout, self.ssh_host)
|
return SSHConnection(self.ssh_transport, self.timeout, self.ssh_host)
|
||||||
|
@ -169,7 +173,10 @@ class SSHHTTPAdapter(BaseHTTPAdapter):
|
||||||
self._create_paramiko_client(base_url)
|
self._create_paramiko_client(base_url)
|
||||||
self._connect()
|
self._connect()
|
||||||
|
|
||||||
self.ssh_host = base_url.lstrip('ssh://')
|
self.ssh_host = base_url
|
||||||
|
if base_url.startswith('ssh://'):
|
||||||
|
self.ssh_host = base_url[len('ssh://'):]
|
||||||
|
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.max_pool_size = max_pool_size
|
self.max_pool_size = max_pool_size
|
||||||
self.pools = RecentlyUsedContainer(
|
self.pools = RecentlyUsedContainer(
|
||||||
|
|
Loading…
Reference in New Issue