From a665b79f85c02eddb54709dee3398e1ea5d5d188 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 4 Jun 2021 16:46:02 +0200 Subject: [PATCH 01/11] #6455 - initial --- netbox/ipam/models/ip.py | 14 ++------------ netbox/ipam/views.py | 2 +- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py index c6c8cf74c..1f3766e3a 100644 --- a/netbox/ipam/models/ip.py +++ b/netbox/ipam/models/ip.py @@ -340,16 +340,6 @@ class Prefix(PrimaryModel): 'prefix': "Cannot create prefix with /0 mask." }) - # Disallow host masks - if self.prefix.version == 4 and self.prefix.prefixlen == 32: - raise ValidationError({ - 'prefix': "Cannot create host addresses (/32) as prefixes. Create an IPv4 address instead." - }) - elif self.prefix.version == 6 and self.prefix.prefixlen == 128: - raise ValidationError({ - 'prefix': "Cannot create host addresses (/128) as prefixes. Create an IPv6 address instead." - }) - # Enforce unique IP space (if applicable) if (self.vrf is None and settings.ENFORCE_GLOBAL_UNIQUE) or (self.vrf and self.vrf.enforce_unique): duplicate_prefixes = self.get_duplicates() @@ -471,8 +461,8 @@ class Prefix(PrimaryModel): child_ips = netaddr.IPSet([ip.address.ip for ip in self.get_child_ips()]) available_ips = prefix - child_ips - # IPv6, pool, or IPv4 /31 sets are fully usable - if self.family == 6 or self.is_pool or self.prefix.prefixlen == 31: + # IPv6, pool, or IPv4 /31-/32 sets are fully usable + if self.family == 6 or self.is_pool or (self.family == 4 and self.prefix.prefixlen >= 31): return available_ips # For "normal" IPv4 prefixes, omit first and last addresses diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 8de6e9b1c..919b09b79 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -522,7 +522,7 @@ class IPAddressView(generic.ObjectView): # Parent prefixes table parent_prefixes = Prefix.objects.restrict(request.user, 'view').filter( vrf=instance.vrf, - prefix__net_contains=str(instance.address.ip) + prefix__net_contains_or_equals=str(instance.address.ip) ).prefetch_related( 'site', 'role' ) From 5e08b2be37cdd78b0cd12c884935be41efe3f722 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 4 Jun 2021 10:53:13 -0400 Subject: [PATCH 02/11] Fixes #6544: Fix migration error when upgrading with VRF(s) defined --- docs/release-notes/version-2.11.md | 8 ++++++++ netbox/ipam/management/commands/rebuild_prefixes.py | 2 +- .../migrations/0048_prefix_populate_depth_children.py | 2 +- netbox/netbox/settings.py | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index db773e2bd..cbe4db701 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -1,5 +1,13 @@ # NetBox v2.11 +## v2.11.6 (FUTURE) + +### Bug Fixes + +* [#6544](https://github.com/netbox-community/netbox/issues/6544) - Fix migration error when upgrading with VRF(s) defined + +--- + ## v2.11.5 (2021-06-04) **NOTE:** This release includes a database migration that calculates and annotates prefix depth. It may impose a noticeable delay on the upgrade process: Users should anticipate roughly one minute of delay per 100 thousand prefixes being updated. diff --git a/netbox/ipam/management/commands/rebuild_prefixes.py b/netbox/ipam/management/commands/rebuild_prefixes.py index 5d614b834..f84ff3ea4 100644 --- a/netbox/ipam/management/commands/rebuild_prefixes.py +++ b/netbox/ipam/management/commands/rebuild_prefixes.py @@ -22,6 +22,6 @@ class Command(BaseCommand): for vrf in VRF.objects.all(): vrf_count = Prefix.objects.filter(vrf=vrf).count() self.stdout.write(f'VRF {vrf}: {vrf_count} prefixes...') - rebuild_prefixes(vrf) + rebuild_prefixes(vrf.pk) self.stdout.write(self.style.SUCCESS('Finished.')) diff --git a/netbox/ipam/migrations/0048_prefix_populate_depth_children.py b/netbox/ipam/migrations/0048_prefix_populate_depth_children.py index 279f899f6..5ec448ee1 100644 --- a/netbox/ipam/migrations/0048_prefix_populate_depth_children.py +++ b/netbox/ipam/migrations/0048_prefix_populate_depth_children.py @@ -20,7 +20,7 @@ def populate_prefix_hierarchy(apps, schema_editor): # Iterate through all VRFs, rebuilding each for vrf in VRF.objects.all(): - rebuild_prefixes(vrf) + rebuild_prefixes(vrf.pk) class Migration(migrations.Migration): diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 2f8af0538..86ca71a4b 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -16,7 +16,7 @@ from django.core.validators import URLValidator # Environment setup # -VERSION = '2.11.5' +VERSION = '2.11.6-dev' # Hostname HOSTNAME = platform.node() From 4273b6e4fbc147baff4ac8d3ccef4940135198e7 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 4 Jun 2021 10:59:36 -0400 Subject: [PATCH 03/11] Release v2.11.6 --- .github/ISSUE_TEMPLATE/bug_report.yaml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yaml | 2 +- docs/release-notes/version-2.11.md | 2 +- netbox/netbox/settings.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yaml b/.github/ISSUE_TEMPLATE/bug_report.yaml index 6ee058e89..419af2c7a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yaml +++ b/.github/ISSUE_TEMPLATE/bug_report.yaml @@ -17,7 +17,7 @@ body: What version of NetBox are you currently running? (If you don't have access to the most recent NetBox release, consider testing on our [demo instance](https://demo.netbox.dev/) before opening a bug report to see if your issue has already been addressed.) - placeholder: v2.11.5 + placeholder: v2.11.6 validations: required: true - type: dropdown diff --git a/.github/ISSUE_TEMPLATE/feature_request.yaml b/.github/ISSUE_TEMPLATE/feature_request.yaml index c18fc3a1a..80cad1a52 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yaml +++ b/.github/ISSUE_TEMPLATE/feature_request.yaml @@ -14,7 +14,7 @@ body: attributes: label: NetBox version description: What version of NetBox are you currently running? - placeholder: v2.11.5 + placeholder: v2.11.6 validations: required: true - type: dropdown diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index cbe4db701..69df4d614 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -1,6 +1,6 @@ # NetBox v2.11 -## v2.11.6 (FUTURE) +## v2.11.6 (2021-06-04) ### Bug Fixes diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 86ca71a4b..d0fce6628 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -16,7 +16,7 @@ from django.core.validators import URLValidator # Environment setup # -VERSION = '2.11.6-dev' +VERSION = '2.11.6' # Hostname HOSTNAME = platform.node() From 7444110c79f0dbbe3a19047962040ebe09eb51cb Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 4 Jun 2021 11:15:12 -0400 Subject: [PATCH 04/11] PRVB --- netbox/netbox/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index d0fce6628..11c0f750f 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -16,7 +16,7 @@ from django.core.validators import URLValidator # Environment setup # -VERSION = '2.11.6' +VERSION = '2.11.7-dev' # Hostname HOSTNAME = platform.node() From a224e5d4702a8551565bfd8a7d8a3504cb180daa Mon Sep 17 00:00:00 2001 From: drmsoffall Date: Sat, 5 Jun 2021 18:46:52 +0000 Subject: [PATCH 05/11] Closes #6493: show ObjectChange diff for non-atomic changes --- netbox/extras/views.py | 18 +++++++++++++----- netbox/templates/extras/objectchange.html | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/netbox/extras/views.py b/netbox/extras/views.py index 3f86c98d2..5316cfbec 100644 --- a/netbox/extras/views.py +++ b/netbox/extras/views.py @@ -202,15 +202,22 @@ class ObjectChangeView(generic.ObjectView): next_change = objectchanges.filter(time__gt=instance.time).order_by('time').first() prev_change = objectchanges.filter(time__lt=instance.time).order_by('-time').first() - if instance.prechange_data and instance.postchange_data: + if not instance.prechange_data and instance.action in ['update', 'delete'] and prev_change: + non_atomic_change = True + prechange_data = prev_change.postchange_data + else: + non_atomic_change = False + prechange_data = instance.prechange_data + + if prechange_data and instance.postchange_data: diff_added = shallow_compare_dict( - instance.prechange_data or dict(), + prechange_data or dict(), instance.postchange_data or dict(), exclude=['last_updated'], ) diff_removed = { - x: instance.prechange_data.get(x) for x in diff_added - } if instance.prechange_data else {} + x: prechange_data.get(x) for x in diff_added + } if prechange_data else {} else: diff_added = None diff_removed = None @@ -221,7 +228,8 @@ class ObjectChangeView(generic.ObjectView): 'next_change': next_change, 'prev_change': prev_change, 'related_changes_table': related_changes_table, - 'related_changes_count': related_changes.count() + 'related_changes_count': related_changes.count(), + 'non_atomic_change': non_atomic_change } diff --git a/netbox/templates/extras/objectchange.html b/netbox/templates/extras/objectchange.html index 9dcd8c2ac..c49cea79b 100644 --- a/netbox/templates/extras/objectchange.html +++ b/netbox/templates/extras/objectchange.html @@ -128,6 +128,8 @@ {{ k }}: {{ v|render_json }} {% endspaceless %} {% endfor %} + {% elif non_atomic_change %} + Warning: Comparing non-atomic change to previous change record ({{ prev_change.pk }}) {% else %} None {% endif %} From cb4392628fe55fa3be6781d688f241107b66645c Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 8 Jun 2021 14:06:17 -0400 Subject: [PATCH 06/11] Fixes #6553: ProviderNetwork search should match on name --- docs/release-notes/version-2.11.md | 8 ++++++++ netbox/circuits/filtersets.py | 1 + 2 files changed, 9 insertions(+) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 69df4d614..253db7302 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -1,5 +1,13 @@ # NetBox v2.11 +## v2.11.7 (FUTURE) + +### Bug Fixes + +* [#6553](https://github.com/netbox-community/netbox/issues/6553) - ProviderNetwork search should match on name + +--- + ## v2.11.6 (2021-06-04) ### Bug Fixes diff --git a/netbox/circuits/filtersets.py b/netbox/circuits/filtersets.py index 066178685..15bc5a8b3 100644 --- a/netbox/circuits/filtersets.py +++ b/netbox/circuits/filtersets.py @@ -104,6 +104,7 @@ class ProviderNetworkFilterSet(PrimaryModelFilterSet): if not value.strip(): return queryset return queryset.filter( + Q(name__icontains=value) | Q(description__icontains=value) | Q(comments__icontains=value) ).distinct() From 6ec296f2a78056518afcc01f1d52fa59edfd867a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 8 Jun 2021 14:15:06 -0400 Subject: [PATCH 07/11] Fixes #6563: Fix filtering by location for cable connection forms --- docs/release-notes/version-2.11.md | 1 + netbox/dcim/forms.py | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 253db7302..3929a3f8d 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -5,6 +5,7 @@ ### Bug Fixes * [#6553](https://github.com/netbox-community/netbox/issues/6553) - ProviderNetwork search should match on name +* [#6563](https://github.com/netbox-community/netbox/issues/6563) - Fix filtering by location for cable connection forms --- diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index c9c7c86a6..0649168e2 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -3948,6 +3948,7 @@ class ConnectCableToDeviceForm(BootstrapMixin, CustomFieldModelForm): required=False, query_params={ 'site_id': '$termination_b_site', + 'location_id': '$termination_b_location', 'rack_id': '$termination_b_rack', } ) From b3cde51590169b162006aac6eae5052b8076dda5 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 8 Jun 2021 14:18:24 -0400 Subject: [PATCH 08/11] Fixes #6562: Disable ordering of secrets by assigned object --- docs/release-notes/version-2.11.md | 1 + netbox/secrets/tables.py | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 3929a3f8d..532b3a019 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -5,6 +5,7 @@ ### Bug Fixes * [#6553](https://github.com/netbox-community/netbox/issues/6553) - ProviderNetwork search should match on name +* [#6562](https://github.com/netbox-community/netbox/issues/6562) - Disable ordering of secrets by assigned object * [#6563](https://github.com/netbox-community/netbox/issues/6563) - Fix filtering by location for cable connection forms --- diff --git a/netbox/secrets/tables.py b/netbox/secrets/tables.py index 7e164920a..a8324a65d 100644 --- a/netbox/secrets/tables.py +++ b/netbox/secrets/tables.py @@ -37,6 +37,7 @@ class SecretTable(BaseTable): ) assigned_object = tables.Column( linkify=True, + orderable=False, verbose_name='Assigned object' ) role = tables.Column( From 79c06442db7b36e46d2d188984b48f4c8964f5a3 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 8 Jun 2021 15:39:39 -0400 Subject: [PATCH 09/11] Changelog for #6455, 6493 --- docs/release-notes/version-2.11.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 532b3a019..56417fce9 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -2,6 +2,11 @@ ## v2.11.7 (FUTURE) +### Enhancements + +* [#6455](https://github.com/netbox-community/netbox/issues/6455) - Permit /32 IPv4 and /128 IPv6 prefixes +* [#6493](https://github.com/netbox-community/netbox/issues/6493) - Show change log diff for non-atomic (pre-2.11) changes + ### Bug Fixes * [#6553](https://github.com/netbox-community/netbox/issues/6553) - ProviderNetwork search should match on name From 809d9e4697bb8a94192ba73dbc2421b7ea9fda1b Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 10 Jun 2021 14:27:42 -0400 Subject: [PATCH 10/11] Fixes #6584: Fix ordering of nested inventory items --- docs/release-notes/version-2.11.md | 1 + netbox/dcim/tables/devices.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 56417fce9..f010e5d1b 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -12,6 +12,7 @@ * [#6553](https://github.com/netbox-community/netbox/issues/6553) - ProviderNetwork search should match on name * [#6562](https://github.com/netbox-community/netbox/issues/6562) - Disable ordering of secrets by assigned object * [#6563](https://github.com/netbox-community/netbox/issues/6563) - Fix filtering by location for cable connection forms +* [#6584](https://github.com/netbox-community/netbox/issues/6584) - Fix ordering of nested inventory items --- diff --git a/netbox/dcim/tables/devices.py b/netbox/dcim/tables/devices.py index 5f275f1eb..258e712d5 100644 --- a/netbox/dcim/tables/devices.py +++ b/netbox/dcim/tables/devices.py @@ -694,7 +694,7 @@ class InventoryItemTable(DeviceComponentTable): ) cable = None # Override DeviceComponentTable - class Meta(DeviceComponentTable.Meta): + class Meta(BaseTable.Meta): model = InventoryItem fields = ( 'pk', 'device', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', @@ -715,7 +715,7 @@ class DeviceInventoryItemTable(InventoryItemTable): buttons=('edit', 'delete') ) - class Meta(DeviceComponentTable.Meta): + class Meta(BaseTable.Meta): model = InventoryItem fields = ( 'pk', 'name', 'label', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'description', 'discovered', From 7e481960f9035ccc168a5063c9510b127f8846dc Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 14 Jun 2021 09:19:05 -0400 Subject: [PATCH 11/11] Optimize MPTTColumn rendering --- netbox/utilities/tables.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/netbox/utilities/tables.py b/netbox/utilities/tables.py index 14dc3ab6d..b0797fa50 100644 --- a/netbox/utilities/tables.py +++ b/netbox/utilities/tables.py @@ -340,8 +340,11 @@ class MPTTColumn(tables.TemplateColumn): """ Display a nested hierarchy for MPTT-enabled models. """ - template_code = """{% for i in record.get_ancestors %}{% endfor %}""" \ - """{{ record.name }}""" + template_code = """ + {% load helpers %} + {% for i in record.level|as_range %}{% endfor %} + {{ record.name }} + """ def __init__(self, *args, **kwargs): super().__init__(