feat: export ESXi host / Proxmox node per VM in offline JSON
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
28c6654f6b
commit
dc39c8f4ec
2 files changed
+5
-3
No files matched your search
@@ -75,6 +75,7 @@ def validate(data):
|
||||
raise ExchangeError("Die Datei enthält eine VM ohne Name oder Quelle.")
|
||||
vm.setdefault("interfaces", [])
|
||||
vm.setdefault("cluster", "")
|
||||
vm.setdefault("host", "")
|
||||
vm.setdefault("status", "offline")
|
||||
for key in ("vcpus", "memory", "disk"):
|
||||
vm[key] = int(vm.get(key) or 0)
|
||||
|
||||
@@ -87,7 +87,7 @@ def load_vmware_source(source, log=_noop):
|
||||
if properties.get("name") and not properties.get("config.template"):
|
||||
vm = _normalize_vmware_vm(properties, source, vim)
|
||||
host = properties.get("runtime.host")
|
||||
vm["cluster"] = host_clusters.get(getattr(host, "_moId", None), "")
|
||||
vm["cluster"], vm["host"] = host_clusters.get(getattr(host, "_moId", None), ("", ""))
|
||||
normalized.append(vm)
|
||||
return normalized
|
||||
finally:
|
||||
@@ -97,14 +97,14 @@ def load_vmware_source(source, log=_noop):
|
||||
|
||||
|
||||
def _vmware_host_clusters(content, vim):
|
||||
"""Map ESXi host IDs to their cluster name (or the host name when standalone)."""
|
||||
"""Map ESXi host IDs to ``(cluster name, host name)``; standalone hosts use their own name as cluster."""
|
||||
result = {}
|
||||
view = content.viewManager.CreateContainerView(content.rootFolder, [vim.ComputeResource], True)
|
||||
try:
|
||||
for resource in view.view:
|
||||
name = resource.name
|
||||
for host in resource.host or []:
|
||||
result[host._moId] = name
|
||||
result[host._moId] = (name, host.name)
|
||||
finally:
|
||||
view.Destroy()
|
||||
return result
|
||||
@@ -205,6 +205,7 @@ def load_proxmox_source(source, log=_noop):
|
||||
try:
|
||||
guest = _normalize_proxmox_guest(session, source, resource)
|
||||
guest["cluster"] = cluster_name or resource.get("node", "")
|
||||
guest["host"] = resource.get("node", "")
|
||||
result.append(guest)
|
||||
except Exception as error: # noqa: BLE001 - one broken guest must not stop the source
|
||||
log(f"{source['name']} / VMID {resource.get('vmid')}: {error}", "warning")
|
||||
|
||||
Reference in new issue
Block a user