From 2ad1ead2f563f09c06eadcd4bf0562f2062f7d6f Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Sun, 29 Nov 2026 20:48:04 +0100 Subject: [PATCH] refactor(access-point): the new shapes beside their declarations, models.py within its ratchet DhcpLeaseDict lives in dhcp_leases, the AP shapes in access_point_models; models.py stays at its recorded size. --- napalm_device_types/__init__.py | 13 +++++++------ napalm_device_types/ap_config.py | 2 +- napalm_device_types/dhcp_leases.py | 17 ++++++++++++++++- napalm_device_types/models.py | 20 -------------------- napalm_device_types/wireless_writes.py | 2 +- tests/test_ap_dhcp_contracts.py | 10 +++++----- 6 files changed, 30 insertions(+), 34 deletions(-) diff --git a/napalm_device_types/__init__.py b/napalm_device_types/__init__.py index 5620034..a8a851a 100644 --- a/napalm_device_types/__init__.py +++ b/napalm_device_types/__init__.py @@ -86,6 +86,12 @@ Introspection -- :func:`~napalm_device_types.roles.roles_of`, """ from napalm_device_types.access_point import AccessPointDriver +from napalm_device_types.access_point_models import ( + ApConfigDict, + ApConfigResultDict, + ApSsidConfigDict, + SsidConfigDict, +) from napalm_device_types.ap_config import ( AP_CONFIG_PARTS, AP_CONFIG_SSID_ATTRIBUTES, @@ -180,7 +186,7 @@ from napalm_device_types.credential_expiry import ( CredentialKind, ) from napalm_device_types.dhcp import DhcpApplyError, DhcpServerMixin, normalize_cidr, normalize_mac -from napalm_device_types.dhcp_leases import DhcpLeasesMixin +from napalm_device_types.dhcp_leases import DhcpLeaseDict, DhcpLeasesMixin from napalm_device_types.dns_forward import DnsForwardMixin from napalm_device_types.firewall import FirewallDriver from napalm_device_types.firewall_rules import FirewallRuleMixin @@ -277,13 +283,9 @@ from napalm_device_types.management_controller import ManagementControllerDriver from napalm_device_types.media import MediaDriver from napalm_device_types.models import ( POWER_ACTIONS, - ApConfigDict, - ApConfigResultDict, - ApSsidConfigDict, ConfigSyncDict, DhcpHaDict, DhcpHaPeerDict, - DhcpLeaseDict, DnsForwardDict, EventLogEntryDict, FirmwareDict, @@ -299,7 +301,6 @@ from napalm_device_types.models import ( PowerAction, PowerStateDict, SnmpAgentSettingsDict, - SsidConfigDict, UpdateProgressDict, ) from napalm_device_types.nat_vpn import NatVpnMixin diff --git a/napalm_device_types/ap_config.py b/napalm_device_types/ap_config.py index ef8cd0f..ba1d8d8 100644 --- a/napalm_device_types/ap_config.py +++ b/napalm_device_types/ap_config.py @@ -17,7 +17,7 @@ from __future__ import annotations from typing import TYPE_CHECKING -from napalm_device_types.models import ApConfigDict, ApConfigResultDict +from napalm_device_types.access_point_models import ApConfigDict, ApConfigResultDict #: The parts without a subject, and the values of ``ApConfigDict`` each writes. AP_CONFIG_PARTS = frozenset( diff --git a/napalm_device_types/dhcp_leases.py b/napalm_device_types/dhcp_leases.py index 631dc1d..32d7da7 100644 --- a/napalm_device_types/dhcp_leases.py +++ b/napalm_device_types/dhcp_leases.py @@ -15,7 +15,22 @@ from __future__ import annotations from typing import TYPE_CHECKING -from napalm_device_types.models import DhcpLeaseDict +from typing_extensions import TypedDict + + +class DhcpLeaseDict(TypedDict): + """A lease a DHCP server handed out (``DhcpLeasesMixin.get_dhcp_leases``). + + ``mac`` lower-case and colon-separated; ``hostname`` "" when the client sent + none; ``lease_end`` the Unix time the lease ends, 0 when it does not end or is + not known; ``state`` the server's own word for it ("" when it has none). + """ + + mac: str + ip: str + hostname: str + lease_end: int + state: str class DhcpLeasesMixin: diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index 455c731..60f6744 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -8,10 +8,6 @@ from typing import Literal, NotRequired, get_args from typing_extensions import TypedDict -from napalm_device_types.access_point_models import ApConfigDict as ApConfigDict -from napalm_device_types.access_point_models import ApConfigResultDict as ApConfigResultDict -from napalm_device_types.access_point_models import ApSsidConfigDict as ApSsidConfigDict - # The SNMP health profile shapes live in snmp_health_profile.py, those of the access # point getters in access_point_models.py; re-exported here, where they were. from napalm_device_types.access_point_models import ChannelScanEntryDict as ChannelScanEntryDict @@ -22,7 +18,6 @@ from napalm_device_types.access_point_models import MeshConfigDict as MeshConfig from napalm_device_types.access_point_models import MeshPeerDict as MeshPeerDict from napalm_device_types.access_point_models import RadioStatusDict as RadioStatusDict from napalm_device_types.access_point_models import SSIDBridgeDict as SSIDBridgeDict -from napalm_device_types.access_point_models import SsidConfigDict as SsidConfigDict from napalm_device_types.access_point_models import SSIDDict as SSIDDict from napalm_device_types.access_point_models import WirelessClientDict as WirelessClientDict from napalm_device_types.access_point_models import WirelessConfigDict as WirelessConfigDict @@ -540,21 +535,6 @@ class FirewallRuleDiffDict(TypedDict): update: list[FirewallRuleUpdateDict] -class DhcpLeaseDict(TypedDict): - """A lease a DHCP server handed out (``DhcpLeasesMixin.get_dhcp_leases``). - - ``mac`` lower-case and colon-separated; ``hostname`` "" when the client sent - none; ``lease_end`` the Unix time the lease ends, 0 when it does not end or is - not known; ``state`` the server's own word for it ("" when it has none). - """ - - mac: str - ip: str - hostname: str - lease_end: int - state: str - - class DhcpReservationDict(TypedDict): """A single static DHCP reservation (MAC -> IP), in vendor-neutral form. diff --git a/napalm_device_types/wireless_writes.py b/napalm_device_types/wireless_writes.py index 0a16736..33a4538 100644 --- a/napalm_device_types/wireless_writes.py +++ b/napalm_device_types/wireless_writes.py @@ -10,7 +10,7 @@ from __future__ import annotations from typing import TYPE_CHECKING -from napalm_device_types.models import SsidConfigDict +from napalm_device_types.access_point_models import SsidConfigDict #: The channel that lets a radio choose its own (``set_radio_channels``). AUTO_CHANNEL = 0 diff --git a/tests/test_ap_dhcp_contracts.py b/tests/test_ap_dhcp_contracts.py index 0200e92..1bd4ccb 100644 --- a/tests/test_ap_dhcp_contracts.py +++ b/tests/test_ap_dhcp_contracts.py @@ -179,12 +179,12 @@ class TestDeclarations: ): assert name in napalm_device_types.__all__, name - def test_models_re_exports_the_shapes(self): - from napalm_device_types import models + def test_the_shapes_live_beside_their_declarations(self): + from napalm_device_types import access_point_models, dhcp_leases - assert models.DhcpLeaseDict is DhcpLeaseDict - assert models.SsidConfigDict is SsidConfigDict - assert models.ApConfigDict is ApConfigDict + assert dhcp_leases.DhcpLeaseDict is DhcpLeaseDict + assert access_point_models.SsidConfigDict is SsidConfigDict + assert access_point_models.ApConfigDict is ApConfigDict class TestParts: