feat: get_clusters() and create_vm_from_cloud_init(node=)
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Failing after 1m2s
driver / test (3.12) (pull_request) Failing after 57s
driver / test (3.13) (pull_request) Failing after 52s
driver / lowest (pull_request) Failing after 25s
driver / build (pull_request) Successful in 24s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Failing after 2m21s
driver / publish (pull_request) Skipped

vCenter reports each cluster compute resource, and each standalone host
it runs as a cluster of one, identified by "<instanceUuid>/<moref>"; an
ESXi host reports itself. Nodes carry state, maintenance, CPU and memory;
datastores and port groups carry the hosts that see them.

create_vm_from_cloud_init(node=) places the VM on that host and refuses
one that does not exist or cannot take it, before anything is created.
Placement now runs before the image download, so a refused host fails at
once instead of after the download.

Refs NetOrk/netork#484, NetOrk/netork#1822
This commit is contained in:
Christian Manivong committed 2026-11-01 16:38:38 +01:00
1 parent 1bf8de4c23
commit 52c802ed41
14 files changed
+812 -28

No files matched your search

+21 -4
View File
@@ -35,7 +35,7 @@ from napalm_vmware.provision import transfer
from napalm_vmware.provision.image import ImageCache
from napalm_vmware.provision.ovf import ovf_descriptor
from napalm_vmware.provision.placement import Inventory as PlacementInventory
from napalm_vmware.provision.placement import Placement, choose_placement
from napalm_vmware.provision.placement import NodeRefused, Placement, choose_placement
from napalm_vmware.provision.seed import meta_data, nocloud_iso, user_data
logger = logging.getLogger(__name__)
@@ -153,6 +153,7 @@ class VmwareProvisioningMixin:
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:
@@ -163,13 +164,11 @@ class VmwareProvisioningMixin:
# one, and there is no get_vm_cpu_types() that could offer a model.
raise ValueError(f"VMware cannot give a single VM a CPU type ({cpu_type!r})")
self._check_nics(nics)
place = self._place(storage, nics, node)
try:
vmdk, image_size = ImageCache(self._image_cache_dir).vmdk(
image_url, image_checksum, download_timeout
)
place = choose_placement(
self._placement_inventory(), storage, [n["bridge"] for n in nics]
)
except ValueError as exc:
raise RuntimeError(str(exc)) from exc
descriptor = ovf_descriptor(
@@ -196,6 +195,24 @@ class VmwareProvisioningMixin:
)
return {"vmid": props["config.instanceUuid"], "name": name, "node": place.host_name}
def _place(self, storage: str | None, nics: list[NICConfigDict], node: str | None) -> Placement:
"""Where the VM goes, decided before the image is fetched.
A ``node`` that does not exist or cannot take the VM stays a
ValueError, as the contract has it; no host at all is a RuntimeError.
"""
try:
return choose_placement(
self._placement_inventory(),
storage,
[n["bridge"] for n in nics],
host_name=node,
)
except NodeRefused:
raise
except ValueError as exc:
raise RuntimeError(str(exc)) from exc
def _run_task(self, call: Any, *args: Any, **kwargs: Any) -> None:
wait_for_task(self._inventory, invoke(call, *args, **kwargs), _TASK_TIMEOUT)