fix(get_config): use netmiko hp_procurve on port 22

HP ProCurve needs invoke_shell (not exec_channel) — exec_command via
paramiko returns 'SSH command execution is not supported'. Netmiko's
hp_procurve device type handles this correctly. Port 22 explicit.
This commit is contained in:
Christian Manivong
2026-06-29 15:51:32 +02:00
parent 6e2ac6bd94
commit 348a62927e
+11 -24
View File
@@ -592,34 +592,21 @@ 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:
"""Open a one-shot SSH session on port 22 to retrieve running-config. """Retrieve running-config via netmiko on port 22.
Used when the REST API does not expose the running-config endpoint HP ProCurve switches do not support exec_channel SSH; they require
(e.g. HP 2530 / YA firmware). Uses port 22 explicitly because an interactive shell (invoke_shell), which netmiko's hp_procurve
device type handles correctly. Port 22 is used explicitly because
self.port is the REST API port (443) in API transport mode. self.port is the REST API port (443) in API transport mode.
""" """
import paramiko
_TIMEOUT = 15
try: try:
client = paramiko.SSHClient() kwargs = self._netmiko_kwargs()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) kwargs["port"] = 22 # always SSH — self.port is the REST API port
client.connect( conn = ConnectHandler(**kwargs)
hostname=self.hostname, try:
port=22, # always SSH — self.port is the REST API port return conn.send_command("show running-config")
username=self.username, finally:
password=self.password, conn.disconnect()
timeout=_TIMEOUT,
banner_timeout=_TIMEOUT,
auth_timeout=_TIMEOUT,
look_for_keys=False,
allow_agent=False,
)
_, stdout, _ = client.exec_command("show running-config", timeout=_TIMEOUT)
config = stdout.read().decode("utf-8", errors="replace")
client.close()
return config
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 ""