@@ -48,7 +48,8 @@ def __init__(self, host,
4848 allow_agent = True , timeout = 10 , proxy_host = None ,
4949 proxy_port = 22 , proxy_user = None , proxy_password = None ,
5050 proxy_pkey = None , channel_timeout = None ,
51- _openssh_config_file = None ):
51+ _openssh_config_file = None ,
52+ ** paramiko_kwargs ):
5253 """
5354 :param host: Hostname to connect to
5455 :type host: str
@@ -95,6 +96,9 @@ def __init__(self, host,
9596 :param allow_agent: (Optional) set to False to disable connecting to
9697 the SSH agent
9798 :type allow_agent: bool
99+ :param paramiko_kwargs: (Optional) Extra keyword arguments to be
100+ passed on to :py:func:`paramiko.client.SSHClient.connect`
101+ :type paramiko_kwargs: dict
98102 """
99103 try :
100104 host , _user , _port , _pkey = read_openssh_config (
@@ -125,11 +129,11 @@ def __init__(self, host,
125129 logger .debug (
126130 "Proxy configured for destination host %s - Proxy host: %s:%s" ,
127131 self .host , self .proxy_host , self .proxy_port ,)
128- self ._connect_tunnel ()
132+ self ._connect_tunnel (** paramiko_kwargs )
129133 else :
130- self ._connect (self .client , self .host , self .port )
134+ self ._connect (self .client , self .host , self .port , ** paramiko_kwargs )
131135
132- def _connect_tunnel (self ):
136+ def _connect_tunnel (self , ** paramiko_kwargs ):
133137 """Connects to SSH server via an intermediate SSH tunnel server.
134138 client (me) -> tunnel (ssh server to proxy through) ->
135139 ``self.host`` (ssh server to run command)
@@ -142,7 +146,7 @@ def _connect_tunnel(self):
142146 paramiko .MissingHostKeyPolicy ())
143147 self ._connect (self .proxy_client , self .proxy_host , self .proxy_port ,
144148 user = self .proxy_user , password = self .proxy_password ,
145- pkey = self .proxy_pkey )
149+ pkey = self .proxy_pkey , ** paramiko_kwargs )
146150 logger .info ("Connecting via SSH proxy %s:%s -> %s:%s" , self .proxy_host ,
147151 self .proxy_port , self .host , self .port ,)
148152 try :
@@ -151,15 +155,17 @@ def _connect_tunnel(self):
151155 timeout = self .timeout )
152156 sleep (0 )
153157 return self ._connect (self .client , self .host , self .port ,
154- sock = proxy_channel )
158+ sock = proxy_channel ,
159+ ** paramiko_kwargs )
155160 except (ChannelException , paramiko .SSHException ) as ex :
156161 error_type = ex .args [1 ] if len (ex .args ) > 1 else ex .args [0 ]
157162 raise ConnectionErrorException (
158163 "Error connecting to host '%s:%s' - %s" ,
159164 self .host , self .port , str (error_type ))
160165
161166 def _connect (self , client , host , port , sock = None , retries = 1 ,
162- user = None , password = None , pkey = None ):
167+ user = None , password = None , pkey = None ,
168+ ** paramiko_kwargs ):
163169 """Connect to host
164170
165171 :raises: :py:class:`pssh.exceptions.AuthenticationException`
@@ -172,18 +178,22 @@ def _connect(self, client, host, port, sock=None, retries=1,
172178 SSH errors
173179 """
174180 try :
175- client .connect (host , username = user if user else self .user ,
181+ client .connect (host ,
182+ username = user if user else self .user ,
176183 password = password if password else self .password ,
177184 port = port , pkey = pkey if pkey else self .pkey ,
178185 sock = sock , timeout = self .timeout ,
179- allow_agent = self .allow_agent )
186+ allow_agent = self .allow_agent ,
187+ ** paramiko_kwargs )
180188 except sock_gaierror as ex :
181189 logger .error ("Could not resolve host '%s' - retry %s/%s" ,
182190 host , retries , self .num_retries )
183191 while retries < self .num_retries :
184192 sleep (5 )
185- return self ._connect (client , host , port , sock = sock ,
186- retries = retries + 1 )
193+ return self ._connect (client , host , port ,
194+ sock = sock ,
195+ retries = retries + 1 ,
196+ ** paramiko_kwargs )
187197 raise UnknownHostException ("Unknown host %s - %s - retry %s/%s" ,
188198 host , str (ex .args [1 ]), retries ,
189199 self .num_retries )
@@ -192,8 +202,10 @@ def _connect(self, client, host, port, sock=None, retries=1,
192202 self .host , self .port , retries , self .num_retries )
193203 while retries < self .num_retries :
194204 sleep (5 )
195- return self ._connect (client , host , port , sock = sock ,
196- retries = retries + 1 )
205+ return self ._connect (client , host , port ,
206+ sock = sock ,
207+ retries = retries + 1 ,
208+ ** paramiko_kwargs )
197209 error_type = ex .args [1 ] if len (ex .args ) > 1 else ex .args [0 ]
198210 raise ConnectionErrorException (
199211 "Error connecting to host '%s:%s' - %s - retry %s/%s" ,
@@ -234,9 +246,6 @@ def exec_command(self, command, sudo=False, user=None,
234246 being where a shell is not used and/or stdout/stderr/stdin buffers
235247 are not required. Defaults to ``True``
236248 :type use_pty: bool
237- :param kwargs: (Optional) Keyword arguments to be passed to remote
238- command
239- :type kwargs: dict
240249 :rtype: Tuple of `(channel, hostname, stdout, stderr, stdin)`.
241250 Channel is the remote SSH channel, needed to ensure all of stdout has
242251 been got, hostname is remote hostname the copy is to, stdout and
0 commit comments