From f8f4df3621b650205870542b6114decb049e3477 Mon Sep 17 00:00:00 2001 From: Vineet Naik Date: Mon, 29 Jun 2015 20:29:49 +0530 Subject: Add keepalive support to GerritSSHClient This will allow keeping the SSH sessions alive for a duration of time longer than the timeout configured for the server. Change-Id: I9d86c0fc304783fab944ebae7bd0da8f3b1edd6c --- pygerrit/client.py | 9 +++++++-- pygerrit/ssh.py | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pygerrit/client.py b/pygerrit/client.py index 73f43be..733aa9a 100644 --- a/pygerrit/client.py +++ b/pygerrit/client.py @@ -40,14 +40,19 @@ class GerritClient(object): :arg str host: The hostname. :arg str username: (optional) The username to use when connecting. :arg str port: (optional) The port number to connect to. + :arg int keepalive: (optional) Keepalive interval in seconds. """ - def __init__(self, host, username=None, port=None): + def __init__(self, host, username=None, port=None, keepalive=None): self._factory = GerritEventFactory() self._events = Queue() self._stream = None - self._ssh_client = GerritSSHClient(host, username=username, port=port) + self.keepalive = keepalive + self._ssh_client = GerritSSHClient(host, + username=username, + port=port, + keepalive=keepalive) def gerrit_version(self): """ Get the Gerrit version. diff --git a/pygerrit/ssh.py b/pygerrit/ssh.py index 350eb48..fbc5a29 100644 --- a/pygerrit/ssh.py +++ b/pygerrit/ssh.py @@ -65,7 +65,7 @@ class GerritSSHClient(SSHClient): """ Gerrit SSH Client, wrapping the paramiko SSH Client. """ - def __init__(self, hostname, username=None, port=None): + def __init__(self, hostname, username=None, port=None, keepalive=None): """ Initialise and connect to SSH. """ super(GerritSSHClient, self).__init__() self.remote_version = None @@ -76,6 +76,7 @@ class GerritSSHClient(SSHClient): self.connected = Event() self.lock = Lock() self.proxy = None + self.keepalive = keepalive def _configure(self): """ Configure the ssh parameters from the config file. """ @@ -136,6 +137,8 @@ class GerritSSHClient(SSHClient): # waiting to acquire the lock if not self.connected.is_set(): self._do_connect() + if self.keepalive: + self._transport.set_keepalive(self.keepalive) self.connected.set() except GerritError: raise -- cgit v1.2.1