From fcf72b6dad44209213cf378ef985b0d36e5eabac Mon Sep 17 00:00:00 2001 From: Christian Manivong Date: Tue, 7 Jul 2026 09:03:44 +0200 Subject: [PATCH] feat(hypervisor): add get_network_targets() interface for VM NIC provisioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Returns selectable bridge/vnet targets for a new VM's NIC, distinguishing real bridges (Linux, OVS) from SDN vnets, and exposing whether a NIC on that target may additionally carry a vlan_tag (Linux bridge vlan_aware flag, OVS always, SDN vnet never — the VLAN is already fixed by the vnet's zone/tag). --- napalm_device_types/hypervisor.py | 19 +++++++++++++++++++ napalm_device_types/models.py | 17 +++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/napalm_device_types/hypervisor.py b/napalm_device_types/hypervisor.py index 1a4abaa..0001b9e 100644 --- a/napalm_device_types/hypervisor.py +++ b/napalm_device_types/hypervisor.py @@ -16,6 +16,7 @@ from napalm_device_types._ucd_metrics import IF_SKIP_DEFAULT, collect_ucd_metric from napalm_device_types.models import ( HealthMetricsDict, NICConfigDict, + NetworkTargetDict, PackageDict, SnapshotDict, StorageVolumeDict, @@ -655,3 +656,21 @@ class HypervisorDriver(DeviceTypeDriver): timeout is exceeded. """ raise NotImplementedError + + def get_network_targets(self) -> List[NetworkTargetDict]: + """ + List the network targets a new VM's NIC may attach to. + + Returns only targets that are actually valid ``NICConfigDict.bridge`` + values — real bridges (Linux or OVS) and SDN network segments (vnets). + Physical NICs, bonds, and other non-bridge interface types are excluded, + since VMs cannot attach directly to them on any hypervisor this interface + supports. + + Returns: + List[NetworkTargetDict] - each entry's ``vlan_aware`` flag tells the + caller whether a ``NICConfigDict.vlan_tag`` may additionally be set + for a NIC using that target (see ``NetworkTargetDict`` for the + per-kind rules). + """ + raise NotImplementedError diff --git a/napalm_device_types/models.py b/napalm_device_types/models.py index 5c3f317..2bc5093 100644 --- a/napalm_device_types/models.py +++ b/napalm_device_types/models.py @@ -730,3 +730,20 @@ class VMStatusDict(TypedDict): ip_address: NotRequired[str] # Management NIC IP (absent if VM has no IP or is stopped) hostname: NotRequired[str] # Hostname resolved from IP (if available) mac_address: NotRequired[str] # MAC of management NIC + + +class NetworkTargetDict(TypedDict): + """A selectable network target for a new VM's NIC (``NICConfigDict.bridge``). + + Distinguishes real bridges (Linux or OVS) from SDN network segments (vnets), + and tells the caller whether a separate ``vlan_tag`` may be applied on top: + - Linux bridge: vlan_aware reflects the bridge's own ``bridge_vlan_aware`` flag. + - OVS bridge: always vlan_aware (OVS bridges tag per-port regardless of a + dedicated "VLAN aware" setting). + - SDN vnet: never vlan_aware — the VLAN is already fixed by the vnet's zone/tag, + so a NIC attached to it must not also carry a ``vlan_tag``. + """ + + name: str # Bridge or vnet name, usable directly as NICConfigDict.bridge + kind: str # "bridge" or "vnet" + vlan_aware: bool # True if a NICConfigDict.vlan_tag may be set on top of this target