feat: implement the HypervisorDriver VM contract

start_vm, stop_vm, reboot_vm, suspend_vm and get_vm_config existed only
as declarations. netOrk called Proxmox's own power_vm and read a VM's
raw config through _node_api(), so no other hypervisor could serve the
same endpoints. These let netOrk talk to every hypervisor alike.

The power methods accept a VM's name or vmid, wait for the Proxmox task,
and raise ValueError/RuntimeError as the contract says instead of
returning a result dict. A forced reboot of a container is stop + start,
since LXC has no reset; suspending a container is refused. power_vm is
unchanged for existing callers.

get_vm_config moves the config parsing netOrk did in
_parse_proxmox_hw_config into the driver and returns a VMConfigDict:
disks with storage and size, NICs with model, MAC, bridge and VLAN, CPU
topology, firmware, machine type and PCI/USB passthrough.

get_vms reports vmid as a string ("100"), following
napalm-device-types 2.0, still ordered numerically.
This commit is contained in:
Christian Manivong
2026-09-24 09:06:59 +02:00
parent fc9f1426be
commit dd48d3c1e5
6 changed files with 440 additions and 5 deletions
+4 -4
View File
@@ -216,7 +216,7 @@ class ProxmoxVMMixin:
"""Return all VMs (QEMU) and containers (LXC) on this node.
Each entry contains:
* vmid (int) - Proxmox VM/container ID
* vmid (str) - Proxmox VM/container ID, e.g. ``"100"``
* name (str) - display name
* type (str) - ``"vm"`` or ``"container"``
* status (str) - ``"running"``, ``"stopped"``, etc.
@@ -257,7 +257,7 @@ class ProxmoxVMMixin:
disks, onboot = self._get_vm_disk_and_boot(vmid, "qemu")
result.append({
"vmid": vmid,
"vmid": str(vmid),
"name": name,
"type": "vm",
"status": status,
@@ -301,7 +301,7 @@ class ProxmoxVMMixin:
disks, onboot = self._get_vm_disk_and_boot(vmid, "lxc")
result.append({
"vmid": vmid,
"vmid": str(vmid),
"name": name,
"type": "container",
"status": status,
@@ -321,7 +321,7 @@ class ProxmoxVMMixin:
except Exception as exc:
logger.warning("get_vms: failed to list LXC containers: %s", exc)
return sorted(result, key=lambda x: x["vmid"])
return sorted(result, key=lambda x: int(x["vmid"]))
# Disk-key prefixes for QEMU: scsi, virtio, ide, sata (exclude cdrom/none entries)
_DISK_KEYS_VM = re.compile(r"^(scsi|virtio|ide|sata)\d+$")