feat: get_clusters() and create_vm_from_cloud_init(node=)
driver / lint (pull_request) Successful in 16s
driver / standard (pull_request) Failing after 19s
driver / types (pull_request) Successful in 1m10s
driver / test (3.13) (pull_request) Successful in 1m13s
driver / test (3.12) (pull_request) Successful in 1m19s
driver / lowest (pull_request) Successful in 32s
driver / build (pull_request) Successful in 28s
driver / security (pull_request) Successful in 1m0s
CI / driver (pull_request) Failing after 2m32s
driver / publish (pull_request) Skipped

A hypervisor reports every cluster its connection can see: the cluster's
name and quorum, its nodes (offline ones too, the local one marked) with
CPU and memory, and the storages and networks with the nodes that see
each. A standalone host is a cluster of one without a name; a manager
reports each cluster and standalone host it runs. Declared only, so a
capability check stays truthful.

create_vm_from_cloud_init() takes the node to create the VM on; a driver
that can only create on its own node refuses another.

Refs NetOrk/netork#484, NetOrk/netork#1822
This commit is contained in:
christianmanivong committed 2026-11-01 16:38:38 +01:00
1 parent 97cb8779c5
commit 00aa5efef0
5 files changed
+215

No files matched your search

+8
View File
@@ -135,6 +135,10 @@ from napalm_device_types.management_controller import ManagementControllerDriver
from napalm_device_types.media import MediaDriver
from napalm_device_types.models import (
POWER_ACTIONS,
ClusterDict,
ClusterNetworkDict,
ClusterNodeDict,
ClusterStorageDict,
ConfigSyncDict,
DhcpHaDict,
DhcpHaPeerDict,
@@ -235,6 +239,10 @@ from napalm_device_types.virtual_ips import (
from napalm_device_types.vm_stop_request import VmStopRequestMixin
__all__ = [
"ClusterDict",
"ClusterNetworkDict",
"ClusterNodeDict",
"ClusterStorageDict",
"HypervisorHostDict",
"DnsForwardDict",
"DnsForwardMixin",
+33
View File
@@ -15,6 +15,7 @@ from typing import TYPE_CHECKING, Any
from napalm_device_types.base import DeviceTypeDriver
from napalm_device_types.health_metrics import HealthMetricsMixin
from napalm_device_types.models import (
ClusterDict,
HypervisorHostDict,
NetworkTargetDict,
NICConfigDict,
@@ -464,6 +465,7 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
storage: str | None = None,
cpu_type: str | None = None,
guest_os: str = "linux",
node: str | None = None,
download_timeout: int = 300,
timeout: int = 180,
) -> VMProvisionResultDict:
@@ -519,6 +521,13 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
network-config itself (``provisioning.network_config``). A
guest_os the driver does not list raises ValueError before
anything is created. Default ``"linux"``.
node (string | None) - the cluster node to create the VM on, a
node ``name`` from ``get_clusters()``. None leaves it to the
driver: the node this connection talks to, or, on a manager of
several hosts, a host of the driver's choosing. A driver that
can only create on its own node raises ValueError for any other
name, before creating anything. ``storage`` and the NICs'
bridges must then be ones that node sees.
download_timeout (int) - maximum seconds to wait for the image download
(skipped entirely if already cached on the hypervisor). Default 300.
timeout (int) - maximum seconds to wait for the remaining provisioning
@@ -637,6 +646,30 @@ class HypervisorDriver(PackageManagementMixin, HealthMetricsMixin, DeviceTypeDri
"""
...
def get_clusters(self) -> list[ClusterDict]:
"""
List the clusters this connection can see, each with its nodes, its
storages and its networks.
A cluster member (a Proxmox node) reports its one cluster, the whole of
it: every node, offline ones included with ``status`` ``"offline"``, and
``local`` set on the node it is. A manager (vCenter) reports each
cluster it runs, and each standalone host it runs as a cluster of one.
A standalone host reports itself as a cluster of one, ``name`` None.
The VMs ``get_vms()`` lists name their node in ``node``; that name is
the node's ``name`` here. A storage or network lists the nodes it is
available on, so a caller can tell where a VM may go. A value the
platform does not report is None, never a guess.
Facts only: which node is a good place for a VM is the caller's to
decide.
Returns:
List[ClusterDict]
"""
...
def get_hypervisor_hosts(self) -> list[HypervisorHostDict]:
"""The hosts this hypervisor or its manager runs, and how each stands:
connected, in maintenance, with configuration issues, under a central
+51
View File
@@ -1195,6 +1195,57 @@ class HypervisorHostDict(TypedDict):
managed_by: NotRequired[str | None] # the address of a central manager, if any
class ClusterNodeDict(TypedDict):
"""One host of a cluster, as its cluster sees it. A value the platform does not
report is None; it is never guessed."""
name: str # the node's name in its cluster, as get_vms() reports it in ``node``
status: str # "online", "offline" or "unknown"
local: bool # the node this connection talks to; False on a manager (vCenter)
maintenance: bool | None # in maintenance mode
cpu_threads: int | None # logical CPUs
cpu_cores: int | None # physical cores
cpu_model: str | None
cpu_flags: list[str] | None # cpuinfo flags; None where the platform does not say
cpu_usage: float | None # 0.0–1.0
memory_total: int | None # bytes
memory_used: int | None # bytes
class ClusterStorageDict(TypedDict):
"""A storage of a cluster and the nodes that see it."""
name: str # usable as create_vm_from_cloud_init(storage=...) on each of ``nodes``
type: str # backend type: "dir", "lvmthin", "zfspool", "nfs", "rbd", "vmfs", ...
shared: bool # the same storage on every node in ``nodes``, so a VM on it can move
content: list[str] # what it holds: "images", "iso", "snippets", ...
nodes: list[str] # the nodes it is available on
total: int | None # bytes; None where the platform does not report it
used: int | None # bytes
class ClusterNetworkDict(TypedDict):
"""A network a VM's NIC may attach to, and the nodes that carry it."""
name: str # usable as NICConfigDict.bridge on each of ``nodes``
kind: str # "bridge", "vnet" or "portgroup", as in NetworkTargetDict
vlan_aware: bool # True if a NICConfigDict.vlan_tag may be set on top of it
fixed_vlan_tag: NotRequired[int | None] # vnet/portgroup: the VLAN baked into it
nodes: list[str]
class ClusterDict(TypedDict):
"""A cluster the connection can see. A standalone host is a cluster of one,
with no name."""
id: str | None # stable across connections where the platform has one; None otherwise
name: str | None # the cluster's name; None for a standalone host
quorate: bool | None # None where the platform has no quorum (standalone, vSphere)
nodes: list[ClusterNodeDict]
storages: list[ClusterStorageDict]
networks: list[ClusterNetworkDict]
class FixStepOutcomeDict(TypedDict):
"""What one step of a fix routine reports (see ``napalm_device_types.fixes``)."""