feat(time-sync): the switch's NTP servers and zone through TimeSyncMixin
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 56s
driver / test (3.12) (pull_request) Successful in 53s
driver / test (3.13) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m16s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 12s
driver / types (pull_request) Successful in 56s
driver / test (3.12) (pull_request) Successful in 53s
driver / test (3.13) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 25s
driver / build (pull_request) Successful in 30s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m16s
driver / publish (pull_request) Skipped
netOrk aligns every device's NTP servers and time zone with its site's (NetOrk/netork#2360, #2366). A ProCurve keeps them as configuration lines: sntp server priority <1-3> (or ntp server lines when 16.x runs timesync ntp), time timezone <minutes> and time daylight-time-rule. get_time_sync() reads those lines from show running-config, over REST through the /cli endpoint, and the zone as None: the switch keeps minutes and a rule, no name. configure_time_sync() writes the servers in the protocol the switch runs (SNTP unless it runs NTP, switching TimeP to sntp unicast), keeping those already in place from the first on; the zone as minutes and the switch's own US/EU rule, or user-defined dates for other Sunday rules, from the zone's POSIX rule. What the switch cannot take is refused before anything is sent: more than 3 SNTP or 8 NTP servers, host names, half an hour of summer time, a change on a weekday. A change is saved with write memory; values already in place are not sent again, so the alignment on every poll does not churn. Over REST the writes need the CLI, so the temporary SSH session configure_snmp_agent opened is now the _config_cli() context manager both use. get_ntp_servers() reads through get_time_sync() on every transport; it and get_ntp_stats() move to time_sync.py with the rest of the clock, so procurve.py shrinks (1383 -> 1339 lines). The unused parse_ntp_servers() and ProcurveApiClient.get_ntp_servers() are gone.
This commit is contained in:
1 parent
bb8b3a7182
commit
6bd3372933
11 files changed
+801
-111
No files matched your search
+21
-59
@@ -17,6 +17,8 @@ Netmiko device type: ``hp_procurve`` / ``hp_procurve_telnet``
|
||||
|
||||
import logging
|
||||
import re
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from napalm.base.exceptions import (
|
||||
@@ -48,6 +50,7 @@ from netmiko.exceptions import NetmikoAuthenticationException
|
||||
from napalm_procurve import parsers
|
||||
from napalm_procurve.api_client import HTTPS_PORT, ProcurveApiClient
|
||||
from napalm_procurve.connect_reasons import NO_FREE_TELNET_SESSION, TelnetTranscript, failure_reason
|
||||
from napalm_procurve.time_sync import ProcurveTimeSyncMixin
|
||||
|
||||
logger = logging.getLogger("napalm_procurve")
|
||||
|
||||
@@ -83,7 +86,7 @@ _SSH_PORT_BESIDE_API = 22 # SSH beside the REST API: ``port`` then is the API's
|
||||
_CLI_WORD = re.compile(r'^[^\s"#]+$')
|
||||
|
||||
|
||||
class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
class ProcurveDriver(ProcurveTimeSyncMixin, ConfigLifecycleMixin, SwitchDriver):
|
||||
"""NAPALM driver for HPE/Aruba ProCurve switches.
|
||||
|
||||
Auto-detects transport on ``open()``. See module docstring for details.
|
||||
@@ -689,52 +692,6 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
combined = sysinfo + "\n" + env_out
|
||||
return parsers.parse_environment(combined)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# NAPALM: get_ntp_servers
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def get_ntp_servers(self) -> dict[str, dict]:
|
||||
"""Return configured NTP servers."""
|
||||
if self._transport == "api":
|
||||
return self._api.get_ntp_servers()
|
||||
|
||||
out = self._send_command(["show ntp associations", "show ntp status", "show timesync"])
|
||||
return parsers.parse_ntp_servers(out)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# NAPALM: get_ntp_stats
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
def get_ntp_stats(self) -> list[dict]:
|
||||
"""Return NTP peer statistics."""
|
||||
out = self._send_command(["show ntp associations", "show ntp status"])
|
||||
stats = []
|
||||
for line in out.splitlines():
|
||||
m = re.match(
|
||||
r"\s*([*+]?)\s*(\d{1,3}(?:\.\d{1,3}){3})"
|
||||
r"\s+(\S+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)",
|
||||
line,
|
||||
)
|
||||
if not m:
|
||||
continue
|
||||
synced = m.group(1) == "*"
|
||||
stats.append(
|
||||
{
|
||||
"remote": m.group(2),
|
||||
"referenceid": m.group(3),
|
||||
"synchronized": synced,
|
||||
"stratum": int(m.group(4)),
|
||||
"type": "-",
|
||||
"when": m.group(5),
|
||||
"hostpoll": int(m.group(6)) if m.group(6).isdigit() else -1,
|
||||
"reachability": int(m.group(7), 8) if m.group(7).isdigit() else -1,
|
||||
"delay": float(m.group(8)) if _is_float(m.group(8)) else 0.0,
|
||||
"offset": float(m.group(9)) if _is_float(m.group(9)) else 0.0,
|
||||
"jitter": 0.0,
|
||||
}
|
||||
)
|
||||
return stats
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# NAPALM: get_users
|
||||
# ------------------------------------------------------------------
|
||||
@@ -1248,8 +1205,22 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
("firewall", lambda: self._snmp_sources_note(settings)),
|
||||
("start", lambda: self._snmp_save_and_verify(settings)),
|
||||
]
|
||||
try:
|
||||
with self._config_cli():
|
||||
return run_fix_steps(steps)
|
||||
except ConnectionException as exc:
|
||||
failed = {"ok": False, "output": str(exc)}
|
||||
return run_fix_steps([("configure", lambda: failed)])
|
||||
|
||||
@contextmanager
|
||||
def _config_cli(self) -> Iterator[None]:
|
||||
"""The config-mode CLI: this session, or over REST a temporary SSH session on port 22.
|
||||
|
||||
:raises ConnectionException: when no SSH session opens.
|
||||
"""
|
||||
if self._transport != "api":
|
||||
return run_fix_steps(steps)
|
||||
yield
|
||||
return
|
||||
old_api, old_device, old_transport = self._api, self._device, self._transport
|
||||
self._api = self._device = self._transport = None
|
||||
ssh_error = ""
|
||||
@@ -1265,9 +1236,8 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
ssh_error = str(exc)
|
||||
try:
|
||||
if self._device is None:
|
||||
failed = {"ok": False, "output": f"no SSH for the CLI: {ssh_error}"}
|
||||
return run_fix_steps([("configure", lambda: failed)])
|
||||
return run_fix_steps(steps)
|
||||
raise ConnectionException(f"no SSH for the CLI: {ssh_error}")
|
||||
yield
|
||||
finally:
|
||||
if self._device is not None:
|
||||
try:
|
||||
@@ -1315,14 +1285,6 @@ class ProcurveDriver(ConfigLifecycleMixin, SwitchDriver):
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _is_float(s: str) -> bool:
|
||||
try:
|
||||
float(s)
|
||||
return True
|
||||
except (ValueError, TypeError):
|
||||
return False
|
||||
|
||||
|
||||
def _parse_ping_output(output: str, count: int) -> dict:
|
||||
"""Parse ProCurve CLI ping output into NAPALM ping result dict.
|
||||
|
||||
|
||||
Reference in new issue
Block a user