Skip to content

Commit

Permalink
ide is now able to use gateway if given.
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Sep 20, 2023
1 parent 5e5b151 commit ca9c82c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
23 changes: 12 additions & 11 deletions bibigrid/core/actions/ide.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import sys
import time
import webbrowser

import sshtunnel
import sympy

from bibigrid.core.utility.handler import cluster_ssh_handler

Expand All @@ -21,7 +23,6 @@
LOCALHOST = "127.0.0.1"



def sigint_handler(caught_signal, frame): # pylint: disable=unused-argument
"""
Is called when SIGINT is thrown and terminates the program
Expand All @@ -48,7 +49,6 @@ def is_used(ip_address):
for line in lines:
is_open = re.match(rf'tcp.*{ip_address}:([0-9][0-9]*).*ESTABLISHED\s*$', line)
if is_open is not None:
print(line)
ports_used.append(is_open[1])


Expand All @@ -68,18 +68,19 @@ def ide(cluster_id, master_provider, master_configuration, log):
used_local_bind_address = LOCAL_BIND_ADDRESS
if master_ip and ssh_user and used_private_key:
attempts = 0
if master_configuration.get("gateway"):
octets = {f'oct{enum + 1}': int(elem) for enum, elem in enumerate(master_ip.split("."))}
port = sympy.sympify(master_configuration["gateway"]["portFunction"]).subs(dict(octets))
gateway = (master_configuration["gateway"]["ip"], int(port))
else:
gateway = None
while attempts < 16:
attempts += 1
try:
with sshtunnel.SSHTunnelForwarder(
ssh_address_or_host=master_ip, # Raspberry Pi in my network

ssh_username=ssh_user,
ssh_pkey=used_private_key,

local_bind_address=(LOCALHOST, used_local_bind_address),
remote_bind_address=(LOCALHOST, REMOTE_BIND_ADDRESS)
) as server:
with sshtunnel.SSHTunnelForwarder(ssh_address_or_host=gateway or master_ip, ssh_username=ssh_user,
ssh_pkey=used_private_key,
local_bind_address=(LOCALHOST, used_local_bind_address),
remote_bind_address=(LOCALHOST, REMOTE_BIND_ADDRESS)) as server:
print("CTRL+C to close port forwarding when you are done.")
with server:
# opens in existing window if any default program exists
Expand Down
1 change: 0 additions & 1 deletion bibigrid/core/utility/handler/ssh_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def is_active(client, floating_ip_address, private_key, username, log, gateway,
establishing_connection = True
while establishing_connection:
try:
# Add Port
port = 22
if gateway:
log.info(f"Using SSH Gateway {gateway.get('ip')}")
Expand Down

0 comments on commit ca9c82c

Please sign in to comment.