Skip to content

Commit d73d138

Browse files
Merge pull request #90 from jupierce/paramiko_pkey
Allow extra kwargs to be passed to the paramiko connect API
2 parents a6c97f8 + c2e7fb9 commit d73d138

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

ansible/rebuild_module.digest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
6c9feb2f7df50d4a35a72871aeedd8ee -
1+
9e833fc40f0df2adc63f97257898bc8c -

ansible/roles/openshift_client_python/library/openshift_client_python.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/openshift/base_verbs.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ def node_ssh_client(apiobj_node_name_or_qname=None,
13701370
connect_timeout=600,
13711371
through_client_host=True,
13721372
address_type_pref="ExternalDNS,ExternalIP,Hostname",
1373+
paramiko_connect_extras=None,
13731374
):
13741375
"""
13751376
Returns a paramiko ssh client connected to the named cluster node. The caller is responsible for closing the
@@ -1387,6 +1388,7 @@ def node_ssh_client(apiobj_node_name_or_qname=None,
13871388
unless overridden.
13881389
:param address_type_pref: Comma delimited list of node address types. Types will be tried in
13891390
the order specified.
1391+
:param paramiko_connect_extras: An optional dictionary of kwargs to pass to the underlying SSH client connection method.
13901392
:return: ssh_client which can be used as a context manager
13911393
"""
13921394

@@ -1437,9 +1439,11 @@ def node_ssh_client(apiobj_node_name_or_qname=None,
14371439
if not password:
14381440
password = cur_context().get_ssh_password()
14391441

1442+
paramiko_connect_extras = paramiko_connect_extras or {}
14401443
ssh_client.connect(hostname=address, port=port, username=username,
14411444
password=password, key_filename=key_filename,
1442-
timeout=connect_timeout, sock=host_sock)
1445+
timeout=connect_timeout, sock=host_sock,
1446+
**paramiko_connect_extras)
14431447

14441448
# Enable agent fowarding
14451449
paramiko.agent.AgentRequestHandler(ssh_client.get_transport().open_session())
@@ -1457,18 +1461,25 @@ def node_ssh_await(apiobj_node_name_or_qname=None,
14571461
key_filename=None,
14581462
auto_add_host=True,
14591463
through_client_host=True,
1460-
address_type_pref="ExternalDNS,ExternalIP,Hostname"):
1464+
address_type_pref="ExternalDNS,ExternalIP,Hostname",
1465+
paramiko_connect_extras=None
1466+
):
14611467
"""
14621468
Periodically attempts to connect to a node's ssh server.
1463-
:param apiobj_node_name_or_qname:
1464-
:param timeout_seconds:
1465-
:param port:
1466-
:param username:
1467-
:param password:
1468-
:param key_filename:
1469-
:param auto_add_host:
1470-
:param through_client_host:
1471-
:param address_type_pref:
1469+
:param apiobj_node_name_or_qname: The name of the node or the apiobject representing the node to ssh to. If None,
1470+
tries to return the ssh_client associated with current client_host context, if any.
1471+
:param port: The ssh port
1472+
:param username: The username to use
1473+
:param password: The username's password
1474+
:param key_filename: The filename of optional private key and/or cert to try for authentication
1475+
:param auto_add_host: Whether to auto accept host certificates
1476+
:param connect_timeout: Connection timeout
1477+
:param through_client_host: If True, and client_host is being used, ssh will be initiated
1478+
through the client_host ssh connection. Username/password used for client_host will propagate
1479+
unless overridden.
1480+
:param address_type_pref: Comma delimited list of node address types. Types will be tried in
1481+
the order specified.
1482+
:param paramiko_connect_extras: An optional dictionary of kwargs to pass to the underlying SSH client connection method.
14721483
:return: N/A, but throws the last exception received if timeout occurs.
14731484
"""
14741485

@@ -1485,7 +1496,8 @@ def node_ssh_await(apiobj_node_name_or_qname=None,
14851496
auto_add_host=auto_add_host,
14861497
connect_timeout=25,
14871498
through_client_host=through_client_host,
1488-
address_type_pref=address_type_pref) as ssh_client:
1499+
address_type_pref=address_type_pref,
1500+
paramiko_connect_extras=paramiko_connect_extras) as ssh_client:
14891501
return
14901502

14911503
except Exception as e:
@@ -1504,7 +1516,8 @@ def node_ssh_client_exec(apiobj_node_name_or_qname=None,
15041516
auto_add_host=True,
15051517
connect_timeout=600,
15061518
through_client_host=True,
1507-
address_type_pref="ExternalDNS,ExternalIP,Hostname"
1519+
address_type_pref="ExternalDNS,ExternalIP,Hostname",
1520+
paramiko_connect_extras=None,
15081521
):
15091522
"""
15101523
Executes a single command on the remote host via ssh and returns rc, stdout, stderr. Closes the connection
@@ -1524,6 +1537,7 @@ def node_ssh_client_exec(apiobj_node_name_or_qname=None,
15241537
unless overridden.
15251538
:param address_type_pref: Comma delimited list of node address types. Types will be tried in
15261539
the order specified.
1540+
:param paramiko_connect_extras: An optional dictionary of kwargs to pass to the underlying SSH client connection method.
15271541
:return: rc, stdout, stderr
15281542
"""
15291543

@@ -1535,7 +1549,8 @@ def node_ssh_client_exec(apiobj_node_name_or_qname=None,
15351549
auto_add_host=auto_add_host,
15361550
connect_timeout=connect_timeout,
15371551
through_client_host=through_client_host,
1538-
address_type_pref=address_type_pref) as ssh_client:
1552+
address_type_pref=address_type_pref,
1553+
paramiko_connect_extras=paramiko_connect_extras) as ssh_client:
15391554
ssh_stdin, ssh_stdout, ssh_stderr = ssh_client.exec_command(cmd_str)
15401555

15411556
if stdin_str:

0 commit comments

Comments
 (0)