diff options
author | Håkon Solbjørg <hakon@solbj.org> | 2023-03-31 19:49:15 +0200 |
---|---|---|
committer | Håkon Solbjørg <hakon@solbj.org> | 2023-03-31 20:38:48 +0200 |
commit | 0e69ebd815356a8c8452018082d9125793f2813e (patch) | |
tree | ff76e1c227430fad9fc99ac48a46e34454ad1486 | |
parent | c47e2f3c8f745dec1529f1abb0e9ef0f3693d19a (diff) |
feat(tags): Add num-uplinks and uplink-type tags automagically
-rw-r--r-- | tools/netbox/scripts/create-switch/create-switch.py | 13 |
1 files changed, 13 insertions, 0 deletions
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 <a href=\"/extras/scripts/netbox2gondul.Netbox2Gondul/?device={ switch.id }\">trigger an update immediately</a> or <a href=\"{switch.get_absolute_url()}\">view the device</a> first and trigger an update from there.") |