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

+33 -2
View File
@@ -20,6 +20,8 @@ import logging
import re
from typing import Any
from napalm_proxmox.pve_values import PVE_9_3
logger = logging.getLogger(__name__)
_JsonDict = dict[str, Any]
@@ -238,9 +240,9 @@ class ProxmoxVMMixin:
* node (str) - cluster node name
* interfaces (dict) - network interfaces (NAPALM format + ipv4 field)
* ipv4 (str) - primary IPv4 address (empty string if unknown)
* uid (str) - PVE 9.3's identity of the guest (``_with_uids``); absent before
"""
result: list[_JsonDict] = []
# QEMU VMs; only the full status has ``qmpstatus``, which tells paused from running.
try:
for vm in self._node_api().qemu.get(full=1) or []:
@@ -335,7 +337,36 @@ class ProxmoxVMMixin:
except Exception as exc:
logger.warning("get_vms: failed to list LXC containers: %s", exc)
return sorted(result, key=lambda x: int(x["vmid"]))
return self._with_uids(sorted(result, key=lambda x: int(x["vmid"])))
def _with_uids(self, vms: list[_JsonDict]) -> list[_JsonDict]:
"""Give each guest in *vms* its ``uid``, joined by node and vmid.
PVE 9.3 gives every guest a random identifier that survives a migration, a
restore and a changed vmid; only ``GET /cluster/resources?type=vm`` reports
it. A guest without one, an older node and a listing that cannot be read
leave the key out: the guest is still listed, known by its vmid alone.
"""
try:
uids = self._guest_uids()
except Exception as exc:
logger.debug("get_vms: cannot read the guests' uids: %s", exc)
return vms
for vm in vms:
uid = uids.get((vm["node"], vm["vmid"]))
if uid:
vm["uid"] = uid
return vms
def _guest_uids(self) -> dict[tuple[str, str], str]:
if not self._version_at_least(*PVE_9_3):
return {}
rows = self._api.cluster.resources.get(type="vm") or []
return {
(str(row.get("node")), str(row.get("vmid"))): str(row["uid"])
for row in rows
if row.get("uid")
}
# Disk-key prefixes for QEMU: scsi, virtio, ide, sata (exclude cdrom/none entries)
_DISK_KEYS_VM = re.compile(r"^(scsi|virtio|ide|sata)\d+$")