feat(vm_provision_mixin): implement get_network_targets()

Filters _get_node_network() to bridge/OVSBridge types only (excludes physical
NICs, bonds), plus SDN vnets from _get_sdn_vnets(). vlan_aware: Linux bridge
reflects its bridge_vlan_aware config flag; OVS bridge always true; SDN vnet
always false (VLAN already fixed by the vnet's zone/tag).

4 new tests: bridge/vnet filtering, Linux bridge vlan_aware flag, OVS bridge
always vlan_aware, SDN vnet never vlan_aware. All 15 tests in the file pass.
This commit is contained in:
Christian Manivong
2026-07-07 09:08:21 +02:00
parent a5a5b634b0
commit c7289fa674
2 changed files with 110 additions and 1 deletions
+32 -1
View File
@@ -8,7 +8,7 @@ import yaml
from typing import Any, Dict, List
from urllib.parse import quote
from napalm_device_types.models import VMProvisionResultDict, VMStatusDict
from napalm_device_types.models import NetworkTargetDict, VMProvisionResultDict, VMStatusDict
_logger = logging.getLogger(__name__)
@@ -387,3 +387,34 @@ class ProxmoxVMProvisionMixin:
except Exception as e:
_logger.exception(f"Error getting status for VM {vmid}: {e}")
raise RuntimeError(f"Failed to get VM {vmid} status: {e}")
def get_network_targets(self) -> List[NetworkTargetDict]:
"""
List selectable network targets (bridges + SDN vnets) for a new VM's NIC.
Excludes physical NICs, bonds, and other non-bridge interface types —
those are never valid ``NICConfigDict.bridge`` values on Proxmox.
"""
targets: List[NetworkTargetDict] = []
for iface in self._get_node_network():
iface_type = iface.get("type")
name = iface.get("iface", "")
if not name:
continue
if iface_type == "bridge":
vlan_aware = bool(int(iface.get("bridge_vlan_aware", 0) or 0))
targets.append({"name": name, "kind": "bridge", "vlan_aware": vlan_aware})
elif iface_type == "OVSBridge":
# OVS bridges tag per-port regardless of a dedicated "VLAN aware" setting.
targets.append({"name": name, "kind": "bridge", "vlan_aware": True})
for vnet in self._get_sdn_vnets():
name = vnet.get("vnet", "")
if not name:
continue
# A vnet's VLAN is already fixed by its zone/tag — no separate vlan_tag applies.
targets.append({"name": name, "kind": "vnet", "vlan_aware": False})
return targets