ssh: enable app-level keepalive by default; closes #77

This commit is contained in:
David Wilson 2018-03-29 19:11:03 +05:45
parent 1ff27ada49
commit 29e508fde9
1 changed files with 10 additions and 1 deletions

View File

@ -61,7 +61,8 @@ class Stream(mitogen.parent.Stream):
def construct(self, hostname, username=None, ssh_path=None, port=None, def construct(self, hostname, username=None, ssh_path=None, port=None,
check_host_keys=True, password=None, identity_file=None, check_host_keys=True, password=None, identity_file=None,
compression=True, ssh_args=None, **kwargs): compression=True, ssh_args=None, keepalive_enabled=True,
keepalive_count=3, keepalive_interval=15, **kwargs):
super(Stream, self).construct(**kwargs) super(Stream, self).construct(**kwargs)
self.hostname = hostname self.hostname = hostname
self.username = username self.username = username
@ -70,6 +71,9 @@ class Stream(mitogen.parent.Stream):
self.password = password self.password = password
self.identity_file = identity_file self.identity_file = identity_file
self.compression = compression self.compression = compression
self.keepalive_enabled = keepalive_enabled
self.keepalive_count = keepalive_count
self.keepalive_interval = keepalive_interval
if ssh_path: if ssh_path:
self.ssh_path = ssh_path self.ssh_path = ssh_path
if ssh_args: if ssh_args:
@ -89,6 +93,11 @@ class Stream(mitogen.parent.Stream):
bits += ['-i', self.identity_file] bits += ['-i', self.identity_file]
if self.compression: if self.compression:
bits += ['-o', 'Compression yes'] bits += ['-o', 'Compression yes']
if self.keepalive_enabled:
bits += [
'-o', 'ServerAliveInterval %s' % (self.keepalive_interval,),
'-o', 'ServerAliveCountMax %s' % (self.keepalive_count,),
]
if not self.check_host_keys: if not self.check_host_keys:
bits += [ bits += [
'-o', 'StrictHostKeyChecking no', '-o', 'StrictHostKeyChecking no',