airflow.providers.ssh.hooks.ssh

Hook for SSH connections.

Module Contents

Classes

SSHHook

Execute remote commands with Paramiko.

Attributes

TIMEOUT_DEFAULT

CMD_TIMEOUT

airflow.providers.ssh.hooks.ssh.TIMEOUT_DEFAULT = 10[source]
airflow.providers.ssh.hooks.ssh.CMD_TIMEOUT = 10[source]
class airflow.providers.ssh.hooks.ssh.SSHHook(ssh_conn_id=None, remote_host='', username=None, password=None, key_file=None, port=None, timeout=None, conn_timeout=None, cmd_timeout=NOTSET, keepalive_interval=30, banner_timeout=30.0, disabled_algorithms=None, ciphers=None)[source]

Bases: airflow.hooks.base.BaseHook

Execute remote commands with Paramiko.

This hook also lets you create ssh tunnel and serve as basis for SFTP file transfer.

Parameters
  • ssh_conn_id (str | None) – ssh connection id from airflow Connections from where all the required parameters can be fetched like username, password or key_file, though priority is given to the params passed during init.

  • remote_host (str) – remote host to connect

  • username (str | None) – username to connect to the remote_host

  • password (str | None) – password of the username to connect to the remote_host

  • key_file (str | None) – path to key file to use to connect to the remote_host

  • port (int | None) – port of remote host to connect (Default is paramiko SSH_PORT)

  • conn_timeout (int | None) – timeout (in seconds) for the attempt to connect to the remote_host. The default is 10 seconds. If provided, it will replace the conn_timeout which was predefined in the connection of ssh_conn_id.

  • timeout (int | None) – (Deprecated). timeout for the attempt to connect to the remote_host. Use conn_timeout instead.

  • cmd_timeout (int | airflow.utils.types.ArgNotSet | None) – timeout (in seconds) for executing the command. The default is 10 seconds. Nullable, None means no timeout. If provided, it will replace the cmd_timeout which was predefined in the connection of ssh_conn_id.

  • keepalive_interval (int) – send a keepalive packet to remote host every keepalive_interval seconds

  • banner_timeout (float) – timeout to wait for banner from the server in seconds

  • disabled_algorithms (dict | None) – dictionary mapping algorithm type to an iterable of algorithm identifiers, which will be disabled for the lifetime of the transport

  • ciphers (list[str] | None) – list of ciphers to use in order of preference

conn_name_attr = 'ssh_conn_id'[source]
default_conn_name = 'ssh_default'[source]
conn_type = 'ssh'[source]
hook_name = 'SSH'[source]
classmethod get_ui_field_behaviour()[source]

Return custom UI field behaviour for SSH connection.

host_proxy()[source]
get_conn()[source]

Establish an SSH connection to the remote host.

__enter__()[source]
__exit__(exc_type, exc_val, exc_tb)[source]
get_tunnel(remote_port, remote_host='localhost', local_port=None)[source]

Create a tunnel between two hosts.

This is conceptually similar to ssh -L <LOCAL_PORT>:host:<REMOTE_PORT>.

Parameters
  • remote_port (int) – The remote port to create a tunnel to

  • remote_host (str) – The remote host to create a tunnel to (default localhost)

  • local_port (int | None) – The local port to attach the tunnel to

Returns

sshtunnel.SSHTunnelForwarder object

Return type

sshtunnel.SSHTunnelForwarder

create_tunnel(local_port, remote_port, remote_host='localhost')[source]

Create a tunnel for SSH connection [Deprecated].

Parameters
  • local_port (int) – local port number

  • remote_port (int) – remote port number

  • remote_host (str) – remote host

exec_ssh_client_command(ssh_client, command, get_pty, environment, timeout=NOTSET)[source]
test_connection()[source]

Test the ssh connection by execute remote bash commands.

Was this entry helpful?