@@ -37,12 +37,16 @@ def get_ssh_client(self, asset, system_user):
3737 ssh = paramiko .SSHClient ()
3838 ssh .set_missing_host_key_policy (paramiko .AutoAddPolicy ())
3939 sock = None
40+ error = ''
4041
4142 if not system_user .password and not system_user .private_key :
4243 self .get_system_user_auth (system_user )
4344
4445 if asset .domain :
4546 sock = self .get_proxy_sock_v2 (asset )
47+ if not sock :
48+ error = 'Connect gateway failed;'
49+ logger .error (error )
4650
4751 try :
4852 try :
@@ -81,9 +85,9 @@ def get_ssh_client(self, asset, system_user):
8185 system_user .username , asset .ip , asset .port ,
8286 password_short , key_fingerprint ,
8387 ))
84- return None , None , str (e )
88+ return None , None , error + ' \n ' + str (e )
8589 except (socket .error , TimeoutError ) as e :
86- return None , None , str (e )
90+ return None , None , error + ' \n ' + str (e )
8791 return ssh , sock , None
8892
8993 def get_transport (self , asset , system_user ):
@@ -126,9 +130,9 @@ def get_proxy_sock_v2(asset):
126130 password = gateway .password ,
127131 pkey = gateway .private_key_obj ,
128132 timeout = config ['SSH_TIMEOUT' ])
129- except (paramiko .AuthenticationException ,
130- paramiko .BadAuthenticationType ,
131- SSHException ):
133+ except (paramiko .AuthenticationException ,
134+ paramiko .BadAuthenticationType ,
135+ SSHException , socket . error ):
132136 continue
133137 sock = ssh .get_transport ().open_channel (
134138 'direct-tcpip' , (asset .ip , asset .port ), ('127.0.0.1' , 0 )
0 commit comments