Merge remote-tracking branch 'origin/main' into feat/tls-fingerprint-tofu
driver / lint (pull_request) Successful in 14s
driver / standard (pull_request) Successful in 15s
driver / test (3.13) (pull_request) Successful in 1m14s
driver / types (pull_request) Failing after 1m35s
driver / test (3.12) (pull_request) Successful in 1m27s
driver / lowest (pull_request) Successful in 34s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 59s
CI / driver (pull_request) Failing after 2m34s
driver / publish (pull_request) Skipped

# Conflicts:
#	CHANGELOG.md
This commit is contained in:
christianmanivong committed 2026-11-02 00:06:53 +01:00
commit 516fb18c0e
13 files changed
+357 -68

No files matched your search

+10 -4
View File
@@ -110,6 +110,7 @@ from napalm_device_types.firewall_rules import FirewallRuleMixin
from napalm_device_types.firmware import FirmwareOfferMixin
from napalm_device_types.fixes import (
EnsurePackageMixin,
LldpAgentMixin,
PackageProxyMixin,
SnmpAgentMixin,
run_fix_steps,
@@ -163,10 +164,6 @@ from napalm_device_types.models import (
PowerAction,
PowerStateDict,
SnmpAgentSettingsDict,
SnmpHealthProfile,
SnmpInterfacesSpec,
SnmpMemorySpec,
SnmpValueSpec,
UpdateProgressDict,
)
from napalm_device_types.nat_vpn import NatVpnMixin
@@ -181,6 +178,7 @@ from napalm_device_types.package_updates import (
from napalm_device_types.packages import PackageManagementMixin
from napalm_device_types.phone import PhoneDriver
from napalm_device_types.ping_sweep import PingSweepMixin, driver_supports_ping
from napalm_device_types.provisioning import VMProvisionIncomplete
from napalm_device_types.residential_gateway import ResidentialGatewayDriver
from napalm_device_types.roles import primary_role_of, role_keys_of, roles_of
from napalm_device_types.service_clusters import (
@@ -195,6 +193,12 @@ from napalm_device_types.service_packages import (
parse_service_packages,
)
from napalm_device_types.services import ServiceControlMixin
from napalm_device_types.snmp_health_profile import (
SnmpHealthProfile,
SnmpInterfacesSpec,
SnmpMemorySpec,
SnmpValueSpec,
)
from napalm_device_types.ssh_host_keys import (
KNOWN_KEYS_ARG as SSH_HOST_KEYS_ARG,
)
@@ -268,6 +272,7 @@ __all__ = [
"FixResultDict",
"FixStepDict",
"FixStepOutcomeDict",
"LldpAgentMixin",
"PackageProxyMixin",
"APT_PROXY_COMMAND",
"AptProxyMixin",
@@ -361,6 +366,7 @@ __all__ = [
"VIRTUAL_IPS_COMMAND",
"VirtualIpsMixin",
"VmStopRequestMixin",
"VMProvisionIncomplete",
"SERVICE_CLUSTERS_COMMAND",
"ServiceClustersMixin",
"parse_service_clusters",
+62 -1
View File
@@ -22,7 +22,7 @@ They replace ``run_device_action`` (docs/STRUCTURE.md):
from __future__ import annotations
from collections.abc import Callable, Sequence
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, ClassVar
from napalm_device_types.models import (
FixResultDict,
@@ -133,6 +133,66 @@ class EnsurePackageMixin:
def install_package(self, name: str, version: str = "") -> None: ...
class LldpAgentMixin:
"""Run an LLDP agent on the device, on the interfaces the caller names.
The steps: install the agent, write the interfaces it runs on, enable it at boot
and restart it so it reads them. Installing and starting are generic, over
``ensure_package`` and ``manage_service`` with ``LLDP_AGENT_PACKAGE`` and
``LLDP_AGENT_SERVICE``; the driver writes the configuration. Which interfaces is
the caller's choice -- an agent on every interface also talks to the uplink of a
WAN port. Whether neighbours appear is the caller's to read with
``get_lldp_neighbors``, after the agent's first advertisement interval.
"""
#: The package that brings the agent, as ``ensure_package`` takes it.
LLDP_AGENT_PACKAGE: ClassVar[str] = "lldpd"
#: The agent's service, as ``manage_service`` takes it.
LLDP_AGENT_SERVICE: ClassVar[str] = "lldpd"
def configure_lldp_agent(self, interfaces: Sequence[str]) -> FixResultDict:
"""Install, configure for *interfaces*, enable and restart the agent.
:raises ValueError: for no interface, before anything changes.
"""
names = [str(name) for name in interfaces]
if not names:
raise ValueError("name at least one interface for the LLDP agent")
return run_fix_steps(
[
("install", self._install_lldp_agent),
("configure", lambda: self._write_lldp_agent_config(names)),
("start", self._start_lldp_agent),
]
)
def _install_lldp_agent(self) -> FixStepOutcomeDict:
result = self.ensure_package(self.LLDP_AGENT_PACKAGE)
return {"ok": bool(result["success"]), "output": str(result.get("output", ""))}
def _start_lldp_agent(self) -> FixStepOutcomeDict:
service = self.LLDP_AGENT_SERVICE
for action in ("enable", "restart"):
result = self.manage_service(service, action)
if not result.get("success"):
output = str(result.get("output", "")).strip()
return {"ok": False, "output": f"{action} {service}: {output}".rstrip(": ")}
return {"ok": True, "output": f"{service} enabled and restarted"}
if TYPE_CHECKING: # pragma: no cover - declared for type checkers only
def ensure_package(self, name: str) -> FixResultDict: ...
def manage_service(self, name: str, action: str) -> dict[str, Any]: ...
# The step a driver implements:
def _write_lldp_agent_config(self, interfaces: list[str]) -> FixStepOutcomeDict:
"""Have the agent send and listen on exactly *interfaces* (names as the
device's interface getters report them), replacing the list it had."""
...
class PackageProxyMixin:
"""Point the device's package manager at a caching proxy."""
@@ -152,6 +212,7 @@ class PackageProxyMixin:
__all__ = [
"EnsurePackageMixin",
"FixStep",
"LldpAgentMixin",
"PackageProxyMixin",
"SnmpAgentMixin",
"run_fix_steps",
+2 -2
View File
@@ -2,8 +2,8 @@
**Deprecated** (docs/STRUCTURE.md): drivers do not collect over SNMP. The
application polls; a driver whose device publishes values under its own OIDs
declares them as ``SNMP_HEALTH_PROFILE`` (:class:`~napalm_device_types.models.SnmpHealthProfile`).
This mixin goes in 5.0.
declares them as ``SNMP_HEALTH_PROFILE``
(:class:`~napalm_device_types.snmp_health_profile.SnmpHealthProfile`). This mixin goes in 5.0.
The collection itself is generic: CPU, memory, uptime, load and per-interface
counters come from the same standard OIDs on any UCD-MIB/IF-MIB capable device.
+7 -7
View File
@@ -473,13 +473,11 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
"""
Create a new virtual machine from a cloud image via Cloud-Init.
Downloads the cloud image (qcow2/raw) directly on the hypervisor if not
already cached there, creates a new VM shell, imports the image as its
root disk, configures virtual network interfaces, and injects Cloud-Init
configuration via a storage snippet or similar mechanism. The resulting
VM is left in a running state.
Implementations cache downloaded images on the hypervisor by URL/filename.
Downloads the cloud image (qcow2/raw) directly on the hypervisor unless it is
cached there already (implementations cache by URL/filename), creates a new VM
shell, imports the image as its root disk, configures virtual network interfaces,
and injects Cloud-Init configuration via a storage snippet or similar mechanism.
The resulting VM is left in a running state.
Args:
name (string) - new VM display name
@@ -533,6 +531,8 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
Raises:
RuntimeError - if provisioning fails (download failure, checksum
mismatch, storage unavailable, invalid config, timeout, etc.)
VMProvisionIncomplete - a RuntimeError for a failure after the VM was created,
with that VM's ``vmid`` and ``node`` for ``destroy_vm`` and the failure as cause.
"""
...
+6 -47
View File
@@ -9,6 +9,12 @@ from typing import Literal, NotRequired, get_args
from typing_extensions import TypedDict
# The SNMP health profile shapes live in snmp_health_profile.py; re-exported here, where they were.
from napalm_device_types.snmp_health_profile import SnmpHealthProfile as SnmpHealthProfile
from napalm_device_types.snmp_health_profile import SnmpInterfacesSpec as SnmpInterfacesSpec
from napalm_device_types.snmp_health_profile import SnmpMemorySpec as SnmpMemorySpec
from napalm_device_types.snmp_health_profile import SnmpValueSpec as SnmpValueSpec
# ---------------------------------------------------------------------------
# Common (shared across device types)
# ---------------------------------------------------------------------------
@@ -1230,53 +1236,6 @@ class SnmpAgentSettingsDict(TypedDict):
listen: NotRequired[str] # the address the agent binds to; absent: every address
class SnmpValueSpec(TypedDict, total=False):
"""Where an SNMP agent publishes one value, inside a ``SnmpHealthProfile``.
Either ``oids``, scalars asked in order (the first non-empty answer wins), or
``table``, a column walked and folded to one value by ``fold``. ``pattern`` is a
regular expression whose first group is the number, for an agent that answers
with text.
"""
oids: list[str]
table: str
fold: Literal["first", "average", "max"]
pattern: str
class SnmpMemorySpec(TypedDict, total=False):
"""Memory: ``total`` with ``used`` or ``free``, or ``percent`` alone."""
total: SnmpValueSpec
used: SnmpValueSpec
free: SnmpValueSpec
percent: SnmpValueSpec
unit: Literal["KiB", "bytes"] # of total, used and free; KiB, as UCD-MIB counts, by default
class SnmpInterfacesSpec(TypedDict, total=False):
"""How the IF-MIB counters of a device are to be read."""
skip: str # a pattern of interface names whose counters are noise, not signal
tx_errors_are_drops: bool # the device counts dropped packets as TX errors (OPNsense)
class SnmpHealthProfile(TypedDict, total=False):
"""Where a device's SNMP agent publishes its health values.
A driver declares it as ``SNMP_HEALTH_PROFILE`` when its device does not answer
the standard UCD-MIB and IF-MIB; the application polls and computes. What a
profile does not name is read the standard way. Uptime is in TimeTicks, CPU in
percent busy.
"""
uptime: SnmpValueSpec
cpu: SnmpValueSpec
memory: SnmpMemorySpec
interfaces: SnmpInterfacesSpec
class NICConfigDict(TypedDict):
"""Network interface configuration for VM provisioning."""
+27 -2
View File
@@ -3,8 +3,9 @@ What provisioning a VM from a cloud image needs to know about the guest.
The same for every hypervisor: which agent a guest runs so a QEMU-based
hypervisor can read its IP, the network-config cloud-init and FreeBSD's
nuageinit both read, and how a packed cloud image is unpacked. How a
hypervisor attaches, boots and talks to the VM stays in its driver.
nuageinit both read, how a packed cloud image is unpacked, and how a failure
names the VM it left behind. How a hypervisor attaches, boots and talks to
the VM stays in its driver.
"""
from __future__ import annotations
@@ -37,6 +38,30 @@ _DECOMPRESSORS = {
}
class VMProvisionIncomplete(RuntimeError):
"""``create_vm_from_cloud_init`` failed after the VM was created.
The VM is still on the hypervisor, half built: ``vmid`` and ``node`` name it
as ``VMProvisionResultDict`` would have, so the caller can remove it with
``destroy_vm``. The failure itself is the ``__cause__`` (``raise ... from``),
and the message is its own. A failure before the VM exists raises as before.
"""
def __init__(self, message: str, *, vmid: str, node: str) -> None:
super().__init__(message)
self.vmid = vmid
self.node = node
def __reduce__(self) -> tuple[Any, ...]:
# The keyword-only arguments are not in ``args``, which is all that
# pickle passes back by default.
return (_vm_provision_incomplete, (str(self), self.vmid, self.node))
def _vm_provision_incomplete(message: str, vmid: str, node: str) -> VMProvisionIncomplete:
return VMProvisionIncomplete(message, vmid=vmid, node=node)
def network_config(nics: list[tuple[str, bool]]) -> dict[str, Any] | None:
"""Network-config v2: DHCP on every ``(mac, dhcp)`` NIC that asks for it.
@@ -0,0 +1,60 @@
"""The shape a driver states its device's SNMP health OIDs in (``SNMP_HEALTH_PROFILE``).
Apart from ``models.py``, which is over the file size limit; ``models`` still exports them.
"""
from typing import Literal
from typing_extensions import TypedDict
class SnmpValueSpec(TypedDict, total=False):
"""Where an SNMP agent publishes one value, inside a ``SnmpHealthProfile``.
Either ``oids``, scalars asked in order (the first non-empty answer wins), or
``table``, a column walked and folded to one value by ``fold``. ``pattern`` is a
regular expression whose first group is the number, for an agent that answers
with text.
``unknown`` says the agent answers this value wrongly, or not at all, where it
should: the application reports no value -- neither the standard reading nor a
default. It stands alone, without ``oids`` or ``table``.
"""
oids: list[str]
table: str
fold: Literal["first", "average", "max"]
pattern: str
unknown: bool
class SnmpMemorySpec(TypedDict, total=False):
"""Memory: ``total`` with ``used`` or ``free``, or ``percent`` alone."""
total: SnmpValueSpec
used: SnmpValueSpec
free: SnmpValueSpec
percent: SnmpValueSpec
unit: Literal["KiB", "bytes"] # of total, used and free; KiB, as UCD-MIB counts, by default
class SnmpInterfacesSpec(TypedDict, total=False):
"""How the IF-MIB counters of a device are to be read."""
skip: str # a pattern of interface names whose counters are noise, not signal
tx_errors_are_drops: bool # the device counts dropped packets as TX errors (OPNsense)
class SnmpHealthProfile(TypedDict, total=False):
"""Where a device's SNMP agent publishes its health values.
A driver declares it as ``SNMP_HEALTH_PROFILE`` when its device does not answer
the standard UCD-MIB and IF-MIB; the application polls and computes. What a
profile does not name is read the standard way, and what it marks ``unknown`` is
not read at all. Uptime is in TimeTicks, CPU in percent busy.
"""
uptime: SnmpValueSpec
cpu: SnmpValueSpec
memory: SnmpMemorySpec
interfaces: SnmpInterfacesSpec