feat: add SSH connectivity check
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
24
src/autossh_mgr/check.py
Normal file
24
src/autossh_mgr/check.py
Normal file
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import subprocess
|
||||
from autossh_mgr.config import TunnelConfig
|
||||
|
||||
|
||||
def build_ssh_check_cmd(tunnel: TunnelConfig) -> list[str]:
|
||||
return [
|
||||
"ssh",
|
||||
"-o", "BatchMode=yes",
|
||||
"-o", "ConnectTimeout=5",
|
||||
"-i", os.path.expanduser(tunnel.identity_file),
|
||||
"-p", str(tunnel.port),
|
||||
f"{tunnel.user}@{tunnel.host}",
|
||||
"true",
|
||||
]
|
||||
|
||||
|
||||
def check_connectivity(tunnel: TunnelConfig) -> tuple[bool, str]:
|
||||
result = subprocess.run(
|
||||
build_ssh_check_cmd(tunnel),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
return result.returncode == 0, result.stderr.strip()
|
||||
Reference in New Issue
Block a user