From c47e2f3c8f745dec1529f1abb0e9ef0f3693d19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20Solbj=C3=B8rg?= Date: Fri, 31 Mar 2023 19:01:35 +0200 Subject: feat(tags): Split network and device tags --- .../netbox/scripts/create-switch/create-switch.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/netbox/scripts/create-switch/create-switch.py b/tools/netbox/scripts/create-switch/create-switch.py index cdba028..aeaa1e1 100644 --- a/tools/netbox/scripts/create-switch/create-switch.py +++ b/tools/netbox/scripts/create-switch/create-switch.py @@ -27,6 +27,7 @@ ACCESS_SWITCH_DEVICE_ROLE = DeviceRole.objects.get(name='Access Switch') DEFAULT_SITE = Site.objects.get(slug='ring') # Site.objects.first() # TODO: pick default site ? DEFAULT_L1_SWITCH = Device.objects.get(name='d1.ring') # Site.objects.first() # TODO: pick default site ? DEFAULT_DEVICE_TYPE = DeviceType.objects.get(model='EX2200-48T') # Site.objects.first() # TODO: pick default site ? +DEFAULT_NETWORK_TAGS = [Tag.objects.get(name='dhcp-client')] UPLINK_TYPES = ( (InterfaceTypeChoices.TYPE_10GE_SFP_PLUS, '10G SFP+'), @@ -170,10 +171,24 @@ class CreateSwitch(Script): # required=False, # default='', #) - tags = MultiObjectVar( + device_tags = MultiObjectVar( + label="Device tags", description="Tags to be sent to Gondul. These are used for templating, so be sure what they do.", model=Tag, required=False, + query_params={ + "description__ic": "for:device", + }, + ) + network_tags = MultiObjectVar( + label="Network tags", + description="Tags to be sent to Gondul. These are used for templating, so be sure what they do.", + default=DEFAULT_NETWORK_TAGS, + model=Tag, + required=False, + query_params={ + "description__ic": "for:network", + }, ) nat = BooleanVar( @@ -209,7 +224,7 @@ class CreateSwitch(Script): site=data['site'], ) switch.save() - for tag in data['tags']: + for tag in data['device_tags']: switch.tags.add(tag) self.log_success(f"Created new switch: {switch}") @@ -228,8 +243,9 @@ class CreateSwitch(Script): vid=vid ) vlan.save() - + for tag in data['network_tags']: + vlan.tags.add(tag) # Only do this if access switch if data['leveranse'].name == "Access Switch": -- cgit v1.2.3