From ea051d9a3f50b68e96858751be4746988b454e0d Mon Sep 17 00:00:00 2001 From: XaverStiensmeier Date: Thu, 21 Sep 2023 15:04:45 +0200 Subject: [PATCH] fixed ssh not using gateway --- bibigrid/core/actions/create.py | 12 +++++++++++- bibigrid/core/utility/handler/ssh_handler.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bibigrid/core/actions/create.py b/bibigrid/core/actions/create.py index be1daee3..88c97889 100644 --- a/bibigrid/core/actions/create.py +++ b/bibigrid/core/actions/create.py @@ -9,6 +9,7 @@ from functools import partial import paramiko +import sympy import yaml from bibigrid.core.actions import terminate @@ -431,8 +432,17 @@ def log_cluster_start_info(self): Detailed cluster info: How to log detailed info about the created cluster :return: """ + gateway = self.configurations[0].get("gateway") + ssh_ip = self.master_ip + port = None + if gateway: + octets = {f'oct{enum + 1}': int(elem) for enum, elem in enumerate(self.master_ip.split("."))} + port = int(sympy.sympify(gateway["portFunction"]).subs(dict(octets))) + ssh_ip = gateway["ip"] self.log.log(42, f"Cluster {self.cluster_id} with master {self.master_ip} up and running!") - self.log.log(42, f"SSH: ssh -i '{KEY_FOLDER}{self.key_name}' {self.ssh_user}@{self.master_ip}") + self.log.log(42, + f"SSH: ssh -i '{KEY_FOLDER}{self.key_name}' {self.ssh_user}@{ssh_ip}" + f"{f' -p {port}' if gateway else ''}") self.log.log(42, f"Terminate cluster: ./bibigrid.sh -i '{self.config_path}' -t -cid {self.cluster_id}") self.log.log(42, f"Detailed cluster info: ./bibigrid.sh -i '{self.config_path}' -l -cid {self.cluster_id}") if self.configurations[0].get("ide"): diff --git a/bibigrid/core/utility/handler/ssh_handler.py b/bibigrid/core/utility/handler/ssh_handler.py index 7ae4498d..a705a405 100644 --- a/bibigrid/core/utility/handler/ssh_handler.py +++ b/bibigrid/core/utility/handler/ssh_handler.py @@ -108,9 +108,9 @@ def is_active(client, floating_ip_address, private_key, username, log, gateway, if gateway: log.info(f"Using SSH Gateway {gateway.get('ip')}") octets = {f'oct{enum+1}': int(elem) for enum, elem in enumerate(floating_ip_address.split("."))} - port = sympy.sympify(gateway["portFunction"]).subs(dict(octets)) + port = int(sympy.sympify(gateway["portFunction"]).subs(dict(octets))) client.connect(hostname=gateway.get("ip") or floating_ip_address, username=username, - pkey=private_key, timeout=7, auth_timeout=5, port=int(port)) + pkey=private_key, timeout=7, auth_timeout=5, port=port) establishing_connection = False log.info(f"Successfully connected to {floating_ip_address}") except paramiko.ssh_exception.NoValidConnectionsError as exc: