@@ -74,11 +74,11 @@ def is_port_open(host, port):
7474except socket .error :
7575return False
7676
77- def establish_ssh_tunnel (self ,local_port ,remote_port ):
77+ def establish_ssh_tunnel (self ,local_port ,remote_port , host = 'localhost' ):
7878"""
7979 Establish an SSH tunnel from a local port to a remote PostgreSQL port.
8080 """
81- ssh_cmd = ['-N' ,'-L' ,f"{ local_port } :localhost :{ remote_port } " ]
81+ ssh_cmd = ['-N' ,'-L' ,f"{ local_port } :{ host } :{ remote_port } " ]
8282self .tunnel_process = self .exec_command (ssh_cmd ,get_process = True ,timeout = 300 )
8383timeout = 10
8484start_time = time .time ()
@@ -410,7 +410,7 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
410410 """
411411local_port = reserve_port ()
412412self .tunnel_port = local_port
413- self .establish_ssh_tunnel (local_port = local_port ,remote_port = port )
413+ self .establish_ssh_tunnel (local_port = local_port ,remote_port = port , host = host )
414414try :
415415conn = pglib .connect (
416416host = host ,
@@ -423,8 +423,8 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
423423print ("Database connection established successfully." )
424424return conn
425425except Exception as e :
426- print (f"Error connecting to the database:{ str (e )} " )
426+ print (f"!!! Error connecting to the database:{ str (e )} " )
427427if self .tunnel_process :
428428self .tunnel_process .terminate ()
429- print ("SSH tunnel closed due to connection failure." )
429+ print ("!!! SSH tunnel closed due to connection failure." )
430430raise