Skip to content

Commit

Permalink
Add support for paramiko set_keepalive
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Gomizelj committed Mar 24, 2015
1 parent 2ab6b51 commit ffb2dba
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plumbum/machines/paramiko_machine.py
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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)

#
Expand Down

0 comments on commit ffb2dba

Please sign in to comment.