From 348a62927e7fcfa2af69c6922d56711751e2b088 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Mon, 29 Jun 2026 15:51:32 +0200 Subject: [PATCH] fix(get_config): use netmiko hp_procurve on port 22 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- napalm_procurve/procurve.py | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/napalm_procurve/procurve.py b/napalm_procurve/procurve.py index a44ee69..9a0a89b 100644 --- a/napalm_procurve/procurve.py +++ b/napalm_procurve/procurve.py @@ -592,34 +592,21 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver): return {"running": running, "startup": startup, "candidate": candidate} 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 - (e.g. HP 2530 / YA firmware). Uses port 22 explicitly because + HP ProCurve switches do not support exec_channel SSH; they require + 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. """ - import paramiko - - _TIMEOUT = 15 - try: - client = paramiko.SSHClient() - client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - client.connect( - hostname=self.hostname, - 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, - ) - _, stdout, _ = client.exec_command("show running-config", timeout=_TIMEOUT) - config = stdout.read().decode("utf-8", errors="replace") - client.close() - return config + kwargs = self._netmiko_kwargs() + kwargs["port"] = 22 # always SSH — self.port is the REST API port + conn = ConnectHandler(**kwargs) + try: + return conn.send_command("show running-config") + finally: + conn.disconnect() except Exception as exc: logger.warning("SSH config fallback failed for %s: %s", self.hostname, exc) return ""