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.
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""NAPALM driver for VMware vCenter Server.
|
|
|
|
netOrk treats the vCenter as one device. The ESXi hosts behind it appear as
|
|
the ``node`` of each VM; a host can additionally be added with the
|
|
``vmware_esxi`` driver when its own NICs and sensors are of interest.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from napalm_device_types import FingerprintRule
|
|
|
|
from napalm_vmware.actions import VmwareActionsMixin
|
|
from napalm_vmware.base import VmwareBaseDriver
|
|
from napalm_vmware.parse.facts import vcenter_facts
|
|
from napalm_vmware.provisioning import VmwareProvisioningMixin
|
|
|
|
|
|
class VmwareVcenterDriver(VmwareProvisioningMixin, VmwareActionsMixin, VmwareBaseDriver):
|
|
"""A vCenter and every VM, datastore and port group it manages."""
|
|
|
|
DRIVER_NAME = "vmware_vcenter"
|
|
API_TYPE = "VirtualCenter"
|
|
STANDALONE = False
|
|
# The appliance starts several dozen services before the API answers.
|
|
REBOOT_SETTLE_SECONDS = 600
|
|
# Unverified against real hardware; see VmwareEsxiDriver.
|
|
HTTP_FINGERPRINT = [
|
|
FingerprintRule("vcenter", weight=9.0, mandatory=True),
|
|
FingerprintRule("vsphere", weight=3.0),
|
|
FingerprintRule("vmware esxi", weight=9.0, negative=True),
|
|
]
|
|
|
|
def get_facts(self) -> dict[str, Any]:
|
|
return vcenter_facts(self._inventory.about(), self.hostname)
|
|
|
|
# The hosts' NICs are not the vCenter's; reporting them here would attach
|
|
# their MAC addresses to the wrong device. The appliance's own NICs are
|
|
# only visible through its management API, which this driver does not use.
|
|
|
|
def get_interfaces(self) -> dict[str, dict[str, Any]]:
|
|
return {}
|
|
|
|
def get_interfaces_ip(self) -> dict[str, dict[str, Any]]:
|
|
return {}
|
|
|
|
def get_lldp_neighbors(self) -> dict[str, list[dict[str, str]]]:
|
|
return {}
|