@@ -48,7 +48,8 @@ def __init__(self, host,
48
48
allow_agent = True , timeout = 10 , proxy_host = None ,
49
49
proxy_port = 22 , proxy_user = None , proxy_password = None ,
50
50
proxy_pkey = None , channel_timeout = None ,
51
- _openssh_config_file = None ):
51
+ _openssh_config_file = None ,
52
+ ** paramiko_kwargs ):
52
53
"""
53
54
:param host: Hostname to connect to
54
55
:type host: str
@@ -95,6 +96,9 @@ def __init__(self, host,
95
96
:param allow_agent: (Optional) set to False to disable connecting to
96
97
the SSH agent
97
98
: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
98
102
"""
99
103
try :
100
104
host , _user , _port , _pkey = read_openssh_config (
@@ -125,11 +129,11 @@ def __init__(self, host,
125
129
logger .debug (
126
130
"Proxy configured for destination host %s - Proxy host: %s:%s" ,
127
131
self .host , self .proxy_host , self .proxy_port ,)
128
- self ._connect_tunnel ()
132
+ self ._connect_tunnel (** paramiko_kwargs )
129
133
else :
130
- self ._connect (self .client , self .host , self .port )
134
+ self ._connect (self .client , self .host , self .port , ** paramiko_kwargs )
131
135
132
- def _connect_tunnel (self ):
136
+ def _connect_tunnel (self , ** paramiko_kwargs ):
133
137
"""Connects to SSH server via an intermediate SSH tunnel server.
134
138
client (me) -> tunnel (ssh server to proxy through) ->
135
139
``self.host`` (ssh server to run command)
@@ -142,7 +146,7 @@ def _connect_tunnel(self):
142
146
paramiko .MissingHostKeyPolicy ())
143
147
self ._connect (self .proxy_client , self .proxy_host , self .proxy_port ,
144
148
user = self .proxy_user , password = self .proxy_password ,
145
- pkey = self .proxy_pkey )
149
+ pkey = self .proxy_pkey , ** paramiko_kwargs )
146
150
logger .info ("Connecting via SSH proxy %s:%s -> %s:%s" , self .proxy_host ,
147
151
self .proxy_port , self .host , self .port ,)
148
152
try :
@@ -151,15 +155,17 @@ def _connect_tunnel(self):
151
155
timeout = self .timeout )
152
156
sleep (0 )
153
157
return self ._connect (self .client , self .host , self .port ,
154
- sock = proxy_channel )
158
+ sock = proxy_channel ,
159
+ ** paramiko_kwargs )
155
160
except (ChannelException , paramiko .SSHException ) as ex :
156
161
error_type = ex .args [1 ] if len (ex .args ) > 1 else ex .args [0 ]
157
162
raise ConnectionErrorException (
158
163
"Error connecting to host '%s:%s' - %s" ,
159
164
self .host , self .port , str (error_type ))
160
165
161
166
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 ):
163
169
"""Connect to host
164
170
165
171
:raises: :py:class:`pssh.exceptions.AuthenticationException`
@@ -172,18 +178,22 @@ def _connect(self, client, host, port, sock=None, retries=1,
172
178
SSH errors
173
179
"""
174
180
try :
175
- client .connect (host , username = user if user else self .user ,
181
+ client .connect (host ,
182
+ username = user if user else self .user ,
176
183
password = password if password else self .password ,
177
184
port = port , pkey = pkey if pkey else self .pkey ,
178
185
sock = sock , timeout = self .timeout ,
179
- allow_agent = self .allow_agent )
186
+ allow_agent = self .allow_agent ,
187
+ ** paramiko_kwargs )
180
188
except sock_gaierror as ex :
181
189
logger .error ("Could not resolve host '%s' - retry %s/%s" ,
182
190
host , retries , self .num_retries )
183
191
while retries < self .num_retries :
184
192
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 )
187
197
raise UnknownHostException ("Unknown host %s - %s - retry %s/%s" ,
188
198
host , str (ex .args [1 ]), retries ,
189
199
self .num_retries )
@@ -192,8 +202,10 @@ def _connect(self, client, host, port, sock=None, retries=1,
192
202
self .host , self .port , retries , self .num_retries )
193
203
while retries < self .num_retries :
194
204
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 )
197
209
error_type = ex .args [1 ] if len (ex .args ) > 1 else ex .args [0 ]
198
210
raise ConnectionErrorException (
199
211
"Error connecting to host '%s:%s' - %s - retry %s/%s" ,
@@ -234,9 +246,6 @@ def exec_command(self, command, sudo=False, user=None,
234
246
being where a shell is not used and/or stdout/stderr/stdin buffers
235
247
are not required. Defaults to ``True``
236
248
:type use_pty: bool
237
- :param kwargs: (Optional) Keyword arguments to be passed to remote
238
- command
239
- :type kwargs: dict
240
249
:rtype: Tuple of `(channel, hostname, stdout, stderr, stdin)`.
241
250
Channel is the remote SSH channel, needed to ensure all of stdout has
242
251
been got, hostname is remote hostname the copy is to, stdout and
0 commit comments