fix(get_config): use plain text GET for running/startup config
AOS-Switch returns the config body as text/plain, not JSON. The previous get_config() called self.get() which calls resp.json(), silently caught the JSONDecodeError, and returned ''. Now uses _get_text() which reads resp.text directly.
This commit is contained in:
@@ -435,15 +435,28 @@ class ProcurveApiClient:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_config(self) -> Dict[str, str]:
|
def get_config(self) -> Dict[str, str]:
|
||||||
"""Return running and startup configuration via REST API."""
|
"""Return running and startup configuration via REST API.
|
||||||
running = self.get("running-config")
|
|
||||||
startup = self.get("startup-config")
|
AOS-Switch returns the config as plain text, not JSON.
|
||||||
|
"""
|
||||||
return {
|
return {
|
||||||
"running": running.get("config", ""),
|
"running": self._get_text("running-config"),
|
||||||
"startup": startup.get("config", ""),
|
"startup": self._get_text("startup-config"),
|
||||||
"candidate": "",
|
"candidate": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _get_text(self, endpoint: str) -> str:
|
||||||
|
"""GET *endpoint* and return the response body as plain text."""
|
||||||
|
url = self._base_url + endpoint
|
||||||
|
try:
|
||||||
|
resp = self._session.get(url, timeout=self.timeout)
|
||||||
|
if resp.ok:
|
||||||
|
return resp.text
|
||||||
|
logger.warning("GET %s returned HTTP %s: %s", url, resp.status_code, resp.text[:200])
|
||||||
|
except Exception as exc:
|
||||||
|
logger.warning("GET %s error: %s", url, exc)
|
||||||
|
return ""
|
||||||
|
|
||||||
def get_ntp_servers(self) -> Dict[str, Dict]:
|
def get_ntp_servers(self) -> Dict[str, Dict]:
|
||||||
"""Return NTP servers from REST API."""
|
"""Return NTP servers from REST API."""
|
||||||
data = self.get("ntp/server")
|
data = self.get("ntp/server")
|
||||||
|
|||||||
Reference in New Issue
Block a user