feat: map hypervisor clusters to NetBox clusters automatically
- Read the vCenter/ESXi compute resource and the Proxmox cluster name (node name when standalone) for every VM - Match each hypervisor cluster to a NetBox cluster by name, normalized name or unique similarity; remember manual choices per profile and offer to create missing clusters (with cluster type) - Import wizard: per-cluster mapping table instead of a single cluster, tenant prefilled from the mapped clusters, review shows the mapping - Show the hypervisor cluster in the VM table fix: graphic glitches - Empty state text no longer clipped by the buttons - Combo boxes open a plain drop-down list instead of the overlay popup - Status bar badges keep their height and no longer get cut off Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
4878275f2a
commit
c3b5fb547e
12 files changed
+300
-50
No files matched your search
@@ -73,5 +73,6 @@ class FakeNetBox:
|
||||
self.dcim = SimpleNamespace(devices=Endpoint(), interfaces=Endpoint(), cables=Endpoint(),
|
||||
mac_addresses=Endpoint(), platforms=Endpoint())
|
||||
self.ipam = SimpleNamespace(ip_addresses=Endpoint(), prefixes=Endpoint(), vrfs=Endpoint())
|
||||
self.virtualization = SimpleNamespace(clusters=Endpoint(), virtual_machines=Endpoint(), interfaces=Endpoint())
|
||||
self.virtualization = SimpleNamespace(clusters=Endpoint(), cluster_types=Endpoint(), virtual_machines=Endpoint(),
|
||||
interfaces=Endpoint())
|
||||
self.tenancy = SimpleNamespace(tenants=Endpoint())
|
||||
@@ -20,6 +20,7 @@ def test_roundtrip_encrypts_secrets(tmp_path):
|
||||
"token_secret": "geheim", "enabled": True}],
|
||||
"switches": [{"id": "w1", "name": "sw1", "device_id": 5, "platform": "auto", "host": "10.0.0.1",
|
||||
"port": 22, "username": "admin", "password": "pw", "enabled": True, "_runtime": "x"}],
|
||||
"cluster_map": {"s1:pve-cluster": "PVE-Prod"},
|
||||
}
|
||||
}
|
||||
settings = dict(DEFAULT_SETTINGS, theme="dark")
|
||||
@@ -35,6 +36,7 @@ def test_roundtrip_encrypts_secrets(tmp_path):
|
||||
assert loaded["Kunde A"]["netbox_token"] == "token-123"
|
||||
assert loaded["Kunde A"]["sources"][0]["token_secret"] == "geheim"
|
||||
assert loaded["Kunde A"]["switches"][0]["password"] == "pw"
|
||||
assert loaded["Kunde A"]["cluster_map"] == {"s1:pve-cluster": "PVE-Prod"}
|
||||
|
||||
|
||||
def test_unreadable_secret_does_not_block_loading(tmp_path):
|
||||
|
||||
@@ -58,3 +58,29 @@ def test_global_vrf_import():
|
||||
engine.sync_vm(VM, cluster_id=1, tenant_id=10, vrf_id=None)
|
||||
assert "vrf" not in nb.ipam.prefixes.created[0]
|
||||
assert nb.ipam.ip_addresses.created[0]["vrf"] is None
|
||||
|
||||
|
||||
def test_match_cluster_by_name_similarity_and_memory():
|
||||
nb, engine = _engine()
|
||||
for index, name in enumerate(("PVE-Prod", "vSphere Cluster RZ2"), start=2):
|
||||
nb.virtualization.clusters.records.append(Record(nb.virtualization.clusters, id=index, name=name, tenant=None))
|
||||
engine.load_targets()
|
||||
assert engine.match_cluster("rz1") == ("RZ1", "name")
|
||||
assert engine.match_cluster("pve_prod") == ("PVE-Prod", "name")
|
||||
assert engine.match_cluster("RZ2") == ("vSphere Cluster RZ2", "similar")
|
||||
assert engine.match_cluster("unbekannt") == (None, None)
|
||||
assert engine.match_cluster("unbekannt", remembered="PVE-Prod") == ("PVE-Prod", "remembered")
|
||||
# A remembered cluster that was deleted in NetBox falls back to matching.
|
||||
assert engine.match_cluster("rz1", remembered="weg") == ("RZ1", "name")
|
||||
|
||||
|
||||
def test_create_cluster_with_type():
|
||||
nb, engine = _engine()
|
||||
cluster_id = engine.create_cluster("pve-lab", "Proxmox", tenant_id=10)
|
||||
assert engine.clusters["pve-lab"] == cluster_id
|
||||
assert nb.virtualization.cluster_types.created == [{"name": "Proxmox VE", "slug": "proxmox-ve"}]
|
||||
created = nb.virtualization.clusters.created[0]
|
||||
assert created["name"] == "pve-lab" and created["tenant"] == 10
|
||||
# Type is reused for the next cluster.
|
||||
engine.create_cluster("pve-lab2", "Proxmox")
|
||||
assert len(nb.virtualization.cluster_types.created) == 1
|
||||
Reference in new issue
Block a user