Files
napalm-proxmox/napalm_proxmox/network_targets.py
T
Christian Manivong f60532e434
driver / standard (pull_request) Successful in 16s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Failing after 1m2s
driver / test (3.12) (pull_request) Successful in 1m9s
driver / test (3.13) (pull_request) Successful in 57s
driver / lowest (pull_request) Successful in 31s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 1m3s
CI / driver (pull_request) Failing after 2m42s
driver / publish (pull_request) Skipped
feat: get_clusters() for the whole cluster, node= refused for another node
Every PVE node can read its whole cluster, so get_clusters() reports the
one it belongs to: name and quorum from /cluster/status, every member
(offline ones as offline, without capacity), CPU and memory from
/cluster/resources and each online node's cpuinfo, maintenance from the
HA manager where it can be read, storages grouped by name with the nodes
they are available on, and bridges and vnets with the nodes that carry
them. A standalone node is a cluster of one.

The bridge part of get_network_targets() moved to network_targets.py so
both use it. create_vm_from_cloud_init() takes node= and refuses any node
but its own before creating anything.

Refs NetOrk/netork#484, NetOrk/netork#1822
2026-11-01 16:38:38 +01:00

52 lines
1.9 KiB
Python

"""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,
}