Skip to content
Snippets Groups Projects
Commit af9aab12 authored by Jedrzej Rybicki's avatar Jedrzej Rybicki
Browse files

default host ist bsc now

parent 48aa3915
No related branches found
No related tags found
No related merge requests found
Pipeline #95813 failed
...@@ -23,7 +23,7 @@ def conn_decorator(): ...@@ -23,7 +23,7 @@ def conn_decorator():
def doing_nothing(conn_id): def doing_nothing(conn_id):
print(f"Using connection {conn_id}") print(f"Using connection {conn_id}")
ssh_hook = get_connection(conn_id=conn_id) ssh_hook = get_connection(conn_id=conn_id, default_host='amdlogin.bsc.es')
with ssh_hook.get_conn() as ssh_client: with ssh_hook.get_conn() as ssh_client:
sftp_client = ssh_client.open_sftp() sftp_client = ssh_client.open_sftp()
print("Connected") print("Connected")
......
...@@ -29,7 +29,7 @@ def create_temp_connection(rrid, params): ...@@ -29,7 +29,7 @@ def create_temp_connection(rrid, params):
return conn_id return conn_id
def get_connection(conn_id): def get_connection(conn_id, default_host='amdlogin.bsc.es'):
if conn_id.startswith('vault'): if conn_id.startswith('vault'):
vault_hook = VaultHook(vault_conn_id='my_vault') vault_hook = VaultHook(vault_conn_id='my_vault')
con = vault_hook.get_secret( con = vault_hook.get_secret(
...@@ -37,7 +37,7 @@ def get_connection(conn_id): ...@@ -37,7 +37,7 @@ def get_connection(conn_id):
print(f"Got some values from vault {list(con.keys())}") print(f"Got some values from vault {list(con.keys())}")
# for now SSH is hardcoded # for now SSH is hardcoded
host = con.get('host', 'bsc') host = con.get('host', default_host)
port = int(con.get('port', 22)) port = int(con.get('port', 22))
hook = SSHHook(remote_host=host, port=port, username=con['userName']) hook = SSHHook(remote_host=host, port=port, username=con['userName'])
# key in vault should be in form of formated string: # key in vault should be in form of formated string:
......
...@@ -58,7 +58,7 @@ def taskflow_example(): ...@@ -58,7 +58,7 @@ def taskflow_example():
target = params.get('target', '/tmp/') target = params.get('target', '/tmp/')
print(f"Using {connection_id} connection") print(f"Using {connection_id} connection")
ssh_hook = get_connection(conn_id=connection_id) ssh_hook = get_connection(conn_id=connection_id, default_host='amdlogin.bsc.es')
with ssh_hook.get_conn() as ssh_client: with ssh_hook.get_conn() as ssh_client:
sftp_client = ssh_client.open_sftp() sftp_client = ssh_client.open_sftp()
......
...@@ -11,7 +11,7 @@ from airflow.utils.dates import days_ago ...@@ -11,7 +11,7 @@ from airflow.utils.dates import days_ago
from b2shareoperator import (add_file, create_draft_record, get_community, from b2shareoperator import (add_file, create_draft_record, get_community,
submit_draft) submit_draft)
from decors import remove, setup from decors import remove, setup, get_connection
default_args = { default_args = {
'owner': 'airflow', 'owner': 'airflow',
...@@ -45,7 +45,7 @@ def upload_example(): ...@@ -45,7 +45,7 @@ def upload_example():
target = params.get('target', '/tmp/') target = params.get('target', '/tmp/')
source = params.get('source', '/tmp/') source = params.get('source', '/tmp/')
ssh_hook = SSHHook(ssh_conn_id=connection_id) ssh_hook = get_connection(conn_id=connection_id, default_host='amdlogin.bsc.es')
with ssh_hook.get_conn() as ssh_client: with ssh_hook.get_conn() as ssh_client:
sftp_client = ssh_client.open_sftp() sftp_client = ssh_client.open_sftp()
lst = sftp_client.listdir(path=source) lst = sftp_client.listdir(path=source)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment