feat(time-sync): w32time's servers and the time zone through TimeSyncMixin
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 14s
driver / types (pull_request) Successful in 57s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 51s
driver / lowest (pull_request) Successful in 26s
driver / build (pull_request) Successful in 27s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m23s
driver / publish (pull_request) Skipped

netOrk keeps one list of NTP servers and a time zone per site and aligns
a device that differs (NetOrk/netork#2360). A Windows host takes part
through w32time and its time zone, in one PowerShell script per read.

The servers and the mode are read from w32time's registry values, group
policy's first, not from w32tm /query /configuration, whose text is in
the host's language; synchronised is the leap indicator on the first
line of w32tm /query /status, which reads the same in any language. The
servers are written the way w32tm /config /manualpeerlist
/syncfromflags:manual writes them (NtpServer with 0x8, Type NTP),
followed by w32tm /config /update: no value passes a native command
line, whose quoting Windows PowerShell 5.1 mangles. A domain member that
takes its time from the domain hierarchy (NT5DS, AllSync) and a host
whose w32time comes from group policy refuse the write: their time is
set elsewhere, and a local write would be overridden or break the
domain's time.

Windows keeps a Windows zone, which stands for several IANA zones, so
Europe/Vienna written would read back as Europe/Berlin and the poll
would align the host forever. The IANA name written is kept beside it
in HKLM\SOFTWARE\napalm-windows and read back while the host is still
in that Windows zone. The zone is read from the registry, which
[TimeZoneInfo]::Local caches for the life of the remote session.

The zone table is now CLDR's windowsZones.xml (release 49) both ways,
generated by tools/windows_zones.py with tzdata's links and committed
with its source and checksum; nothing is fetched at runtime. CLDR's old
names (Asia/Calcutta) read as their current ones (Asia/Kolkata).

Writes the host already has are skipped. Needs napalm-device-types
4.35.0.

Refs NetOrk/netork#2367
This commit is contained in:
Christian Manivong committed 2026-11-11 15:27:56 +01:00
1 parent 37708009a0
commit 0b30ab00a5
12 files changed
+1481 -108

No files matched your search

+26
View File
@@ -41,6 +41,7 @@ handshake once.
| `get_scheduled_jobs` | `Get-ScheduledTask` + `Get-ScheduledTaskInfo`, one script; `\Microsoft\*` is `platform`, other tasks `admin`, the root task an application wrote `application`; time zone mapped to IANA for the common zones |
| `manage_scheduled_job` | `Enable-`/`Disable-ScheduledTask`, `Start-ScheduledTask` (returns once started; the result shows in the next reading) |
| `put_scheduled_job` / `delete_scheduled_job` | `Register-ScheduledTask -Xml -Force` in the root folder, `Unregister-ScheduledTask`; an application's tasks only |
| `get_time_sync` / `configure_time_sync` | w32time's registry values (group policy first), `w32tm /query /status`, the registry's `TimeZoneInformation`; writes `NtpServer`/`Type` + `w32tm /config /update`, `Set-TimeZone`. See *Time sync* |
`running_kernel` carries the full build including the update revision
(`10.0.20348.2340`): Windows ships fixes as UBR bumps, which is what CVE
@@ -70,6 +71,31 @@ changed by hand count as a change.
vendor's updater is `admin`; and the days of a monthly trigger, which
`Get-ScheduledTask` does not expose.
### Time sync
napalm-device-types' `TimeSyncMixin`; both the servers and the zone are written.
* **Servers** are w32time's `NtpServer` in order, without their `,0x` flags; group
policy's values (`HKLM\SOFTWARE\Policies\Microsoft\W32Time\Parameters`) win over
the local ones. `Type NoSync` has none. Written as `<server>,0x8` (client mode) with
`Type NTP` — what `w32tm /config /manualpeerlist /syncfromflags:manual` writes —
then `w32tm /config /update`; a stopped Windows Time service is started first.
* **Domain members** that take their time from the domain hierarchy (`Type NT5DS` or
`AllSync`) report the servers configured, and a write is refused: the domain sets
their time. So is a write where group policy sets w32time.
* **Synchronised** is the leap indicator of `w32tm /query /status` (`3` = not
synchronised); a stopped service is not synchronised. `daemon` is `w32time`.
* **Zone:** Windows keeps a Windows zone (`W. Europe Standard Time`), which stands
for several IANA zones. It is read as the zone CLDR names for it (`Europe/Berlin`)
and written with `Set-TimeZone` from CLDR's mapping
([`windowsZones.xml`](https://github.com/unicode-org/cldr/blob/release-49/common/supplemental/windowsZones.xml),
generated into `napalm_windows/_windows_zones.py` by `tools/windows_zones.py`,
never fetched at runtime). The IANA name written is kept in
`HKLM\SOFTWARE\napalm-windows` (`IanaTimeZone`) and read back while the host is
still in that Windows zone, so `Europe/Vienna` reads back as `Europe/Vienna`. A
zone with summer time switched off reads as `None`; writing the zone switches it
back on.
Not yet: packages, Windows Update, health metrics, Hyper-V.
See netork#300 for the plan.