feat(time-sync): the switch's NTP servers and zone through TimeSyncMixin
driver / lint (pull_request) Successful in 13s
driver / standard (pull_request) Successful in 16s
driver / types (pull_request) Successful in 59s
driver / test (3.13) (pull_request) Successful in 52s
driver / test (3.12) (pull_request) Successful in 1m1s
driver / lowest (pull_request) Successful in 26s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 58s
CI / driver (pull_request) Successful in 2m6s
driver / publish (pull_request) Skipped

netOrk aligns every device's NTP servers and time zone with its site's
(NetOrk/netork#2360, #2366). A JetStream keeps both in one line,
system-time ntp <zone> <primary> <backup> <hours>, with the zone as a
UTC offset from a fixed list and summer time in a system-time dst line
of its own.

get_time_sync() reads the servers from that line and the zone as None:
the switch keeps no name to map back. configure_time_sync() writes an
IANA zone as its offset and a dst recurring rule from the zone's POSIX
rule (posix_tz/parse_posix_tz), and refuses before sending anything
what the switch cannot take: more than two servers, anything but IPv4
addresses, an offset it does not offer, a change outside HH:MM of a day.
Servers and zone share the ntp line, so a call with both writes it once.
A change is saved to the startup configuration; values the switch
already has are not sent again, so the alignment on every poll does not
churn.

The code lives in time_sync.py; get_ntp_servers() now reads through it,
so the driver file shrinks (1999 -> 1987 lines).
This commit is contained in:
Christian Manivong committed 2026-11-11 15:17:51 +01:00
1 parent 7af20c5889
commit dc41b8497e
7 files changed
+575 -20

No files matched your search

+6 -18
View File
@@ -40,6 +40,7 @@ from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutExc
from napalm_tplink_jetstream._ssh import netmiko_connect_args
from napalm_tplink_jetstream.parsers import parse_snmp_communities, parse_snmp_community_access
from napalm_tplink_jetstream.time_sync import JetstreamTimeSyncMixin
logger = logging.getLogger(__name__)
@@ -47,7 +48,9 @@ logger = logging.getLogger(__name__)
_PASSWORD_NOT_SHOWN = "" # nosec B105
class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
class TPLinkJetstreamDriver(
JetstreamTimeSyncMixin, ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver
):
"""NAPALM driver for TP-Link Jetstream managed switches."""
VENDOR = "TP-Link"
@@ -1459,23 +1462,8 @@ class TPLinkJetstreamDriver(ConfigLifecycleMixin, SnmpAgentMixin, SwitchDriver):
}
def get_ntp_servers(self) -> dict[str, dict]:
"""Return configured NTP servers.
Extracts the server list from the running configuration line::
system-time ntp <timezone> <server1> [<server2> ...] <interval>
"""
running = self._send_command("show running-config")
servers: dict[str, dict] = {}
for line in running.splitlines():
m = re.match(r"^system-time\s+ntp\s+\S+\s+(.*)", line.strip(), re.I)
if m:
tokens = m.group(1).split()
# Last token is the update interval (numeric), rest are servers
server_tokens = [t for t in tokens if not t.isdigit()]
for srv in server_tokens:
servers[srv] = {}
return servers
"""The servers of the ``system-time ntp`` line, as ``get_time_sync`` reads them."""
return {server: {} for server in self.get_time_sync()["ntp_servers"]}
def get_ntp_peers(self) -> dict[str, dict]:
"""Return NTP peers (same as servers on TP-Link Jetstream)."""