@@ -76,11 +76,14 @@ def is_port_open(host, port):
76
76
except socket .error :
77
77
return False
78
78
79
- def establish_ssh_tunnel (self ,local_port ,remote_port ):
79
+ def establish_ssh_tunnel (self ,local_port ,remote_port , host ):
80
80
"""
81
81
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
82
82
"""
83
- ssh_cmd = ['-N' ,'-L' ,f"{ local_port } :localhost:{ remote_port } " ]
83
+ if host != 'localhost' :
84
+ ssh_cmd = ['-N' ,'-L' ,f"localhost:{ local_port } :{ host } :{ remote_port } " ]
85
+ else :
86
+ ssh_cmd = ['-N' ,'-L' ,f"{ local_port } :{ host } :{ remote_port } " ]
84
87
self .tunnel_process = self .exec_command (ssh_cmd ,get_process = True ,timeout = 300 )
85
88
timeout = 10
86
89
start_time = time .time ()
@@ -412,10 +415,10 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
412
415
"""
413
416
local_port = reserve_port ()
414
417
self .tunnel_port = local_port
415
- self .establish_ssh_tunnel (local_port = local_port ,remote_port = port )
418
+ self .establish_ssh_tunnel (local_port = local_port ,remote_port = port , host = host )
416
419
try :
417
420
conn = pglib .connect (
418
- host = host ,
421
+ host = 'localhost' ,
419
422
port = local_port ,
420
423
database = dbname ,
421
424
user = user ,