diff options
author | Håkon Solbjørg <hakon@solbj.org> | 2023-04-06 17:24:51 +0200 |
---|---|---|
committer | Håkon Solbjørg <hakon@solbj.org> | 2023-04-06 17:24:51 +0200 |
commit | 590210662c8d5f39dc9fd486f54860e75b368e4f (patch) | |
tree | 58983401d6c2fc45170666885ae986beaa210ad3 /tools | |
parent | a4d9bdca72f0678c95c10a9af0290305b18dea71 (diff) |
fix(netbox2gondul): Get cable for uplink interface without requiring ae0
Diffstat (limited to 'tools')
-rw-r--r-- | tools/netbox/scripts/netbox2gondul/netbox2gondul.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/netbox/scripts/netbox2gondul/netbox2gondul.py b/tools/netbox/scripts/netbox2gondul/netbox2gondul.py index 5fb4ad8..d69f822 100644 --- a/tools/netbox/scripts/netbox2gondul/netbox2gondul.py +++ b/tools/netbox/scripts/netbox2gondul/netbox2gondul.py @@ -148,12 +148,18 @@ class Netbox2Gondul(Script): self.log_failure(f"Gondul said HTTP {req.status_code} and {req.text}") def device_to_gondul_format(self, device: Device): + an_uplink_interface = None + # Find distro and distro port through the cable connected on uplink ae. # Assuming the uplink AE is always named 'ae0'. - uplink_ae: Interface = device.interfaces.get(name="ae0") + try: + uplink_ae: Interface = device.interfaces.get(name="ae0") + an_uplink_interface: Interface = uplink_ae.member_interfaces.first() + except Interface.DoesNotExist: + # If we don't have ae0, assume we're an AP and have eth0. + an_uplink_interface = device.interfaces.get(name="eth0") - first_ae_interface: Interface = uplink_ae.member_interfaces.first() - cable: Cable = first_ae_interface.cable + cable: Cable = an_uplink_interface.cable # Assuming we only have one entry in the cable termination list. distro_interface: Interface = cable.a_terminations[0] if cable.a_terminations[0].device != device else cable.b_terminations[0] distro = distro_interface.device |