Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for paramiko set_keepalive #186

Merged
merged 1 commit into from
Mar 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 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 @@ -177,6 +177,7 @@ def __init__(self, host, user = None, port = None, password = None, keyfile = No
if connect_timeout is not None:
kwargs["timeout"] = connect_timeout
self._client.connect(host, **kwargs)
self._keep_alive = keep_alive
self._sftp = None
BaseRemoteMachine.__init__(self, encoding, connect_timeout)

Expand All @@ -200,7 +201,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 +288,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