From b84b526a434590797b9fadb3ceb7b9aafffeaa40 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Fri, 15 Sep 2017 15:14:35 -0400 Subject: [PATCH] Closes #1484: Added individual "add VLAN" buttons on the VLAN groups list --- netbox/ipam/models.py | 10 ++++++++++ netbox/ipam/tables.py | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index bbd5e1827..214293b7d 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -512,6 +512,16 @@ class VLANGroup(models.Model): def get_absolute_url(self): return "{}?group_id={}".format(reverse('ipam:vlan_list'), self.pk) + def get_next_available_vid(self): + """ + Return the first available VLAN ID (1-4094) in the group. + """ + vids = [vlan['vid'] for vlan in self.vlans.order_by('vid').values('vid')] + for i in range(1, 4095): + if i not in vids: + return i + return None + @python_2_unicode_compatible class VLAN(CreatedUpdatedModel, CustomFieldModel): diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 96127aec5..512b75649 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -120,6 +120,13 @@ VLAN_ROLE_LINK = """ """ VLANGROUP_ACTIONS = """ +{% with next_vid=record.get_next_available_vid %} + {% if next_vid and perms.ipam.add_vlan %} + + + + {% endif %} +{% endwith %} {% if perms.ipam.change_vlangroup %} {% endif %}