Merge NAPALM/napalm-device-types#132 (4.45.0) into feature/services-need-restart-lxc

This commit is contained in:
christianmanivong committed 2026-11-26 19:25:55 +01:00
commit a5275d4c4d
9 files changed
+299 -36

No files matched your search

+23 -1
View File
@@ -41,6 +41,7 @@ instead of being restated on every role that happens to need it:
* :class:`~napalm_device_types.config_revisions.ConfigRevisionsMixin`
* :class:`~napalm_device_types.config_sync.ConfigSyncMixin`
* :class:`~napalm_device_types.container_engine.ContainerEngineMixin`
* :class:`~napalm_device_types.credential_expiry.CredentialExpiryMixin`
* :class:`~napalm_device_types.dhcp.DhcpServerMixin`
* :class:`~napalm_device_types.firewall_rules.FirewallRuleMixin`
* :class:`~napalm_device_types.health_metrics.HealthMetricsMixin`
@@ -144,6 +145,11 @@ from napalm_device_types.container_engine import (
ContainerEngineMixin,
ContainerEngineUnavailable,
)
from napalm_device_types.credential_expiry import (
CredentialExpiryDict,
CredentialExpiryMixin,
CredentialKind,
)
from napalm_device_types.dhcp import DhcpApplyError, DhcpServerMixin, normalize_cidr, normalize_mac
from napalm_device_types.dns_forward import DnsForwardMixin
from napalm_device_types.firewall import FirewallDriver
@@ -303,6 +309,8 @@ from napalm_device_types.service_packages import (
from napalm_device_types.services import ServiceControlMixin
from napalm_device_types.services_restart import (
SERVICES_RESTART_COMMAND,
RestartProcessDict,
ServicesRestartDict,
ServicesRestartMixin,
parse_services_restart,
)
@@ -367,7 +375,13 @@ from napalm_device_types.time_sync import (
check_ntp_servers,
)
from napalm_device_types.time_sync_posix import PosixTimeSyncMixin, parse_time_sync
from napalm_device_types.updates import PackageIndexMissing, UpdateMixin
from napalm_device_types.updates import (
PackageIndexMissing,
UpdateHistoryAction,
UpdateHistoryDict,
UpdateHistoryPackageDict,
UpdateMixin,
)
from napalm_device_types.virtual_ips import (
VIRTUAL_IPS_COMMAND,
VirtualIpsMixin,
@@ -412,6 +426,12 @@ __all__ = [
"OspfInterfaceDict",
"OspfMixin",
"UpdateProgressDict",
"UpdateHistoryAction",
"UpdateHistoryDict",
"UpdateHistoryPackageDict",
"CredentialExpiryDict",
"CredentialExpiryMixin",
"CredentialKind",
"FirmwareOfferMixin",
"FirmwareUpgradeMixin",
"LicenseDict",
@@ -524,6 +544,8 @@ __all__ = [
"SERVICE_PACKAGES_COMMAND",
"SERVICES_RESTART_COMMAND",
"ServicesRestartMixin",
"ServicesRestartDict",
"RestartProcessDict",
"parse_services_restart",
"ServicePackagesMixin",
"parse_service_packages",
+58
View File
@@ -0,0 +1,58 @@
"""When the credential a driver logs in with stops working.
An API token can be given an expiry, and a platform can require one (Proxmox VE
9.3's datacenter ``token-policy``). Once it has passed, every login fails with
an authentication error, and an application that polls the device learns of it
only then. A driver that can read its own credential's expiry says so here, so
the application can warn before, the way it warns of an expiring certificate.
Which credential is read is the driver's: the one this connection logged in
with, never another.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Literal
from typing_extensions import TypedDict
#: ``"api-token"``: a token of an account; ``"account"``: the account a password logs in to.
CredentialKind = Literal["api-token", "account"]
class CredentialExpiryDict(TypedDict):
"""The credential this connection logged in with, and when it expires."""
kind: CredentialKind
#: The credential as the platform names it, e.g. ``"netork@pve!poll"``.
name: str
#: Unix seconds; ``None`` when it never expires.
expires: int | None
class CredentialExpiryMixin:
"""Reads the expiry of the credential the driver logged in with.
Declared under ``if TYPE_CHECKING``: a contract, not a placeholder.
"""
if TYPE_CHECKING:
def get_credential_expiry(self) -> CredentialExpiryDict:
"""
The credential this connection logged in with, and when it expires.
``expires`` is ``None`` for one that never expires. A credential
whose expiry has passed cannot log in, so a driver that returns at
all reports one that still works.
:raises PermissionError: The platform will not tell this credential
its own expiry (a token whose privileges do not reach it). Not a
fault of the connection; a caller then knows nothing either way.
:raises RuntimeError: The platform could not be read.
Example::
{"kind": "api-token", "name": "netork@pve!poll", "expires": 1767225600}
"""
...
+14 -2
View File
@@ -41,6 +41,13 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
Inherits all standard NAPALM NetworkDriver methods and adds
hypervisor-specific operations that concrete drivers must implement.
A guest is known by its ``vmid``, which a platform may give to another guest
once the first is gone, and where it has one also by its ``uid``
(``VMDict.uid``): an identity that survives a migration, a restore and a
changed ``vmid`` -- Proxmox VE 9.3's ``uid``, VMware's instance UUID. A driver
leaves it out where the platform has none or has not given the guest one yet;
a caller then knows that guest by ``vmid`` alone.
"""
#: Stable key netOrk exposes as ``device_class``. The order in which a
@@ -69,8 +76,7 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
Each entry contains:
* name (string) - VM display name
* vmid (string) - hypervisor-internal ID (Proxmox: ``"100"``,
VMware: the instance UUID)
* vmid (string) - hypervisor-internal ID (Proxmox: ``"100"``, VMware: the instance UUID)
* status (string) - ``"running"``, ``"stopped"``, ``"paused"``, ``"suspended"``.
A guest that is not executing is never ``"running"``: ``"paused"``
while its process still holds its memory (Proxmox's ``qmpstatus``
@@ -82,6 +88,7 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
* memory_usage (int) - current RAM usage in megabytes
* uptime (int) - uptime in seconds (0 if not running)
* node (string) - cluster node this VM lives on (empty string for standalone)
* uid (string, optional) - outlives the ``vmid``; absent where none (``VMDict.uid``)
Example::
@@ -272,6 +279,11 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
counterpart of :meth:`suspend_vm`. The method blocks until the
hypervisor took the request.
The guest's clock is set to the host's time after it resumes, where the
platform can do so (Proxmox VE: through the guest agent): a guest that
stood still for hours would otherwise run behind. No caller wants
otherwise, so it is the driver's to do, not a choice.
Optional, like every power action: a driver whose platform cannot
resume a guest does not implement it, and a caller then offers no
resume. A driver that can resume some guests but not others (a
+2 -23
View File
@@ -1,5 +1,4 @@
"""
TypedDicts for NAPALM device-type-specific return values.
"""TypedDicts for NAPALM device-type-specific return values.
These supplement the types defined in napalm.base.models and are used by the
abstract device-type driver classes in this package.
@@ -406,27 +405,6 @@ class ListeningSocketsDict(TypedDict):
sockets: list[ListeningSocketDict]
class RestartProcessDict(TypedDict):
"""A process that runs replaced code and belongs to no systemd service."""
pid: int
name: str # /proc/<pid>/comm
class ServicesRestartDict(TypedDict):
"""What ``ServicesRestartMixin.get_services_need_restart`` read.
``units`` are the systemd services, without ".service", that still run code
an update replaced on disk; empty when none does. ``processes`` are the ones
that belong to no service (a login session, systemd itself), read only by the
``/proc`` scan; the host's own tools name services only.
"""
source: str # "needs-restarting", "needrestart" or "maps"
units: list[str]
processes: list[RestartProcessDict]
class NetfilterMatchDict(TypedDict):
"""One condition of a netfilter rule.
@@ -856,6 +834,7 @@ class VMDict(TypedDict):
memory_usage: int
uptime: int
node: str
uid: NotRequired[str] # outlives a migration, a restore, a changed vmid (get_vms)
class VMPassthroughDict(TypedDict):
+23 -2
View File
@@ -39,12 +39,33 @@ from __future__ import annotations
import re
from shlex import quote
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, TypedDict
from napalm_device_types.listening import _cgroup_paths, _container, _unit
from napalm_device_types.models import RestartProcessDict, ServicesRestartDict
from napalm_device_types.terminal import strip_terminal_codes
class RestartProcessDict(TypedDict):
"""A process that runs replaced code and belongs to no systemd service."""
pid: int
name: str # /proc/<pid>/comm
class ServicesRestartDict(TypedDict):
"""What :meth:`ServicesRestartMixin.get_services_need_restart` read.
``units`` are the systemd services, without ".service", that still run code
an update replaced on disk; empty when none does. ``processes`` are the ones
that belong to no service (a login session, systemd itself), read only by the
``/proc`` scan; the host's own tools name services only.
"""
source: str # "needs-restarting", "needrestart" or "maps"
units: list[str]
processes: list[RestartProcessDict]
_BEGIN = "RST_BEGIN"
_END = "RST_END"
NEEDS_RESTARTING = "needs-restarting"
+78 -2
View File
@@ -12,9 +12,47 @@ this class in can never shadow a working implementation from a sibling base.
from __future__ import annotations
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Literal
from napalm_device_types.models import ApplyUpdatesResultDict, UpdateDict, UpdateProgressDict
from typing_extensions import TypedDict
from napalm_device_types.models import (
ApplyUpdatesResultDict,
UpdateDict,
UpdateProgressDict,
)
UpdateHistoryAction = Literal[
"install", "reinstall", "upgrade", "downgrade", "remove", "purge", "disappear"
]
class UpdateHistoryPackageDict(TypedDict):
"""One package a past transaction changed (``UpdateHistoryDict.packages``)."""
name: str
action: UpdateHistoryAction # "disappear": dpkg dropped it, its files taken by another
old_version: str | None # None where nothing was installed before
new_version: str | None # None where nothing is installed after
class UpdateHistoryDict(TypedDict):
"""A past run of the host's package manager (``UpdateMixin.get_update_history``).
A fact of the host's own log: what it changed, when, and who asked, also for
a run that no application of the caller started.
"""
#: Stable for the same transaction across reads, unique on the host: apt's
#: start time with its index among those starting in the same second, dnf's
#: transaction ID.
id: str
start: int # unix seconds
end: int | None # None: still running, or interrupted
packages: list[UpdateHistoryPackageDict]
requested_by: str | None # the user behind sudo, pkexec or PackageKit; None when unknown
command: str | None # the command line, where the log keeps it
error: str | None # the error the run ended with; None for none
class PackageIndexMissing(RuntimeError):
@@ -83,6 +121,44 @@ class UpdateMixin:
"""
...
def get_update_history(self, since: int | None = None) -> list[UpdateHistoryDict]:
"""
The transactions the host's package manager ran, newest first: what
each changed, when, and who asked for it -- also those no caller of
this driver started (an operator's ``apt upgrade``, unattended-upgrades).
:param since: Unix seconds; only transactions that started at or after
it. ``None`` for as far back as the host's log reaches.
**An empty list means no transaction since.** A reader that cannot
read raises, as :meth:`get_available_updates` does: a caller keeps what
it read before, and an empty list for "don't know" would read as a
host that never changed. ``NotImplementedError`` where the package
manager keeps no history.
Example::
[
{
"id": "1764158400-0",
"start": 1764158400,
"end": 1764158460,
"packages": [
{
"name": "openssh-server",
"action": "upgrade",
"old_version": "1:9.2p1-2+deb12u1",
"new_version": "1:9.2p1-2+deb12u2",
},
],
"requested_by": "admin",
"command": "apt-get -y upgrade",
"error": None,
},
]
"""
...
def refresh_available_updates(self) -> dict[str, Any]:
"""
Refreshes the host's package index, so that :meth:`get_available_updates`