Files
napalm-vmware/napalm_vmware/paths.py
Christian Manivong 2b84ceae3a feat: VM provisioning, and reboot_host on ESXi
create_vm_from_cloud_init takes the same qcow2/raw cloud images netOrk
offers for Proxmox. ESXi can neither boot nor download them, so the
driver does both: download with checksum check and one retry, convert
with qemu-img to a streamOptimized VMDK (cached by URL), import through
a minimal OVF descriptor over NFC, pin requested MACs, grow the disk,
and attach a NoCloud seed ISO placed next to the VM's files. NoCloud
rather than guestinfo because it needs nothing in the guest; the
user-data installs open-vm-tools, which the driver declares as its
guest agent. A failure after the import removes the VM again.

Placement is a pure decision over inventory rows: a connected host
outside maintenance mode that sees the datastore and every port group,
with the resource pool and VM folder found by walking up to the
datacenter -- one path for a standalone host and for a vCenter.

Two faults vcsim surfaced and the tests now pin: a chunked upload body
next to a Content-Length is refused with 500, so the disk goes up as a
sized file object that also reports lease progress; and a device edit
replaces the device as sent, so disk and NIC edits start from the live
objects, backing included (vcsim panicked on a disk without one).

destroy_vm, get_vm_status, get_network_targets (port groups with their
fixed VLAN) and get_image_storages complete the contract.

reboot_host on ESXi uses RebootHost_Task and refuses outside
maintenance mode: force=True would cut power to running VMs.

Tested against vcsim in ESXi and vCenter mode, end to end.
2026-09-24 10:00:33 +02:00

93 lines
2.3 KiB
Python

"""The vSphere property paths the drivers read, per managed object type.
Single source of truth for both the drivers and ``tools/harvest.py``: a
fixture harvested from a real host contains exactly what the parsers are
later fed, no more and no less. Adding a path here is the first step of
adding a field to any getter.
"""
from __future__ import annotations
HOST = (
"name",
"summary.hardware",
"summary.quickStats",
"summary.managementServerIp",
"hardware.systemInfo",
"runtime.inMaintenanceMode",
"runtime.connectionState",
"runtime.healthSystemRuntime.systemHealthInfo.numericSensorInfo",
"config.product",
"config.network.pnic",
"config.network.vnic",
"config.network.portgroup",
"config.network.vswitch",
"config.network.dnsConfig",
"config.autoStart",
"configIssue",
"configManager.networkSystem",
"parent",
"datastore",
"network",
)
VM = (
"name",
"config.instanceUuid",
"config.template",
"config.guestId",
"config.guestFullName",
"config.annotation",
"config.firmware",
"config.version",
"config.hardware.numCPU",
"config.hardware.numCoresPerSocket",
"config.hardware.memoryMB",
"config.hardware.device",
"config.bootOptions.bootOrder",
"runtime.powerState",
"runtime.host",
"summary.quickStats",
"guest.net",
"guest.ipAddress",
"guest.hostName",
"config.files.vmPathName",
"guest.toolsStatus",
"guest.toolsRunningStatus",
"snapshot",
)
DATASTORE = (
"name",
"summary",
)
DV_PORTGROUP = (
"name",
"config.defaultPortConfig",
"config.distributedVirtualSwitch",
"config.uplink",
)
DV_SWITCH = ("name",)
# Placement of new VMs: which network objects exist, and the parent chain from
# a host's compute resource up to its datacenter.
NETWORK = ("name",)
COMPUTE_RESOURCE = ("parent", "resourcePool")
FOLDER = ("parent",)
DATACENTER = ("name", "vmFolder")
#: Managed object type name -> paths, in the order harvest.py dumps them.
ALL = {
"HostSystem": HOST,
"VirtualMachine": VM,
"Datastore": DATASTORE,
"DistributedVirtualPortgroup": DV_PORTGROUP,
"DistributedVirtualSwitch": DV_SWITCH,
"Network": NETWORK,
"ComputeResource": COMPUTE_RESOURCE,
"Folder": FOLDER,
"Datacenter": DATACENTER,
}