"""Raw device warnings: ``{"code", "meta"}`` only. What a code means to a user -- severity, wording, the fix -- is decided in netOrk's ``WARNING_CATALOG``, never here. """ from __future__ import annotations from typing import Any _CONNECTED = "connected" _UNMANAGED = {None, "", "0.0.0.0"} #: License edition of the free vSphere Hypervisor. The vSphere API refuses #: every write on it (power, snapshots) with a RestrictedVersion fault. _FREE_EDITIONS = ("esxBasic",) def _host_codes(host: dict[str, Any], standalone: bool) -> list[dict[str, Any]]: name = host.get("name", host.get("_moref", "")) found: list[dict[str, Any]] = [] state = host.get("runtime.connectionState", _CONNECTED) if not standalone and state != _CONNECTED: found.append({"code": "vmware_host_disconnected", "meta": {"host": name, "state": state}}) if host.get("runtime.inMaintenanceMode"): found.append({"code": "vmware_host_maintenance_mode", "meta": {"host": name}}) issues = [ i["fullFormattedMessage"] for i in host.get("configIssue") or [] if i.get("fullFormattedMessage") ] if issues: found.append({"code": "vmware_host_config_issue", "meta": {"host": name, "issues": issues}}) manager = host.get("summary.managementServerIp") if standalone and manager not in _UNMANAGED: found.append({"code": "vmware_host_managed_by_vcenter", "meta": {"vcenter": manager}}) return found def host_warnings( hosts: list[dict[str, Any]], licenses: list[dict[str, Any]], *, standalone: bool ) -> list[dict[str, Any]]: """Warnings for the hosts this driver sees. ``standalone`` is True for the ESXi driver. It alone reports a host being managed by a vCenter -- a hint to add the vCenter instead -- and it never reports disconnection, since a disconnected host could not have answered. """ found = [w for host in hosts for w in _host_codes(host, standalone)] for lic in licenses: if str(lic.get("editionKey", "")).startswith(_FREE_EDITIONS): found.append({"code": "vmware_api_read_only", "meta": {"edition": lic.get("name", "")}}) break return found