feat: network controller role and get_vlans_detail, 4.60.0 (NetOrk/netork#2787) #151

Merged
christianmanivong merged 2 commits from feature/network-controller-role into main 2026-12-05 16:20:34 +00:00
12 changed files with 319 additions and 2 deletions

No files matched your search

+16
View File
@@ -7,6 +7,22 @@ recorded here; their history is the git log.
## [Unreleased]
## [4.60.0] - 2026-12-05
### Added
- `NetworkControllerDriver` (`network_controller`): a role for a controller that manages
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; 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).
- `SwitchDriver.get_vlans_detail()` and `VlanDetailDict`: every VLAN with its tagged and
untagged ports kept apart. Several switch drivers already offered it and netOrk's poll
already read it; now the contract declares it.
## [4.59.1] - 2026-12-05
### Fixed
+12
View File
@@ -47,6 +47,17 @@ UUID and NIC MACs -- what ties the BMC to the host it manages. Its sensors come
NAPALM's `get_environment`, with `cpu` and `memory` empty, since a BMC does not know the
host OS's load; it has no `HealthMetricsMixin` (SNMP) and no command channel.
A network controller (UniFi Network, TP-Link Omada, Aruba Instant On) is a role of its
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. 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).
A backup server (Proxmox Backup Server) is a role of its own too, `BackupServerDriver`
(`backup_server`). Its datastores, the backup groups in them (each with its newest
snapshot), its jobs (garbage collection, verify, prune, sync, tape) and its remotes have
@@ -748,6 +759,7 @@ Requires Python ≥ 3.12 (tested up to 3.13) and NAPALM ≥ 4.0.
| `PhoneDriver` | IP telephony endpoints | Yealink |
| `MediaDriver` | Speakers, streamers, media renderers | Sonos, Chromecast |
| `ManagementControllerDriver` | Server baseboard management controllers | Supermicro BMC, Dell iDRAC, HPE iLO, Lenovo XCC |
| `NetworkControllerDriver` | Controllers that manage switches, APs and gateways | UniFi Network, TP-Link Omada |
| `BackupServerDriver` | Backup servers: datastores, backup groups, GC/verify/prune/sync/tape jobs | Proxmox Backup Server |
Mixins that come with the classes above: `PingSweepMixin` (subnet sweeps, in
+1 -1
View File
@@ -35,7 +35,7 @@ application SNMP polling, ping sweeps, discovery scoring, guest
| Kind | Rule | Modules |
|---|---|---|
| **Role** | Declares only, under `TYPE_CHECKING`. No runtime method. | `access_point`, `switch`, `firewall`, `hypervisor`, `os`, `storage`, `phone`, `media`, `residential_gateway`, `management_controller`, `backup_server` |
| **Role** | Declares only, under `TYPE_CHECKING`. No runtime method. | `access_point`, `switch`, `firewall`, `hypervisor`, `os`, `storage`, `phone`, `media`, `residential_gateway`, `management_controller`, `network_controller`, `backup_server` |
| **Capability** | Declares only. | `packages`, `services`, `updates`, `nat_vpn`, `mac_acl`, `config_lifecycle`, `interface_filter`, `host_reboot`, `dhcp_leases`, `wireless_writes`, `ap_config`, `host_storage` |
| **Template** | A concrete method that runs a fixed sequence of abstract steps. A driver implements the steps, or overrides the whole method when its device does it in one go. All values come from the caller. | the fix routines below |
| **Contract types** | Interfaces and data shapes other packages implement or fill. | `CommandChannelMixin`, `CommandResult`, `ByteStream`; the declaration of `ContainerEngineMixin`; the reader mixins' public method declarations; the SNMP profile type; `models` |
+13
View File
@@ -31,6 +31,7 @@ Role bases -- what a device *is*:
* :class:`~napalm_device_types.phone.PhoneDriver`
* :class:`~napalm_device_types.media.MediaDriver`
* :class:`~napalm_device_types.management_controller.ManagementControllerDriver`
* :class:`~napalm_device_types.network_controller.NetworkControllerDriver`
* :class:`~napalm_device_types.residential_gateway.ResidentialGatewayDriver`
Function classes -- what a device *can do*. Shared behaviour lives here once
@@ -359,6 +360,12 @@ from napalm_device_types.models import (
UpdateProgressDict,
)
from napalm_device_types.nat_vpn import NatVpnMixin
from napalm_device_types.network_controller import NetworkControllerDriver
from napalm_device_types.network_controller_models import (
MANAGED_DEVICE_ROLES,
MANAGED_DEVICE_STATES,
ManagedDeviceDict,
)
from napalm_device_types.network_mounts import (
NETWORK_MOUNTS_COMMAND,
NetworkMountDict,
@@ -489,6 +496,7 @@ from napalm_device_types.sudo_history import (
SudoHistoryMixin,
)
from napalm_device_types.switch import SwitchDriver
from napalm_device_types.switch_models import VlanDetailDict
from napalm_device_types.system_identity import (
SYSTEM_IDENTITY_COMMAND,
SystemIdentityMixin,
@@ -694,6 +702,9 @@ __all__ = [
"HypervisorDriver",
"InterfaceFilterMixin",
"MacAclMixin",
"MANAGED_DEVICE_ROLES",
"MANAGED_DEVICE_STATES",
"ManagedDeviceDict",
"ManagementControllerDriver",
"ARP_AGE_UNKNOWN",
"POWER_ACTIONS",
@@ -707,6 +718,8 @@ __all__ = [
"FirmwareDict",
"ManagementProtocolsDict",
"MediaDriver",
"NetworkControllerDriver",
"VlanDetailDict",
"NatVpnMixin",
"OSDriver",
"PackageManagementMixin",
+70
View File
@@ -0,0 +1,70 @@
"""
Abstract base class for network controllers: devices that manage other devices.
Usage::
from napalm_device_types import NetworkControllerDriver
class UnifiNetworkDriver(NetworkControllerDriver):
def get_managed_devices(self):
...
"""
from typing import TYPE_CHECKING
from napalm_device_types.base import DeviceTypeDriver
if TYPE_CHECKING: # pragma: no cover - for type checkers only
from napalm_device_types.network_controller_models import ManagedDeviceDict
class NetworkControllerDriver(DeviceTypeDriver):
"""
Abstract intermediate driver for a controller that adopts, configures and
watches switches, access points and gateways (e.g. UniFi Network, TP-Link
Omada, Aruba Instant On), reached over its API.
A controller is a device of its own, and it is not the devices it manages.
:meth:`get_managed_devices` reports *which* devices it manages; each of them
is polled as a device of its own -- through the controller, or directly --
with its own driver. The controller's ``get_interfaces``,
``get_interfaces_ip``, ``get_lldp_neighbors`` and ``get_mac_address_table``
are therefore its own, never its children's: reporting a switch's ports here
would attach that switch's MAC addresses to the wrong device.
What a managed device means to the application (a new device, a link to one
it already knows) is the application's decision; the driver reports.
"""
#: Stable key netOrk exposes as ``device_class``. The order in which a
#: driver lists its role bases is the ranking; see
#: :func:`napalm_device_types.roles.primary_role_of`.
ROLE: str = "network_controller"
TYPE_LABEL: str = "Network Controller"
USES_SSH: bool = False
if TYPE_CHECKING:
def get_managed_devices(self) -> list[ManagedDeviceDict]:
"""
Returns every device the controller manages or that waits to be
adopted by it, across all of its sites.
A device the controller has lost contact with is listed as
``offline``, not left out. A read that fails raises; an empty list
means a controller that manages nothing.
Example::
[
{"mac": "f4:92:bf:00:00:01", "name": "usw-office",
"model": "USW24P250", "role": "switch", "state": "online",
"site": "default", "ip": "192.0.2.21",
"id": "5e2f7c1b8a5d3f0012345678", "serial": "F492BF000001",
"model_name": "USW 24 PoE", "firmware": "7.1.26.15869"},
{"mac": "78:8a:20:00:00:02", "name": "", "model": "U7PG2",
"role": "access_point", "state": "pending",
"site": "default", "ip": None},
]
"""
...
@@ -0,0 +1,56 @@
"""The shapes a network controller's getters return.
No ``from __future__ import annotations`` here: TypedDict reads ``NotRequired`` only
in an evaluated annotation (#144).
"""
from typing import Any, NotRequired
from typing_extensions import TypedDict
#: What a managed device is, in the controller's report.
MANAGED_DEVICE_ROLES: tuple[str, ...] = ("switch", "access_point", "gateway", "other")
#: Where a managed device stands with its controller. ``pending`` waits to be
#: adopted; ``busy`` is adopting, provisioning or upgrading.
MANAGED_DEVICE_STATES: tuple[str, ...] = ("online", "offline", "pending", "busy")
class ManagedDeviceDict(TypedDict):
"""One device a controller manages, as the controller reports it.
* mac (str) - the device's base MAC address, lower case, colon-separated
* name (str) - its name on the controller; ``""`` when it has none
* model (str) - the vendor's model code, e.g. ``"USW24P250"``
* role (str) - one of :data:`MANAGED_DEVICE_ROLES`
* state (str) - one of :data:`MANAGED_DEVICE_STATES`
* site (str) - the controller's site the device belongs to, in the controller's
own words (a controller can run several)
* ip (str or None) - its management address; ``None`` while it has none
* id (str, optional) - the controller's own identifier for the device
* serial (str, optional) - the serial number, where the controller reports it
* model_name (str, optional) - the product name, e.g. ``"USW Pro 24 PoE"``
* 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
name: str
model: str
role: str
state: str
site: str
ip: str | None
id: NotRequired[str]
serial: NotRequired[str]
model_name: NotRequired[str]
firmware: NotRequired[str]
firmware_available: NotRequired[str]
driver: NotRequired[str]
driver_args: NotRequired[dict[str, Any]]
+19
View File
@@ -24,6 +24,7 @@ from napalm_device_types.models import (
SpanningTreeDict,
VlanConfigDict,
)
from napalm_device_types.switch_models import VlanDetailDict
class SwitchDriver(MacAclMixin, DeviceTypeDriver):
@@ -247,6 +248,24 @@ class SwitchDriver(MacAclMixin, DeviceTypeDriver):
"""
...
def get_vlans_detail(self) -> dict[str, VlanDetailDict]:
"""
Returns every VLAN on the switch with its ports, tagged and untagged
kept apart -- what NAPALM's ``get_vlans`` folds into one list.
Keyed by the VLAN ID as a string. A port is in ``untagged`` of the
VLAN that is its native (PVID) VLAN, and in ``tagged`` of every VLAN
it carries tagged.
Example::
{
"1": {"name": "Default", "tagged": [], "untagged": ["Port 2", "Port 3"]},
"20": {"name": "Voice", "tagged": ["Port 1"], "untagged": ["Port 4"]},
}
"""
...
def set_vlan(self, vlan_id: int, config: VlanConfigDict) -> None:
"""
Creates or updates a VLAN on the switch.
+19
View File
@@ -0,0 +1,19 @@
"""The shapes a switch's getters return, beyond the older ones in ``models.py``.
``models.py`` is over the size limit and may not grow; new switch shapes live here.
"""
from typing_extensions import TypedDict
class VlanDetailDict(TypedDict):
"""One VLAN with its ports, tagged and untagged kept apart.
* name (str) - the VLAN's name; ``""`` when it has none
* tagged (list of str) - interfaces that carry the VLAN tagged
* untagged (list of str) - interfaces whose untagged (native, PVID) VLAN it is
"""
name: str
tagged: list[str]
untagged: list[str]
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "napalm-device-types"
version = "4.59.1"
version = "4.60.0"
description = "Abstract device-type base classes for NAPALM drivers"
readme = "README.md"
requires-python = ">=3.12"
+106
View File
@@ -0,0 +1,106 @@
"""The network controller role: a device that manages other devices (NetOrk/netork#2787).
A controller (UniFi Network, Omada, Aruba Instant On, ...) is a device of its own.
It reports *which* switches, access points and gateways it manages; each of those
is polled as a device of its own, so the controller never reports their ports,
addresses or neighbours as its own.
"""
from __future__ import annotations
import typing
import pytest
import napalm_device_types as package
from napalm_device_types import (
FirewallDriver,
ManagedDeviceDict,
NetworkControllerDriver,
SwitchDriver,
VlanDetailDict,
)
from napalm_device_types.roles import primary_role_of, role_keys_of
class TestRole:
def test_role_key_label_and_transport(self):
assert NetworkControllerDriver.ROLE == "network_controller"
assert NetworkControllerDriver.TYPE_LABEL == "Network Controller"
assert NetworkControllerDriver.USES_SSH is False
def test_get_managed_devices_is_declared_not_implemented(self):
"""hasattr is the capability probe: absent until a driver provides it."""
assert not hasattr(NetworkControllerDriver, "get_managed_devices")
def test_docstring_says_the_children_are_not_its_own(self):
doc = NetworkControllerDriver.__doc__ or ""
assert "get_managed_devices" in doc
assert "get_interfaces" in doc
def test_a_console_that_also_routes_ranks_its_roles(self):
class Console(NetworkControllerDriver, FirewallDriver):
pass
assert primary_role_of(Console) == "network_controller"
assert role_keys_of(Console) == ["network_controller", "firewall"]
class TestManagedDeviceDict:
def test_required_keys(self):
assert ManagedDeviceDict.__required_keys__ == frozenset(
{"mac", "name", "model", "role", "state", "site", "ip"}
)
def test_optional_keys(self):
assert ManagedDeviceDict.__optional_keys__ == frozenset(
{
"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")
assert package.MANAGED_DEVICE_STATES == ("online", "offline", "pending", "busy")
@pytest.mark.parametrize(
"name",
[
"NetworkControllerDriver",
"ManagedDeviceDict",
"MANAGED_DEVICE_ROLES",
"MANAGED_DEVICE_STATES",
"VlanDetailDict",
],
)
def test_exported(self, name):
assert name in package.__all__ and hasattr(package, name)
class TestVlansDetail:
"""The poll has read get_vlans_detail for years; now the switch contract says so."""
def test_declared_on_the_switch_not_implemented(self):
assert not hasattr(SwitchDriver, "get_vlans_detail")
from napalm_device_types import switch
assert "def get_vlans_detail" in open(switch.__file__, encoding="utf-8").read()
def test_shape(self):
assert VlanDetailDict.__required_keys__ == frozenset({"name", "tagged", "untagged"})
hints = typing.get_type_hints(VlanDetailDict)
assert hints["tagged"] == list[str]
+4
View File
@@ -25,6 +25,7 @@ from napalm_device_types import (
HypervisorDriver,
ManagementControllerDriver,
MediaDriver,
NetworkControllerDriver,
OSDriver,
PhoneDriver,
ResidentialGatewayDriver,
@@ -40,6 +41,7 @@ ROLE_BASES = [
HypervisorDriver,
ManagementControllerDriver,
MediaDriver,
NetworkControllerDriver,
OSDriver,
PhoneDriver,
ResidentialGatewayDriver,
@@ -97,6 +99,8 @@ class TestDeclaredMethodsDoNotExistAtRuntime:
(ManagementControllerDriver, "get_event_log"),
(ManagementControllerDriver, "get_firmware_inventory"),
(ManagementControllerDriver, "get_management_protocols"),
(NetworkControllerDriver, "get_managed_devices"),
(SwitchDriver, "get_vlans_detail"),
],
)
def test_absent_until_a_driver_implements_it(self, base, method):
+2
View File
@@ -8,6 +8,7 @@ from napalm_device_types import (
FirewallDriver,
HypervisorDriver,
ManagementControllerDriver,
NetworkControllerDriver,
OSDriver,
ResidentialGatewayDriver,
StorageDriver,
@@ -20,6 +21,7 @@ BASE_CLASSES = [
(FirewallDriver, "Firewall"),
(HypervisorDriver, "Hypervisor"),
(ManagementControllerDriver, "Management Controller"),
(NetworkControllerDriver, "Network Controller"),
(OSDriver, "OS"),
(ResidentialGatewayDriver, "Gateway"),
(StorageDriver, "Storage"),