feat: Proxmox VE 9.3 API additions (NetOrk/netork#2728)

On a node running 9.3: HA maintenance over PUT /nodes/{node}/maintenance
(the target node's version decides, SSH below it), the guest uid in
get_vms, the cluster-id as ClusterDict.id, sync-time-on-resume on resume.
get_credential_expiry reads the expiry of the token or account the driver
logged in with; get_update_history lists the node's APT transactions.
Needs napalm-device-types 4.44.0.
This commit is contained in:
Christian Manivong committed 2026-11-26 17:35:50 +01:00
1 parent c2d9d7e75e
commit fddf8af680
17 files changed
+718 -17

No files matched your search

+24 -5
View File
@@ -12,9 +12,10 @@ on the node the driver is connected to (``_resolve_vm``).
manages migrates through a ``hamigrate`` task that only hands the request to
the HA manager; the driver then follows ``/cluster/ha/status/current`` until
the guest is on the target, and on a failure reads the migration task's log.
- ``set_node_maintenance``: PVE has no REST endpoint for it; it runs
``ha-manager crm-command node-maintenance`` over the driver's SSH session.
The HA manager moves the node's HA guests away after the command returned.
- ``set_node_maintenance``: from PVE 9.3 ``PUT /nodes/{node}/maintenance``; an
older node has no REST endpoint for it, and the driver runs
``ha-manager crm-command node-maintenance`` over its SSH session. Either way the
HA manager moves the node's HA guests away after the request returned.
"""
from __future__ import annotations
@@ -25,7 +26,7 @@ from time import monotonic, sleep
from typing import TYPE_CHECKING, Any
from napalm_proxmox.migration import lxc_local, qemu_local, refusal, task_errors, upid_field
from napalm_proxmox.pve_values import to_flag
from napalm_proxmox.pve_values import PVE_9_3, to_flag
if TYPE_CHECKING:
# Type-only: newer than the napalm_device_types floor in pyproject.toml.
@@ -57,6 +58,7 @@ class ProxmoxVMMigrateMixin:
_wait_for_task: Any
_node_ssh: Any
_run_node_command: Any
_version_at_least: Any
# -- cluster membership -------------------------------------------------------
@@ -232,13 +234,30 @@ class ProxmoxVMMigrateMixin:
# -- HA maintenance -----------------------------------------------------------
def set_node_maintenance(self, node: str, enabled: bool) -> None:
"""Switch HA maintenance mode of a cluster node, over SSH (no REST endpoint)."""
"""Switch HA maintenance mode of a cluster node: over REST from PVE 9.3, else
with ``ha-manager`` over SSH."""
names = [m.name for m in self._cluster_members()]
if node not in names:
raise ValueError(
f"{node!r} is not a member of the cluster (members: {', '.join(names)})"
)
action = "enable" if enabled else "disable"
# The request is served by *node* itself, which may not run 9.3 yet mid-upgrade.
try:
over_rest = self._version_at_least(*PVE_9_3, node=node)
except Exception as exc:
raise RuntimeError(f"Cannot read the Proxmox VE version of {node!r}: {exc}") from exc
if over_rest:
try:
self._api.nodes(node).maintenance.put(**{"maintenance-mode": action})
except Exception as exc:
raise RuntimeError(
f"Proxmox VE refused to {action} maintenance of {node!r}: {exc}"
) from exc
return
self._ha_manager_maintenance(node, action)
def _ha_manager_maintenance(self, node: str, action: str) -> None:
try:
self._node_ssh()
except Exception as exc: