fix(get_config): back to paramiko with port 22 — no subprocess needed
Root cause was self.port=443 (REST API port) being used for SSH. With port 22 paramiko works fine — same as the SSH console link.
This commit is contained in:
+23
-38
@@ -592,52 +592,37 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
|||||||
return {"running": running, "startup": startup, "candidate": candidate}
|
return {"running": running, "startup": startup, "candidate": candidate}
|
||||||
|
|
||||||
def _get_config_via_ssh(self) -> str:
|
def _get_config_via_ssh(self) -> str:
|
||||||
"""Retrieve running-config via OpenSSH subprocess (sshpass + ssh).
|
"""Open a one-shot SSH session on port 22 to retrieve running-config.
|
||||||
|
|
||||||
paramiko is incompatible with Mocana SSH 6.3 on HP 2530 / YA firmware.
|
Used when the REST API does not expose the running-config endpoint
|
||||||
OpenSSH has better legacy algorithm support and connects where paramiko
|
(e.g. HP 2530 / YA firmware). Uses port 22 explicitly because
|
||||||
fails. Requires openssh-client + sshpass installed in the environment.
|
self.port is the REST API port (443) in API transport mode.
|
||||||
"""
|
"""
|
||||||
import shutil
|
import paramiko
|
||||||
import subprocess
|
|
||||||
|
|
||||||
_TIMEOUT = 12
|
_TIMEOUT = 15
|
||||||
|
|
||||||
if not shutil.which("sshpass") or not shutil.which("ssh"):
|
|
||||||
logger.warning("sshpass/ssh not available — skipping SSH config fallback for %s", self.hostname)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
cmd = [
|
|
||||||
"sshpass", "-p", self.password or "",
|
|
||||||
"ssh",
|
|
||||||
"-o", "StrictHostKeyChecking=no",
|
|
||||||
"-o", "UserKnownHostsFile=/dev/null",
|
|
||||||
"-o", f"ConnectTimeout={_TIMEOUT}",
|
|
||||||
"-o", "BatchMode=no",
|
|
||||||
"-o", "KexAlgorithms=+diffie-hellman-group1-sha1,diffie-hellman-group14-sha1",
|
|
||||||
"-o", "HostKeyAlgorithms=+ssh-rsa",
|
|
||||||
"-p", "22", # always SSH port — self.port is the REST API port (443)
|
|
||||||
f"{self.username}@{self.hostname}",
|
|
||||||
"show running-config",
|
|
||||||
]
|
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
client = paramiko.SSHClient()
|
||||||
cmd,
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
capture_output=True,
|
client.connect(
|
||||||
text=True,
|
hostname=self.hostname,
|
||||||
timeout=_TIMEOUT + 3,
|
port=22, # always SSH — self.port is the REST API port
|
||||||
|
username=self.username,
|
||||||
|
password=self.password,
|
||||||
|
timeout=_TIMEOUT,
|
||||||
|
banner_timeout=_TIMEOUT,
|
||||||
|
auth_timeout=_TIMEOUT,
|
||||||
|
look_for_keys=False,
|
||||||
|
allow_agent=False,
|
||||||
)
|
)
|
||||||
if result.returncode == 0 and result.stdout.strip():
|
_, stdout, _ = client.exec_command("show running-config", timeout=_TIMEOUT)
|
||||||
return result.stdout
|
config = stdout.read().decode("utf-8", errors="replace")
|
||||||
logger.warning(
|
client.close()
|
||||||
"SSH config fallback (openssh) failed for %s: rc=%s err=%s",
|
return config
|
||||||
self.hostname, result.returncode, result.stderr[:200],
|
|
||||||
)
|
|
||||||
except subprocess.TimeoutExpired:
|
|
||||||
logger.warning("SSH config fallback timed out for %s", self.hostname)
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning("SSH config fallback failed for %s: %s", self.hostname, exc)
|
logger.warning("SSH config fallback failed for %s: %s", self.hostname, exc)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# NAPALM: get_environment
|
# NAPALM: get_environment
|
||||||
|
|||||||
Reference in New Issue
Block a user