feat: a managed device names its driver and how to reach it
driver / standard (pull_request) Successful in 22s
driver / lint (pull_request) Successful in 20s
driver / types (pull_request) Successful in 54s
driver / lowest (pull_request) Successful in 53s
driver / test (3.13) (pull_request) Successful in 1m8s
driver / build (pull_request) Successful in 34s
driver / test (3.12) (pull_request) Successful in 1m39s
driver / security (pull_request) Successful in 1m3s
CI / driver (pull_request) Successful in 2m19s
driver / publish (pull_request) Skipped

ManagedDeviceDict gets two optional keys: driver, the entry point that
polls the device, and driver_args, the optional args that reach it through
the controller (never a secret). With them a caller can add a controller's
devices without knowing the vendor (NetOrk/netork#2787).
This commit is contained in:
christianmanivong committed 2026-12-05 17:16:32 +01:00
1 parent d5ffb0f0fa
commit 081ef62d22
4 files changed
+26 -4

No files matched your search

+2 -1
View File
@@ -14,7 +14,8 @@ recorded here; their history is the git log.
switches, access points and gateways (UniFi Network, Omada, Instant On). It declares
`get_managed_devices()`, which reports each managed or pending device as a
`ManagedDeviceDict` (MAC, name, model, role, state, site, address; serial, firmware and
the controller's own id where known). `MANAGED_DEVICE_ROLES` and
the controller's own id where known; the driver that polls it and the optional args
that driver needs to reach it through the controller, never a secret). `MANAGED_DEVICE_ROLES` and
`MANAGED_DEVICE_STATES` name the words. Each managed device is polled with a driver of
its own; the controller never reports their ports or neighbours as its own
(NetOrk/netork#2787).
+3 -1
View File
@@ -52,7 +52,9 @@ own, `NetworkControllerDriver` (`network_controller`), reached over its API
(`USES_SSH = False`). It is not the switches, access points and gateways it manages:
`get_managed_devices` reports *which* devices it manages (`ManagedDeviceDict`: MAC, name,
model, role, state, site, address, and where known serial and firmware), and each of them is
polled as a device of its own with its own driver. Its `get_interfaces`,
polled as a device of its own with its own driver. Where the controller knows that driver, it
names it (`driver`) with the optional args that reach the device through the controller
(`driver_args`, never a secret); the caller links the controller's credential to the child. Its `get_interfaces`,
`get_lldp_neighbors` and `get_mac_address_table` are the controller's own, never its
children's (NetOrk/netork#2787).
@@ -4,7 +4,7 @@ No ``from __future__ import annotations`` here: TypedDict reads ``NotRequired``
in an evaluated annotation (#144).
"""
from typing import NotRequired
from typing import Any, NotRequired
from typing_extensions import TypedDict
@@ -33,6 +33,11 @@ class ManagedDeviceDict(TypedDict):
* firmware (str, optional) - the running firmware version
* firmware_available (str, optional) - the version the controller would
upgrade it to; left out when it has none
* driver (str, optional) - the NAPALM driver that polls this device, by its
entry point name (``"unifi_switch"``); left out where none does
* driver_args (dict, optional) - the optional args that driver needs to reach
the device through this controller (address, site, device id). Never a
secret: the caller hands the child the controller's credential itself
"""
mac: str
@@ -47,3 +52,5 @@ class ManagedDeviceDict(TypedDict):
model_name: NotRequired[str]
firmware: NotRequired[str]
firmware_available: NotRequired[str]
driver: NotRequired[str]
driver_args: NotRequired[dict[str, Any]]
+13 -1
View File
@@ -54,12 +54,24 @@ class TestManagedDeviceDict:
def test_optional_keys(self):
assert ManagedDeviceDict.__optional_keys__ == frozenset(
{"id", "serial", "model_name", "firmware", "firmware_available"}
{
"id",
"serial",
"model_name",
"firmware",
"firmware_available",
"driver",
"driver_args",
}
)
def test_every_annotation_resolves(self):
hints = typing.get_type_hints(ManagedDeviceDict)
assert hints["ip"] == str | None
assert hints["driver_args"] == dict[str, typing.Any]
def test_the_docstring_keeps_secrets_out_of_driver_args(self):
assert "never a secret" in " ".join((ManagedDeviceDict.__doc__ or "").lower().split())
def test_roles_and_states_are_exported_words(self):
assert package.MANAGED_DEVICE_ROLES == ("switch", "access_point", "gateway", "other")