"""What a VM's NIC may attach to on a node (``NetworkTargetDict``). A Linux or OVS bridge from the node's network config (``GET /nodes/{node}/network``), or an SDN vnet (``GET /cluster/sdn/vnets``). Physical NICs, bonds and other interface types are never valid ``NICConfigDict.bridge`` values on Proxmox. Shared by ``get_network_targets()`` (the own node) and ``get_clusters()`` (every online node of the cluster). """ from __future__ import annotations from typing import Any from napalm_device_types.models import NetworkTargetDict from napalm_proxmox.uplinks import bridge_uplinks _BRIDGE_TYPES = frozenset({"bridge", "OVSBridge"}) def bridge_targets(network: list[dict[str, Any]]) -> list[NetworkTargetDict]: """The bridges in one node's *network* config, with their uplinks where known.""" targets: list[NetworkTargetDict] = [] for iface in network: iface_type = iface.get("type") name = iface.get("iface", "") if not name or iface_type not in _BRIDGE_TYPES: continue # OVS bridges tag per-port regardless of a dedicated "VLAN aware" setting. vlan_aware = iface_type == "OVSBridge" or bool(int(iface.get("bridge_vlan_aware", 0) or 0)) target: NetworkTargetDict = {"name": name, "kind": "bridge", "vlan_aware": vlan_aware} uplinks = bridge_uplinks(iface, network) if uplinks is not None: target["uplinks"] = uplinks targets.append(target) return targets def vnet_target(vnet: dict[str, Any]) -> NetworkTargetDict | None: """An SDN *vnet* as a target, or None when it has no name.""" name = vnet.get("vnet", "") if not name: return None # A vnet's VLAN is already fixed by its zone/tag — no separate vlan_tag applies. tag = vnet.get("tag") return { "name": name, "kind": "vnet", "vlan_aware": False, "fixed_vlan_tag": int(tag) if tag is not None else None, }