From a8af24d7ca5af79987a8b2fb68a7e389638e7461 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 22 Jun 2021 14:16:16 -0400 Subject: [PATCH] Fixes #6637: Fix group assignment in 'available VLANs' link under VLAN group view --- docs/release-notes/version-2.11.md | 1 + netbox/ipam/tables.py | 2 +- netbox/ipam/utils.py | 26 +++++++++++++++++++++----- netbox/ipam/views.py | 2 +- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 06020a9ac..f03271c3b 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -5,6 +5,7 @@ ### Bug Fixes * [#6626](https://github.com/netbox-community/netbox/issues/6626) - Fix site field on VM search form; add site group +* [#6637](https://github.com/netbox-community/netbox/issues/6637) - Fix group assignment in "available VLANs" link under VLAN group view * [#6640](https://github.com/netbox-community/netbox/issues/6640) - Disallow numeric values in custom text fields * [#6652](https://github.com/netbox-community/netbox/issues/6652) - Fix exception when adding components in bulk to multiple devices diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index c564985f7..728969738 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -65,7 +65,7 @@ VLAN_LINK = """ {% if record.pk %} {{ record.vid }} {% elif perms.ipam.add_vlan %} - {{ record.available }} VLAN{{ record.available|pluralize }} available + {{ record.available }} VLAN{{ record.available|pluralize }} available {% else %} {{ record.available }} VLAN{{ record.available|pluralize }} available {% endif %} diff --git a/netbox/ipam/utils.py b/netbox/ipam/utils.py index 18a470253..0e79e7f78 100644 --- a/netbox/ipam/utils.py +++ b/netbox/ipam/utils.py @@ -68,24 +68,40 @@ def add_available_ipaddresses(prefix, ipaddress_list, is_pool=False): return output -def add_available_vlans(vlan_group, vlans): +def add_available_vlans(vlans, vlan_group=None): """ Create fake records for all gaps between used VLANs """ if not vlans: - return [{'vid': VLAN_VID_MIN, 'available': VLAN_VID_MAX - VLAN_VID_MIN + 1}] + return [{ + 'vid': VLAN_VID_MIN, + 'vlan_group': vlan_group, + 'available': VLAN_VID_MAX - VLAN_VID_MIN + 1 + }] prev_vid = VLAN_VID_MAX new_vlans = [] for vlan in vlans: if vlan.vid - prev_vid > 1: - new_vlans.append({'vid': prev_vid + 1, 'available': vlan.vid - prev_vid - 1}) + new_vlans.append({ + 'vid': prev_vid + 1, + 'vlan_group': vlan_group, + 'available': vlan.vid - prev_vid - 1, + }) prev_vid = vlan.vid if vlans[0].vid > VLAN_VID_MIN: - new_vlans.append({'vid': VLAN_VID_MIN, 'available': vlans[0].vid - VLAN_VID_MIN}) + new_vlans.append({ + 'vid': VLAN_VID_MIN, + 'vlan_group': vlan_group, + 'available': vlans[0].vid - VLAN_VID_MIN, + }) if prev_vid < VLAN_VID_MAX: - new_vlans.append({'vid': prev_vid + 1, 'available': VLAN_VID_MAX - prev_vid}) + new_vlans.append({ + 'vid': prev_vid + 1, + 'vlan_group': vlan_group, + 'available': VLAN_VID_MAX - prev_vid, + }) vlans = list(vlans) + new_vlans vlans.sort(key=lambda v: v.vid if type(v) == VLAN else v['vid']) diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 596810b0f..95546fcc6 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -675,7 +675,7 @@ class VLANGroupView(generic.ObjectView): Prefetch('prefixes', queryset=Prefix.objects.restrict(request.user)) ).order_by('vid') vlans_count = vlans.count() - vlans = add_available_vlans(instance, vlans) + vlans = add_available_vlans(vlans, vlan_group=instance) vlans_table = tables.VLANDetailTable(vlans) if request.user.has_perm('ipam.change_vlan') or request.user.has_perm('ipam.delete_vlan'):