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:
+11
-24
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user