feat: NAPALM drivers for VMware ESXi and vCenter
Two drivers from one package, both in the hypervisor role: - vmware_esxi talks to one host directly: facts, vmnics and vmkernel NICs, CDP/LLDP neighbours, sensors, VMs, datastores and port groups. - vmware_vcenter talks to a vCenter: every VM of every host it manages, with the host as the VM's node, plus distributed port groups. It reports no interfaces of its own; the hosts' NICs belong to the hosts. Both implement the HypervisorDriver VM contract: get_vms, get_vm_config, start/stop/reboot/suspend_vm and the four snapshot methods, and emit raw device warnings (maintenance mode, disconnected host, config issues, host managed by a vCenter, free license making the API read-only). Every read is a PropertyCollector query for the explicit paths in paths.py, converted by to_plain() into dicts and lists; the parsers only ever see that. tools/harvest.py dumps exactly those paths to JSON and tools/sanitize.py scrubs the dump, so a real host can become a test fixture without code changes. A VM's vmid is its instance UUID, which survives vMotion and re-registration; a MoRef does not. Tested against govmomi's vcsim in ESXi and vCenter mode, including real power and snapshot tasks. Not yet tested against real hardware.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"""NAPALM ``get_lldp_neighbors`` from ``HostNetworkSystem.QueryNetworkHint``.
|
||||
|
||||
ESXi listens for CDP on standard vSwitches by default and for LLDP where a
|
||||
vDS enables it. Both answers come back per vmnic in one hint; LLDP is
|
||||
preferred because it names the switch port the way the switch itself does.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
def _lldp(info: dict[str, Any]) -> dict[str, str] | None:
|
||||
if not info.get("portId"):
|
||||
return None
|
||||
params = {p.get("key"): p.get("value") for p in info.get("parameter", [])}
|
||||
hostname = params.get("System Name") or info.get("chassisId", "")
|
||||
return {"hostname": str(hostname), "port": str(info["portId"])}
|
||||
|
||||
|
||||
def _cdp(info: dict[str, Any]) -> dict[str, str] | None:
|
||||
if not info.get("portId"):
|
||||
return None
|
||||
return {"hostname": str(info.get("devId", "")), "port": str(info["portId"])}
|
||||
|
||||
|
||||
def lldp_neighbors(hints: list[dict[str, Any]]) -> dict[str, list[dict[str, str]]]:
|
||||
result: dict[str, list[dict[str, str]]] = {}
|
||||
for hint in hints:
|
||||
neighbor = _lldp(hint.get("lldpInfo") or {}) or _cdp(hint.get("connectedSwitchPort") or {})
|
||||
if neighbor:
|
||||
result[hint["device"]] = [neighbor]
|
||||
return result
|
||||
Reference in New Issue
Block a user