From 0e69ebd815356a8c8452018082d9125793f2813e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Solbj=C3=B8rg?= Date: Fri, 31 Mar 2023 19:49:15 +0200 Subject: feat(tags): Add num-uplinks and uplink-type tags automagically --- tools/netbox/scripts/create-switch/create-switch.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/netbox/scripts/create-switch/create-switch.py b/tools/netbox/scripts/create-switch/create-switch.py index aeaa1e1..b4c894e 100644 --- a/tools/netbox/scripts/create-switch/create-switch.py +++ b/tools/netbox/scripts/create-switch/create-switch.py @@ -424,4 +424,17 @@ class CreateSwitch(Script): cable.save() self.log_success(f"Cabled {data['destination_device']} {a_interface} to {switch} {b_interface}") + try: + uplink_tag = Tag.objects.get(slug=f"{num_uplinks}-uplinks") + switch.tags.add(uplink_tag) + except Tag.DoesNotExist as e: + self.log_error("Failed to find device tag with {num_uplinks} uplinks.") + raise e + + uplink_type = data['uplink_type'] + if uplink_type in [InterfaceTypeChoices.TYPE_10GE_SFP_PLUS, InterfaceTypeChoices.TYPE_10GE_FIXED]: + uplink_type_tag = Tag.objects.get(slug="10g-uplink") + switch.tags.add(uplink_type_tag) + self.log_info(f"Added device tag for 10g uplinks if it wasn't present already: {uplink_type_tag}") + self.log_success(f"To create this switch in Gondul you can trigger an update immediately or view the device first and trigger an update from there.") -- cgit v1.2.3