Reapply "Merge feature/generic-vm-provisioning: generalize create_vm_from_cloud_init interface"

This reverts commit 97cab9754b.
This commit is contained in:
2026-07-07 08:20:55 +02:00
parent 97cab9754b
commit 2cc93885b4
2 changed files with 27 additions and 19 deletions
+18 -19
View File
@@ -15,6 +15,7 @@ from napalm_device_types.base import DeviceTypeDriver
from napalm_device_types._ucd_metrics import IF_SKIP_DEFAULT, collect_ucd_metrics
from napalm_device_types.models import (
HealthMetricsDict,
NICConfigDict,
PackageDict,
SnapshotDict,
StorageVolumeDict,
@@ -549,39 +550,36 @@ class HypervisorDriver(DeviceTypeDriver):
template: str,
cpu: int,
memory: int,
mgmt_bridge: str,
mgmt_vlan_tag: int | None,
capture_bridge: str,
capture_vlan_tags: List[int],
nics: List[NICConfigDict],
cloud_init_config: Dict[str, Any],
ssh_public_keys: List[str] | None = None,
timeout: int = 120,
disk_resize_gb: int | None = None,
timeout: int = 180,
) -> VMProvisionResultDict:
"""
Create a new virtual machine from a Cloud-Init template.
Clones a pre-existing VM template, configures dual NICs (management +
capture), and injects Cloud-Init configuration via a storage snippet or
similar mechanism. The resulting VM is left in a running state.
Clones a pre-existing VM template, configures virtual network interfaces,
and injects Cloud-Init configuration via a storage snippet or similar
mechanism. The resulting VM is left in a running state.
Args:
name (string) - new VM display name
template (string) - hypervisor-internal ID/name of the template VM to clone
cpu (int) - number of virtual CPUs to assign
memory (int) - RAM to assign in megabytes
mgmt_bridge (string) - network bridge for management NIC (net0)
mgmt_vlan_tag (int | None) - VLAN tag for net0 (None → untagged)
capture_bridge (string) - network bridge for packet capture NIC (net1).
Must support ``vlan-aware`` and trunk mode.
capture_vlan_tags (list[int]) - VLAN tags to place on net1 (trunk).
Packets matching any of these VLANs are visible to the guest.
nics (list[NICConfigDict]) - list of network interface configurations.
First NIC is primary (DHCP by default); subsequent NICs are optional.
Each entry specifies bridge, optional vlan_tag (access) or trunk_vlan_tags,
and dhcp flag.
cloud_init_config (dict) - user-data dict (will be rendered to YAML).
Should include: ``bootstrap_token``, ``central_url``, ``satellite_id``,
``runcmd`` for custom startup sequence.
Should include hostname, bootstrap_token, runcmd, and any custom config.
ssh_public_keys (list[str] | None) - SSH public keys to inject into guest.
If None or empty, no SSH key injection is performed.
disk_resize_gb (int | None) - resize root disk to this size in GB.
If None, disk remains template size. Default None.
timeout (int) - maximum seconds to wait for provisioning completion
(clone, config, start). Default 120.
(clone, config, start). Default 180.
Returns:
VMProvisionResultDict - ``{"vmid": str, "name": str, "node": str}``
@@ -648,8 +646,9 @@ class HypervisorDriver(DeviceTypeDriver):
Returns:
VMStatusDict - ``{"status": str, "ip_address": str, "hostname": str,
"mac_address": str}``. ip_address, hostname, and mac_address are only
present if the VM is running and has network info available.
"mac_address": str}``. ip_address, hostname, and mac_address refer to
the primary NIC (first interface) and are only present if the VM is
running and has network info available.
Raises:
RuntimeError - if the VM does not exist or if wait_for_ip=True and
+9
View File
@@ -706,6 +706,15 @@ class HealthMetricsDict(TypedDict):
interfaces: NotRequired[Dict[str, HealthMetricsIfaceDict]]
class NICConfigDict(TypedDict):
"""Network interface configuration for VM provisioning."""
bridge: str # Bridge or network name
vlan_tag: NotRequired[int | None] # Access VLAN (None = untagged)
trunk_vlan_tags: NotRequired[list[int]] # Trunk VLAN list (alternative to vlan_tag)
dhcp: NotRequired[bool] # Enable DHCP (default True for first NIC, False for others)
class VMProvisionResultDict(TypedDict):
"""Return value of ``create_vm_from_cloud_init()`` — provisioned VM identifier."""