airflow.providers.ssh.hooks.ssh
¶
Hook for SSH connections.
Module Contents¶
Attributes¶
- 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, keepalive_interval=30, banner_timeout=30.0)[source]¶
Bases:
airflow.hooks.base.BaseHook
Hook for ssh remote execution using Paramiko. ref: https://github.com/paramiko/paramiko This hook also lets you create ssh tunnel and serve as basis for SFTP file transfer
- Parameters
ssh_conn_id (Optional[str]) -- ssh connection id from airflow Connections from where all the required parameters can be fetched like username, password or key_file. Thought the priority is given to the param passed during init
remote_host (str) -- remote host to connect
username (Optional[str]) -- username to connect to the remote_host
password (Optional[str]) -- password of the username to connect to the remote_host
key_file (Optional[str]) -- path to key file to use to connect to the remote_host
port (Optional[int]) -- port of remote host to connect (Default is paramiko SSH_PORT)
conn_timeout (Optional[int]) -- 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 (Optional[int]) -- (Deprecated). timeout for the attempt to connect to the remote_host. Use conn_timeout instead.
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
- get_conn(self)[source]¶
Opens a ssh connection to the remote host.
- Return type
paramiko.client.SSHClient
- get_tunnel(self, remote_port, remote_host='localhost', local_port=None)[source]¶
Creates a tunnel between two hosts. Like ssh -L <LOCAL_PORT>:host:<REMOTE_PORT>.
- Parameters
- Returns
sshtunnel.SSHTunnelForwarder object
- Return type
sshtunnel.SSHTunnelForwarder