From 94548e70b7d9e4b9668003a6100a09b3d323375e Mon Sep 17 00:00:00 2001 From: Thomas Schmid Date: Wed, 5 Sep 2018 11:48:58 -0600 Subject: Allow customized pxssh client This can be very useful if you want to run the pxssh client in a network namespace. --- pexpect/pxssh.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'pexpect') diff --git a/pexpect/pxssh.py b/pexpect/pxssh.py index f230e04..d1a059f 100644 --- a/pexpect/pxssh.py +++ b/pexpect/pxssh.py @@ -259,7 +259,7 @@ class pxssh (spawn): sync_multiplier=1, check_local_ip=True, password_regex=r'(?i)(?:password:)|(?:passphrase for key)', ssh_tunnels={}, spawn_local_ssh=True, - sync_original_prompt=True, ssh_config=None): + sync_original_prompt=True, ssh_config=None, cmd='ssh'): '''This logs the user into the given server. It uses @@ -303,6 +303,10 @@ class pxssh (spawn): file to the client to handle itself. You may set any options you wish in here, however doing so will require you to post extra information that you may not want to if you run into issues. + + Alter the ``cmd`` to change the ssh client used, or to prepend it with network + namespaces. For example ```cmd="ip netns exec vlan2 ssh"``` to execute the ssh in + network namespace named ```vlan```. ''' session_regex_array = ["(?i)are you sure you want to continue connecting", original_prompt, password_regex, "(?i)permission denied", "(?i)terminal type", TIMEOUT] @@ -354,7 +358,7 @@ class pxssh (spawn): if spawn_local_ssh==False: tunnel = quote(str(tunnel)) ssh_options = ssh_options + ' -' + cmd_type + ' ' + str(tunnel) - cmd = "ssh %s -l %s %s" % (ssh_options, username, server) + cmd += " %s -l %s %s" % (ssh_options, username, server) if self.debug_command_string: return(cmd) -- cgit v1.2.1