aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåkon Solbjørg <hakon@solbj.org>2023-04-02 13:04:40 +0200
committerHåkon Solbjørg <hakon@solbj.org>2023-04-02 13:04:40 +0200
commit350605be75f4efb50884cf6339f785af0c0d8074 (patch)
tree0e3cd96d0e206a6cabc2e3f17520fa1b6a37b8f4
parentec108cbffa3113e19620a4927275f937e96b00da (diff)
fix(netbox2gondul): Add more checks for invalid configuration for gondul
-rw-r--r--tools/netbox/scripts/netbox2gondul/netbox2gondul.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/tools/netbox/scripts/netbox2gondul/netbox2gondul.py b/tools/netbox/scripts/netbox2gondul/netbox2gondul.py
index 5b98be5..3c6394a 100644
--- a/tools/netbox/scripts/netbox2gondul/netbox2gondul.py
+++ b/tools/netbox/scripts/netbox2gondul/netbox2gondul.py
@@ -197,7 +197,7 @@ class Netbox2Gondul(Script):
input_devices: list[Type[Device]] = data['device']
if len(input_devices) == 0:
- input_devices = Device.objects.all()
+ input_devices = Device.objects.filter(status=DeviceStatusChoices.STATUS_ACTIVE)
networks = []
switches = []
@@ -218,19 +218,38 @@ class Netbox2Gondul(Script):
self.log_warning(f"Failed to configure {device} for import: {e}")
continue
else:
- self.log_warning(f'Device <a href="{device.get_absolute_url()}">{device.name}</a> is missing primary IPv4 address.')
+ self.log_warning(f'Device <a href="{device.get_absolute_url()}">{device.name}</a> is missing primary IPv4 address. Skipping.')
+ continue
prefix_v6: Prefix = None
if device.primary_ip6:
prefix_v6 = Prefix.objects.get(NetHostContained(F('prefix'), str(device.primary_ip6)))
vlan = prefix_v6.vlan
else:
- self.log_warning(f'Device <a href="{device.get_absolute_url()}">{device.name}</a> is missing primary IPv6 address.')
+ self.log_warning(f'Device <a href="{device.get_absolute_url()}">{device.name}</a> is missing primary IPv6 address. Skipping.')
+ continue
+
+ if not vlan:
+ self.log_warning(f"Skipping {device}: missing vlan")
+ continue
if prefix_v4 is not None and prefix_v6 is not None and prefix_v4.vlan != prefix_v6.vlan:
self.log_warning(f'VLANs differ for the IPv4 and IPv6 addresses, skipping...')
continue
+ if (uplink_aes := list(device.interfaces.filter(name="ae0"))):
+ if len(uplink_aes) == 0:
+ self.log_warning(f"Skipping {device}: Missing uplink AE")
+ continue
+
+ uplink_ae = uplink_aes[0]
+ first_uplink_interface = uplink_ae.member_interfaces.first()
+ if first_uplink_interface is None:
+ self.log_warning(f"Skipping {device}: Missing lag member for ae0")
+ continue
+ if not first_uplink_interface.cable:
+ self.log_warning(f"Skipping {device}: Missing netbox cable for uplink AE")
+ continue
networks.append(self.network_to_gondul_format(vlan, prefix_v4, prefix_v6))
switch, traffic_network = self.device_to_gondul_format(device)