fix: propagate tenant to synchronized IP addresses

Assign the confirmed cluster tenant to every created or updated IP address and include the affected address in NetBox synchronization errors.
This commit is contained in:
2026-07-29 13:41:33 +02:00
parent a37477e4ec
commit ec40bded81
2 changed files with 10 additions and 7 deletions
+5 -2
View File
@@ -864,9 +864,8 @@ class NetBoxVMImporter:
payload = { payload = {
"name": source_vm["name"], "cluster": cluster_id, "status": source_vm["status"], "name": source_vm["name"], "cluster": cluster_id, "status": source_vm["status"],
"vcpus": source_vm["vcpus"], "memory": source_vm["memory"], "disk": source_vm["disk"], "vcpus": source_vm["vcpus"], "memory": source_vm["memory"], "disk": source_vm["disk"],
"tenant": tenant_id,
} }
if tenant_id:
payload["tenant"] = tenant_id
platform_id = self.get_platform_id(source_vm.get("guest_os")) platform_id = self.get_platform_id(source_vm.get("guest_os"))
if platform_id: if platform_id:
payload["platform"] = platform_id payload["platform"] = platform_id
@@ -900,14 +899,18 @@ class NetBoxVMImporter:
continue continue
ip_payload = { ip_payload = {
"address": address, "status": "active", "address": address, "status": "active",
"tenant": tenant_id,
"assigned_object_type": "virtualization.vminterface", "assigned_object_type": "virtualization.vminterface",
"assigned_object_id": netbox_interface.id, "assigned_object_id": netbox_interface.id,
} }
try:
ip_object = self.nb.ipam.ip_addresses.get(address=address) ip_object = self.nb.ipam.ip_addresses.get(address=address)
if ip_object: if ip_object:
ip_object.update(ip_payload) ip_object.update(ip_payload)
else: else:
ip_object = self.nb.ipam.ip_addresses.create(ip_payload) ip_object = self.nb.ipam.ip_addresses.create(ip_payload)
except Exception as error:
raise RuntimeError(f"IP-Adresse {address}: {error}") from error
version = ipaddress.ip_interface(address).version version = ipaddress.ip_interface(address).version
if version == 4 and not primary_ipv4: if version == 4 and not primary_ipv4:
primary_ipv4 = ip_object.id primary_ipv4 = ip_object.id
BIN
View File
Binary file not shown.