aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåkon Solbjørg <hakon@solbj.org>2023-03-24 22:35:43 +0100
committerHåkon Solbjørg <hakon@solbj.org>2023-03-24 22:35:43 +0100
commitbcdda4efdd6a0ac813f41ae6d4a93a8fa26602bc (patch)
treee404ac59c631554f8e800af74048e0b0660be833
parent2b8233cedb99955bed82bf83793ba4b5fb18c511 (diff)
fix(nb2gondul): Get mgmt vlan from mgmt ip instead of through arbitrary (wrong) interface
-rw-r--r--tools/netbox/scripts/netbox2gondul/netbox2gondul.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/netbox/scripts/netbox2gondul/netbox2gondul.py b/tools/netbox/scripts/netbox2gondul/netbox2gondul.py
index 5ad0de1..4dfe108 100644
--- a/tools/netbox/scripts/netbox2gondul/netbox2gondul.py
+++ b/tools/netbox/scripts/netbox2gondul/netbox2gondul.py
@@ -145,9 +145,11 @@ class Netbox2Gondul(Script):
distro_interface: Interface = cable.a_terminations[0]
distro = distro_interface.device
- mgmt_vlan = uplink_ae.tagged_vlans.first()
- # Could consider filtering interfaces for: filter(Q(is_management=True) | Q(description__icontains="management")).first()
- # to make sure we only pick management VLANs
+ # This is the same way as we fetch mgmt vlan in the main run() function.
+ # We could pass it in directly to device_to_gondul().
+ mgmt_ip_addr = device.primary_ip4 if device.primary_ip4 is not None else device.primary_ip6
+ mgmt_prefix = Prefix.objects.get(NetHostContained(F('prefix'), str(mgmt_ip_addr)))
+ mgmt_vlan = mgmt_prefix.vlan
mgmt_vlan_name = mgmt_vlan.name
if mgmt_vlan.custom_fields.filter(name='gondul_name').count() == 1 and mgmt_vlan.cf['gondul_name']: