import defer
import functools
import collections
+import hashlib
CTRL_SOCK = "ctrl.sock"
CTRL_PID = "ctrl.pid"
return tmp_known_hosts
+def make_connkey(user, host, port):
+ connkey = repr((user,host,port)).encode("base64").strip().replace('/','.')
+ if len(connkey) > 60:
+ connkey = hashlib.sha1(connkey).hexdigest()
+ return connkey
+
def popen_ssh_command(command, host, port, user, agent,
stdin="",
ident_key = None,
timeout = None,
retry = 0,
err_on_timeout = True,
- connect_timeout = 30):
+ connect_timeout = 30,
+ persistent = True):
"""
Executes a remote commands, returns ((stdout,stderr),process)
"""
print "ssh", host, command
tmp_known_hosts = None
- connkey = repr((user,host,port)).encode("base64").strip().replace('/','.')
+ connkey = make_connkey(user,host,port)
args = ['ssh', '-C',
# Don't bother with localhost. Makes test easier
'-o', 'NoHostAuthenticationForLocalhost=yes',
'-o', 'ConnectionAttempts=3',
'-o', 'ServerAliveInterval=30',
'-o', 'TCPKeepAlive=yes',
+ '-l', user, host]
+ if persistent:
+ args.extend([
'-o', 'ControlMaster=auto',
'-o', 'ControlPath=/tmp/nepi_ssh_pl_%s' % ( connkey, ),
- '-o', 'ControlPersist=60',
- '-l', user, host]
+ '-o', 'ControlPersist=60' ])
if agent:
args.append('-A')
if port:
user,host = remspec.rsplit('@',1)
tmp_known_hosts = None
- connkey = repr((user,host,port)).encode("base64").strip().replace('/','.')
+ connkey = make_connkey(user,host,port)
args = ['ssh', '-l', user, '-C',
# Don't bother with localhost. Makes test easier
'-o', 'NoHostAuthenticationForLocalhost=yes',