Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit37323ab

Browse files
author
vshepard
committed
Update establish_ssh_tunnel
1 parentfffb23c commit37323ab

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

‎testgres/operations/remote_ops.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ def is_port_open(host, port):
7676
exceptsocket.error:
7777
returnFalse
7878

79-
defestablish_ssh_tunnel(self,local_port,remote_port):
79+
defestablish_ssh_tunnel(self,local_port,remote_port,host):
8080
"""
8181
Establish an SSH tunnel from a local port to a remote PostgreSQL port.
8282
"""
83-
ssh_cmd= ['-N','-L',f"{local_port}:localhost:{remote_port}"]
83+
ifhost!='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}"]
8487
self.tunnel_process=self.exec_command(ssh_cmd,get_process=True,timeout=300)
8588
timeout=10
8689
start_time=time.time()
@@ -412,10 +415,10 @@ def db_connect(self, dbname, user, password=None, host="localhost", port=5432):
412415
"""
413416
local_port=reserve_port()
414417
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)
416419
try:
417420
conn=pglib.connect(
418-
host=host,
421+
host='localhost',
419422
port=local_port,
420423
database=dbname,
421424
user=user,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp