Repository: incubator-airflow Updated Branches: refs/heads/master c2a0ab5e2 -> 5d6307c1a
[AIRFLOW-691] Add SSH KeepAlive option to SSH_hook This patch adds the option to set tcp keepalive and to configure the server alive interval for the ssh connection. Closes #1937 from danielvdende/add_ssh_keepalive Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/5d6307c1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/5d6307c1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/5d6307c1 Branch: refs/heads/master Commit: 5d6307c1a4c27abe1ee4401e76b694da8dae2968 Parents: c2a0ab5 Author: Daniel van der Ende <[email protected]> Authored: Sun Dec 25 14:26:54 2016 +0100 Committer: Bolke de Bruin <[email protected]> Committed: Sun Dec 25 14:26:57 2016 +0100 ---------------------------------------------------------------------- airflow/contrib/hooks/ssh_hook.py | 6 ++++++ 1 file changed, 6 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/5d6307c1/airflow/contrib/hooks/ssh_hook.py ---------------------------------------------------------------------- diff --git a/airflow/contrib/hooks/ssh_hook.py b/airflow/contrib/hooks/ssh_hook.py index f35e909..e63a65d 100755 --- a/airflow/contrib/hooks/ssh_hook.py +++ b/airflow/contrib/hooks/ssh_hook.py @@ -54,6 +54,8 @@ class SSHHook(BaseHook): conn = self.get_connection(conn_id) self.key_file = conn.extra_dejson.get('key_file', None) self.connect_timeout = conn.extra_dejson.get('connect_timeout', None) + self.tcp_keepalive = conn.extra_dejson.get('tcp_keepalive', False) + self.server_alive_interval = conn.extra_dejson.get('server_alive_interval', 60) self.no_host_key_check = conn.extra_dejson.get('no_host_key_check', False) self.tty = conn.extra_dejson.get('tty', False) self.sshpass = conn.extra_dejson.get('sshpass', False) @@ -81,6 +83,10 @@ class SSHHook(BaseHook): if self.connect_timeout: connection_cmd += ["-o", "ConnectionTimeout={}".format(self.connect_timeout)] + if self.tcp_keepalive: + connection_cmd += ["-o", "TCPKeepAlive=yes"] + connection_cmd += ["-o", "ServerAliveInterval={}".format(self.server_alive_interval)] + if self.no_host_key_check: connection_cmd += ["-o", "UserKnownHostsFile=/dev/null", "-o", "StrictHostKeyChecking=no"]
