From bcdda4efdd6a0ac813f41ae6d4a93a8fa26602bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Solbj=C3=B8rg?= Date: Fri, 24 Mar 2023 22:35:43 +0100 Subject: fix(nb2gondul): Get mgmt vlan from mgmt ip instead of through arbitrary (wrong) interface --- tools/netbox/scripts/netbox2gondul/netbox2gondul.py | 8 +++++--- 1 file 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']: -- cgit v1.2.3