From ffb2dbae1a273bcd95f19d9a3b7982f7c12f99a1 Mon Sep 17 00:00:00 2001 From: Simon Gomizelj Date: Mon, 23 Mar 2015 20:35:51 -0400 Subject: [PATCH] Add support for paramiko set_keepalive --- plumbum/machines/paramiko_machine.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plumbum/machines/paramiko_machine.py b/plumbum/machines/paramiko_machine.py index f1520b175..42ea370f4 100644 --- a/plumbum/machines/paramiko_machine.py +++ b/plumbum/machines/paramiko_machine.py @@ -153,7 +153,7 @@ def __lshift__(self, *_): def __init__(self, host, user = None, port = None, password = None, keyfile = None, load_system_host_keys = True, missing_host_policy = None, encoding = "utf8", - look_for_keys = None, connect_timeout = None): + look_for_keys = None, connect_timeout = None, keep_alive = 0): self.host = host kwargs = {} if user: @@ -176,6 +176,8 @@ def __init__(self, host, user = None, port = None, password = None, keyfile = No kwargs["look_for_keys"] = look_for_keys if connect_timeout is not None: kwargs["timeout"] = connect_timeout + if keep_alive: + self._keep_alive = keep_alive self._client.connect(host, **kwargs) self._sftp = None BaseRemoteMachine.__init__(self, encoding, connect_timeout) @@ -200,7 +202,9 @@ def sftp(self): @_setdoc(BaseRemoteMachine) def session(self, isatty = False, term = "vt100", width = 80, height = 24, new_session = False): # new_session is ignored for ParamikoMachine - chan = self._client.get_transport().open_session() + trans = self._client.get_transport() + trans.set_keepalive(self._keep_alive) + chan = trans.open_session() if isatty: chan.get_pty(term, width, height) chan.set_combine_stderr() @@ -285,7 +289,9 @@ def connect_sock(self, dport, dhost = "localhost", ipv6 = False): if ipv6 and dhost == "localhost": dhost = "::1" srcaddr = ("::1", 0, 0, 0) if ipv6 else ("127.0.0.1", 0) - chan = self._client.get_transport().open_channel('direct-tcpip', (dhost, dport), srcaddr) + trans = self._client.get_transport() + trans.set_keepalive(self._keep_alive) + chan = trans.open_channel('direct-tcpip', (dhost, dport), srcaddr) return SocketCompatibleChannel(chan) #