From 081ef62d227b820a99fab84c5093fbde8a6a19c8 Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sat, 5 Dec 2026 17:16:32 +0100 Subject: [PATCH] feat: a managed device names its driver and how to reach it 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). --- CHANGELOG.md | 3 ++- README.md | 4 +++- napalm_device_types/network_controller_models.py | 9 ++++++++- tests/test_network_controller.py | 14 +++++++++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daaece1..8d69002 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/README.md b/README.md index c2abd75..da32fe0 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/napalm_device_types/network_controller_models.py b/napalm_device_types/network_controller_models.py index 7922888..d2d2742 100644 --- a/napalm_device_types/network_controller_models.py +++ b/napalm_device_types/network_controller_models.py @@ -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]] diff --git a/tests/test_network_controller.py b/tests/test_network_controller.py index d555a34..6ecacde 100644 --- a/tests/test_network_controller.py +++ b/tests/test_network_controller.py @@ -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")