fix(get_config): SSH fallback when REST API returns empty (HP 2530/YA firmware)

HP 2530 switches with YA firmware do not expose /rest/v7/running-config.
_get_config_via_ssh() opens a temporary netmiko session to run
'show running-config' as fallback when the API endpoint returns 404.
This commit is contained in:
Christian Manivong
2026-06-29 12:36:09 +02:00
parent 46aadbbe3b
commit 87db7b2873
+23 -1
View File
@@ -565,7 +565,13 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
) -> Dict[str, str]: ) -> Dict[str, str]:
"""Return device configuration.""" """Return device configuration."""
if self._transport == "api": if self._transport == "api":
return self._api.get_config() result = self._api.get_config()
if result.get("running"):
return result
# REST endpoint not available on this firmware (e.g. HP 2530 / YA series).
# Fall back to a temporary SSH connection to run show running-config.
running = self._get_config_via_ssh()
return {"running": running, "startup": "", "candidate": ""}
running = "" running = ""
startup = "" startup = ""
@@ -580,6 +586,22 @@ 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:
"""Open a one-shot SSH session to retrieve running-config.
Used as fallback when the REST API does not expose the config endpoint
(e.g. HP 2530 / YA firmware). Returns empty string on any failure.
"""
try:
conn = ConnectHandler(**self._netmiko_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 ""
# ------------------------------------------------------------------ # ------------------------------------------------------------------
# NAPALM: get_environment # NAPALM: get_environment
# ------------------------------------------------------------------ # ------------------------------------------------------------------