@@ -44,7 +44,8 @@ def __init__(self, host,
4444 pkey = None , forward_ssh_agent = True ,
4545 num_retries = DEFAULT_RETRIES , agent = None ,
4646 allow_agent = True , timeout = 10 , proxy_host = None ,
47- proxy_port = 22 , channel_timeout = None ,
47+ proxy_port = 22 , proxy_user = None , proxy_password = None ,
48+ proxy_pkey = None , channel_timeout = None ,
4849 _openssh_config_file = None ):
4950 """Connect to host honouring any user set configuration in ~/.ssh/config \
5051 or /etc/ssh/ssh_config
@@ -115,7 +116,9 @@ def __init__(self, host,
115116 self .num_retries = num_retries
116117 self .timeout = timeout
117118 self .channel_timeout = channel_timeout
118- self .proxy_host , self .proxy_port = proxy_host , proxy_port
119+ self .proxy_host , self .proxy_port , self .proxy_user , self .proxy_password , \
120+ self .proxy_pkey = proxy_host , proxy_port , proxy_user , \
121+ proxy_password , proxy_pkey
119122 self .proxy_client = None
120123 if self .proxy_host and self .proxy_port :
121124 logger .debug ("Proxy configured for destination host %s - Proxy host: %s:%s" ,
@@ -134,13 +137,14 @@ def _connect_tunnel(self):
134137 """
135138 self .proxy_client = paramiko .SSHClient ()
136139 self .proxy_client .set_missing_host_key_policy (paramiko .MissingHostKeyPolicy ())
137- self ._connect (self .proxy_client , self .proxy_host , self .proxy_port )
140+ self ._connect (self .proxy_client , self .proxy_host , self .proxy_port ,
141+ user = self .proxy_user , password = self .proxy_password ,
142+ pkey = self .proxy_pkey )
138143 logger .info ("Connecting via SSH proxy %s:%s -> %s:%s" , self .proxy_host ,
139144 self .proxy_port , self .host , self .port ,)
140145 try :
141- proxy_channel = self .proxy_client .get_transport ().\
142- open_channel ('direct-tcpip' , (self .host , self .port ,),
143- ('127.0.0.1' , 0 ))
146+ proxy_channel = self .proxy_client .get_transport ().open_channel (
147+ 'direct-tcpip' , (self .host , self .port ,), ('127.0.0.1' , 0 ))
144148 sleep (0 )
145149 return self ._connect (self .client , self .host , self .port , sock = proxy_channel )
146150 except ChannelException , ex :
@@ -149,7 +153,8 @@ def _connect_tunnel(self):
149153 self .host , self .port ,
150154 str (error_type ))
151155
152- def _connect (self , client , host , port , sock = None , retries = 1 ):
156+ def _connect (self , client , host , port , sock = None , retries = 1 ,
157+ user = None , password = None , pkey = None ):
153158 """Connect to host
154159
155160 :raises: :mod:`pssh.exceptions.AuthenticationException` on authentication error
@@ -158,20 +163,20 @@ def _connect(self, client, host, port, sock=None, retries=1):
158163 :raises: :mod:`pssh.exceptions.SSHException` on other undefined SSH errors
159164 """
160165 try :
161- client .connect (host , username = self .user ,
162- password = self .password , port = port ,
163- pkey = self .pkey ,
166+ client .connect (host , username = user if user else self .user ,
167+ password = password if password else self .password ,
168+ port = port , pkey = pkey if pkey else self .pkey ,
164169 sock = sock , timeout = self .timeout ,
165170 allow_agent = self .allow_agent )
166171 except sock_gaierror , ex :
167172 logger .error ("Could not resolve host '%s' - retry %s/%s" ,
168- self . host , retries , self .num_retries )
173+ host , retries , self .num_retries )
169174 while retries < self .num_retries :
170175 sleep (5 )
171176 return self ._connect (client , host , port , sock = sock ,
172177 retries = retries + 1 )
173178 raise UnknownHostException ("Unknown host %s - %s - retry %s/%s" ,
174- self . host , str (ex .args [1 ]), retries ,
179+ host , str (ex .args [1 ]), retries ,
175180 self .num_retries )
176181 except sock_error , ex :
177182 logger .error ("Error connecting to host '%s:%s' - retry %s/%s" ,
0 commit comments