feat(vm-provision): declare the guest agent per guest OS, Linux only
CI / test (3.10) (push) Successful in 30s
CI / test (3.11) (push) Successful in 26s
CI / test (3.12) (push) Successful in 28s
CI / test (3.10) (pull_request) Successful in 27s
CI / test (3.11) (pull_request) Successful in 26s
CI / test (3.12) (pull_request) Successful in 27s
CI / test (3.10) (push) Successful in 30s
CI / test (3.11) (push) Successful in 26s
CI / test (3.12) (push) Successful in 28s
CI / test (3.10) (pull_request) Successful in 27s
CI / test (3.11) (pull_request) Successful in 26s
CI / test (3.12) (pull_request) Successful in 27s
Follows napalm-device-types 3.0, which replaces GUEST_AGENT_PACKAGES /
GUEST_AGENT_RUNCMD with GUEST_AGENTS = {guest_os: (packages, runcmd)}.
VMware lists Linux with open-vm-tools, as before, and refuses any other
guest_os before anything is created: BSD guests on VMware are optional
for now (NetOrk/netork#801).
The NoCloud network-config moved to napalm-device-types
(`provisioning.network_config`), which Proxmox now uses as well; the seed
module's copy is gone, and the tests check that the generic one is used.
This commit is contained in:
@@ -31,20 +31,6 @@ def meta_data(hostname: str, instance_id: str) -> str:
|
||||
return yaml.safe_dump({"instance-id": instance_id, "local-hostname": hostname}, sort_keys=False)
|
||||
|
||||
|
||||
def network_config(nics: list[tuple[str, bool]]) -> dict[str, Any] | None:
|
||||
"""Netplan v2 config: DHCP on every ``(mac, dhcp)`` NIC that asks for it.
|
||||
|
||||
``None`` when no NIC does -- cloud-init then leaves networking alone
|
||||
rather than being told to configure nothing.
|
||||
"""
|
||||
ethernets = {
|
||||
f"nic{i}": {"match": {"macaddress": mac}, "dhcp4": True}
|
||||
for i, (mac, dhcp) in enumerate(nics)
|
||||
if dhcp
|
||||
}
|
||||
return {"version": 2, "ethernets": ethernets} if ethernets else None
|
||||
|
||||
|
||||
def nocloud_iso(user: str, meta: str, network: dict[str, Any] | None) -> bytes:
|
||||
"""An ISO 9660 image (Rock Ridge + Joliet) holding the seed files."""
|
||||
files = {"user-data": user, "meta-data": meta}
|
||||
|
||||
@@ -22,6 +22,7 @@ from napalm_device_types.models import (
|
||||
VMProvisionResultDict,
|
||||
VMStatusDict,
|
||||
)
|
||||
from napalm_device_types.provisioning import GuestAgents, network_config
|
||||
from pyVmomi import vim
|
||||
|
||||
from napalm_vmware import paths
|
||||
@@ -35,7 +36,7 @@ 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.seed import meta_data, network_config, nocloud_iso, user_data
|
||||
from napalm_vmware.provision.seed import meta_data, nocloud_iso, user_data
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -48,11 +49,14 @@ _STATUS = {"poweredOn": "running", "poweredOff": "stopped", "suspended": "suspen
|
||||
class VmwareProvisioningMixin:
|
||||
"""Mixed into both drivers ahead of :class:`VmwareBaseDriver`."""
|
||||
|
||||
GUEST_AGENT_PACKAGES: tuple[str, ...] = ("open-vm-tools",)
|
||||
# The unit is open-vm-tools on Debian/Ubuntu and vmtoolsd on EL/Fedora.
|
||||
GUEST_AGENT_RUNCMD: tuple[str, ...] = (
|
||||
"systemctl enable --now open-vm-tools || systemctl enable --now vmtoolsd",
|
||||
)
|
||||
# Linux only: BSD guests on VMware are optional (NetOrk/netork#801). The
|
||||
# unit is open-vm-tools on Debian/Ubuntu and vmtoolsd on EL/Fedora.
|
||||
GUEST_AGENTS: GuestAgents = {
|
||||
"linux": (
|
||||
("open-vm-tools",),
|
||||
("systemctl enable --now open-vm-tools || systemctl enable --now vmtoolsd",),
|
||||
),
|
||||
}
|
||||
|
||||
hostname: str
|
||||
_port: int
|
||||
@@ -148,9 +152,12 @@ class VmwareProvisioningMixin:
|
||||
disk_resize_gb: int | None = None,
|
||||
storage: str | None = None,
|
||||
cpu_type: str | None = None,
|
||||
guest_os: str = "linux",
|
||||
download_timeout: int = 300,
|
||||
timeout: int = 180,
|
||||
) -> VMProvisionResultDict:
|
||||
if guest_os not in self.GUEST_AGENTS:
|
||||
raise ValueError(f"VMware provisions Linux guests only, not {guest_os!r}")
|
||||
if cpu_type is not None:
|
||||
# CPU compatibility is a cluster setting here (EVC), not a per-VM
|
||||
# one, and there is no get_vm_cpu_types() that could offer a model.
|
||||
|
||||
Reference in New Issue
Block a user