From dc39c8f4ec8df72160b44dae402ff19ab2c23905 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 29 Oct 2026 12:29:43 +0100 Subject: [PATCH] feat: export ESXi host / Proxmox node per VM in offline JSON Co-Authored-By: Claude Opus 5.5 --- netbox_sync/core/exchange.py | 1 + netbox_sync/core/virtualization.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/netbox_sync/core/exchange.py b/netbox_sync/core/exchange.py index b5bd2db..e8fd84f 100644 --- a/netbox_sync/core/exchange.py +++ b/netbox_sync/core/exchange.py @@ -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) diff --git a/netbox_sync/core/virtualization.py b/netbox_sync/core/virtualization.py index 8a9041d..2f727d8 100644 --- a/netbox_sync/core/virtualization.py +++ b/netbox_sync/core/virtualization.py @@ -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")