@@ -101,10 +101,10 @@ def __init__(self, host,
101
101
:type paramiko_kwargs: dict
102
102
"""
103
103
try :
104
- host , _user , _port , _pkey = read_openssh_config (
104
+ _host , _user , _port , _pkey = read_openssh_config (
105
105
host , config_file = _openssh_config_file )
106
106
except TypeError :
107
- host , _user , _port , _pkey = host , None , 22 , None
107
+ _host , _user , _port , _pkey = None , None , 22 , None
108
108
user = user if user else _user
109
109
client = paramiko .SSHClient ()
110
110
client .set_missing_host_key_policy (paramiko .MissingHostKeyPolicy ())
@@ -115,6 +115,7 @@ def __init__(self, host,
115
115
self .pkey = pkey if pkey else _pkey
116
116
self .port = port if port else _port
117
117
self .host = host
118
+ self ._host = _host
118
119
self .allow_agent = allow_agent
119
120
if agent :
120
121
self .client ._agent = agent
@@ -125,15 +126,16 @@ def __init__(self, host,
125
126
self .proxy_password , self .proxy_pkey = proxy_host , proxy_port , \
126
127
proxy_user , proxy_password , proxy_pkey
127
128
self .proxy_client = None
129
+ real_host = _host if _host is not None else host
128
130
if self .proxy_host and self .proxy_port :
129
131
logger .debug (
130
132
"Proxy configured for destination host %s - Proxy host: %s:%s" ,
131
- self . host , self .proxy_host , self .proxy_port ,)
132
- self ._connect_tunnel (** paramiko_kwargs )
133
+ real_host , self .proxy_host , self .proxy_port ,)
134
+ self ._connect_tunnel (real_host , ** paramiko_kwargs )
133
135
else :
134
- self ._connect (self .client , self . host , self .port , ** paramiko_kwargs )
136
+ self ._connect (self .client , real_host , self .port , ** paramiko_kwargs )
135
137
136
- def _connect_tunnel (self , ** paramiko_kwargs ):
138
+ def _connect_tunnel (self , host , ** paramiko_kwargs ):
137
139
"""Connects to SSH server via an intermediate SSH tunnel server.
138
140
client (me) -> tunnel (ssh server to proxy through) ->
139
141
``self.host`` (ssh server to run command)
@@ -148,20 +150,20 @@ def _connect_tunnel(self, **paramiko_kwargs):
148
150
user = self .proxy_user , password = self .proxy_password ,
149
151
pkey = self .proxy_pkey , ** paramiko_kwargs )
150
152
logger .info ("Connecting via SSH proxy %s:%s -> %s:%s" , self .proxy_host ,
151
- self .proxy_port , self . host , self .port ,)
153
+ self .proxy_port , host , self .port ,)
152
154
try :
153
155
proxy_channel = self .proxy_client .get_transport ().open_channel (
154
- 'direct-tcpip' , (self . host , self .port ,), ('127.0.0.1' , 0 ),
156
+ 'direct-tcpip' , (host , self .port ,), ('127.0.0.1' , 0 ),
155
157
timeout = self .timeout )
156
158
sleep (0 )
157
- return self ._connect (self .client , self . host , self .port ,
159
+ return self ._connect (self .client , host , self .port ,
158
160
sock = proxy_channel ,
159
161
** paramiko_kwargs )
160
162
except (ChannelException , paramiko .SSHException ) as ex :
161
163
error_type = ex .args [1 ] if len (ex .args ) > 1 else ex .args [0 ]
162
164
raise ConnectionErrorException (
163
165
"Error connecting to host '%s:%s' - %s" ,
164
- self . host , self .port , str (error_type ))
166
+ host , self .port , str (error_type ))
165
167
166
168
def _connect (self , client , host , port , sock = None , retries = 1 ,
167
169
user = None , password = None , pkey = None ,
@@ -177,6 +179,7 @@ def _connect(self, client, host, port, sock=None, retries=1,
177
179
:raises: :py:class:`pssh.exceptions.SSHException` on other undefined
178
180
SSH errors
179
181
"""
182
+ logger .debug ("Connecting to %s.." , host )
180
183
try :
181
184
client .connect (host ,
182
185
username = user if user else self .user ,
@@ -199,7 +202,7 @@ def _connect(self, client, host, port, sock=None, retries=1,
199
202
self .num_retries )
200
203
except sock_error as ex :
201
204
logger .error ("Error connecting to host '%s:%s' - retry %s/%s" ,
202
- self . host , self .port , retries , self .num_retries )
205
+ host , self .port , retries , self .num_retries )
203
206
while retries < self .num_retries :
204
207
sleep (5 )
205
208
return self ._connect (client , host , port ,
@@ -209,7 +212,7 @@ def _connect(self, client, host, port, sock=None, retries=1,
209
212
error_type = ex .args [1 ] if len (ex .args ) > 1 else ex .args [0 ]
210
213
raise ConnectionErrorException (
211
214
"Error connecting to host '%s:%s' - %s - retry %s/%s" ,
212
- self . host , self .port , str (error_type ), retries ,
215
+ host , self .port , str (error_type ), retries ,
213
216
self .num_retries ,)
214
217
except paramiko .AuthenticationException as ex :
215
218
msg = "Authentication error while connecting to %s:%s."
0 commit comments