From 826a1714c37b94ca26f23936f120cb19981815b7 Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 1 Dec 2022 08:52:16 -0800 Subject: [PATCH 01/13] 11041 return power percentage with 1 decimal place --- netbox/utilities/templatetags/helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 139562355..18abe86b1 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -138,7 +138,8 @@ def percentage(x, y): """ if x is None or y is None: return None - return round(x / y * 100) + + return round(x / y * 100, 1) @register.filter() From ee03f3d5846f9342782553245a6750e50eab33e4 Mon Sep 17 00:00:00 2001 From: PieterL75 <74899468+PieterL75@users.noreply.github.com> Date: Fri, 2 Dec 2022 15:27:47 +0100 Subject: [PATCH 02/13] 10748 Add 'Provider' to the circuit termination edit/view (#10939) * Show the Provider of the NetworkProvider * Clean up form fields Co-authored-by: Pieter Lambrecht Co-authored-by: jeremystretch --- netbox/circuits/forms/models.py | 16 ++++++++++++++-- .../circuits/circuittermination_edit.html | 1 + .../circuits/inc/circuit_termination.html | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/netbox/circuits/forms/models.py b/netbox/circuits/forms/models.py index aebdce10e..7dd85aef9 100644 --- a/netbox/circuits/forms/models.py +++ b/netbox/circuits/forms/models.py @@ -158,16 +158,28 @@ class CircuitTerminationForm(NetBoxModelForm): }, required=False ) + provider_network_provider = DynamicModelChoiceField( + queryset=Provider.objects.all(), + required=False, + label='Provider', + initial_params={ + 'networks': 'provider_network' + } + ) provider_network = DynamicModelChoiceField( queryset=ProviderNetwork.objects.all(), + query_params={ + 'provider_id': '$provider_network_provider', + }, required=False ) class Meta: model = CircuitTermination fields = [ - 'provider', 'circuit', 'term_side', 'region', 'site_group', 'site', 'provider_network', 'mark_connected', - 'port_speed', 'upstream_speed', 'xconnect_id', 'pp_info', 'description', 'tags', + 'provider', 'circuit', 'term_side', 'region', 'site_group', 'site', 'provider_network_provider', + 'provider_network', 'mark_connected', 'port_speed', 'upstream_speed', 'xconnect_id', 'pp_info', + 'description', 'tags', ] help_texts = { 'port_speed': "Physical circuit speed", diff --git a/netbox/templates/circuits/circuittermination_edit.html b/netbox/templates/circuits/circuittermination_edit.html index 5196eddf2..f171ecc1b 100644 --- a/netbox/templates/circuits/circuittermination_edit.html +++ b/netbox/templates/circuits/circuittermination_edit.html @@ -32,6 +32,7 @@ {% render_field form.site %}
+ {% render_field form.provider_network_provider %} {% render_field form.provider_network %}
diff --git a/netbox/templates/circuits/inc/circuit_termination.html b/netbox/templates/circuits/inc/circuit_termination.html index f4e0ea6ca..160ff940f 100644 --- a/netbox/templates/circuits/inc/circuit_termination.html +++ b/netbox/templates/circuits/inc/circuit_termination.html @@ -81,7 +81,7 @@ {% else %} Provider Network - {{ termination.provider_network|linkify }} + {{ termination.provider_network.provider|linkify }} / {{ termination.provider_network|linkify }} {% endif %} From db7590df1a797de143e9128d880df1a3553c255d Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 2 Dec 2022 09:30:44 -0500 Subject: [PATCH 03/13] Changelog for #10748, #11041 --- docs/release-notes/version-3.3.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index 2d62fb5bd..c35ac2a64 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -2,6 +2,14 @@ ## v3.3.10 (FUTURE) +### Enhancements + +* [#10748](https://github.com/netbox-community/netbox/issues/10748) - Add provider selection field for provider networks to circuit termination edit view + +### Bug Fixes + +* [#11041](https://github.com/netbox-community/netbox/issues/11041) - Correct power utilization percentage precision + --- ## v3.3.9 (2022-11-30) From d4d8d00d01d422adaa13cd1fbd0384ee39ea1d9f Mon Sep 17 00:00:00 2001 From: Renato Almeida de Oliveira Date: Sat, 3 Dec 2022 20:02:51 +0000 Subject: [PATCH 04/13] add distinct method to circuit_count --- netbox/dcim/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index e8a7c66bd..edc9a5ce8 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -335,7 +335,7 @@ class SiteView(generic.ObjectView): scope_id=instance.pk ).count(), 'vlan_count': VLAN.objects.restrict(request.user, 'view').filter(site=instance).count(), - 'circuit_count': Circuit.objects.restrict(request.user, 'view').filter(terminations__site=instance).count(), + 'circuit_count': Circuit.objects.restrict(request.user, 'view').filter(terminations__site=instance).distinct().count(), 'vm_count': VirtualMachine.objects.restrict(request.user, 'view').filter(cluster__site=instance).count(), } locations = Location.objects.add_related_count( From d2d60c06075bae3188bd6a6a28cc1aa15ff18c55 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 6 Dec 2022 15:40:59 -0500 Subject: [PATCH 05/13] Fixes #11087: Fix background color of bottom banner content --- docs/release-notes/version-3.3.md | 2 ++ netbox/templates/base/layout.html | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index c35ac2a64..321cb28b9 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -9,6 +9,8 @@ ### Bug Fixes * [#11041](https://github.com/netbox-community/netbox/issues/11041) - Correct power utilization percentage precision +* [#11087](https://github.com/netbox-community/netbox/issues/11087) - Fix background color of bottom banner content +* [#11101](https://github.com/netbox-community/netbox/issues/11101) - Correct circuits count under site view --- diff --git a/netbox/templates/base/layout.html b/netbox/templates/base/layout.html index dd0412eac..e4db1a1f5 100644 --- a/netbox/templates/base/layout.html +++ b/netbox/templates/base/layout.html @@ -103,14 +103,14 @@ Blocks: {% block content %}{% endblock %} {% endblock %} + {# Bottom banner #} + {% if config.BANNER_BOTTOM %} +
+ {{ config.BANNER_BOTTOM|safe }} +
+ {% endif %} - {% if config.BANNER_BOTTOM %} -
- {{ config.BANNER_BOTTOM|safe }} -
- {% endif %} - {# BS5 pop-up modals #} {% block modals %}{% endblock %} From 780997a568e79a3b86aa0ad19ef40bde370ee42f Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 6 Dec 2022 15:48:22 -0500 Subject: [PATCH 06/13] Closes #11119: Enable filtering L2VPNs by slug --- docs/release-notes/version-3.3.md | 1 + netbox/ipam/filtersets.py | 2 +- netbox/ipam/tests/test_filtersets.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index 321cb28b9..f5bd53b80 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -5,6 +5,7 @@ ### Enhancements * [#10748](https://github.com/netbox-community/netbox/issues/10748) - Add provider selection field for provider networks to circuit termination edit view +* [#11119](https://github.com/netbox-community/netbox/issues/11119) - Enable filtering L2VPNs by slug ### Bug Fixes diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index 3c0ab1ac8..2634dd725 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -960,7 +960,7 @@ class L2VPNFilterSet(NetBoxModelFilterSet, TenancyFilterSet): class Meta: model = L2VPN - fields = ['id', 'identifier', 'name', 'type', 'description'] + fields = ['id', 'identifier', 'name', 'slug', 'type', 'description'] def search(self, queryset, name, value): if not value.strip(): diff --git a/netbox/ipam/tests/test_filtersets.py b/netbox/ipam/tests/test_filtersets.py index 5c4113786..d67994fc1 100644 --- a/netbox/ipam/tests/test_filtersets.py +++ b/netbox/ipam/tests/test_filtersets.py @@ -1501,6 +1501,10 @@ class L2VPNTestCase(TestCase, ChangeLoggedFilterSetTests): params = {'name': ['L2VPN 1', 'L2VPN 2']} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) + def test_slug(self): + params = {'slug': ['l2vpn-1', 'l2vpn-2']} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) + def test_identifier(self): params = {'identifier': ['65001', '65002']} self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2) From 0cacac82ee4cb9fb51eb52c931f77b16efc5a7ef Mon Sep 17 00:00:00 2001 From: kkthxbye-code Date: Thu, 8 Dec 2022 12:02:10 +0100 Subject: [PATCH 07/13] Disable sorting by object_repr on ObjectChangeTable --- netbox/extras/tables/tables.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox/extras/tables/tables.py b/netbox/extras/tables/tables.py index 1df5c9487..22da5f52a 100644 --- a/netbox/extras/tables/tables.py +++ b/netbox/extras/tables/tables.py @@ -195,7 +195,8 @@ class ObjectChangeTable(NetBoxTable): object_repr = tables.TemplateColumn( accessor=tables.A('changed_object'), template_code=OBJECTCHANGE_OBJECT, - verbose_name='Object' + verbose_name='Object', + orderable=False ) request_id = tables.TemplateColumn( template_code=OBJECTCHANGE_REQUEST_ID, From 35596ddcbcce6b7287114b6e326d4c50be90151b Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 8 Dec 2022 08:56:57 -0500 Subject: [PATCH 08/13] Closes #10806: Add warning to run deactivate prior to upgrade script --- docs/installation/3-netbox.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/installation/3-netbox.md b/docs/installation/3-netbox.md index 72c054e5b..a2a2d9df3 100644 --- a/docs/installation/3-netbox.md +++ b/docs/installation/3-netbox.md @@ -225,6 +225,9 @@ Once NetBox has been configured, we're ready to proceed with the actual installa * Builds the documentation locally (for offline use) * Aggregate static resource files on disk +!!! warning + If you still have a Python virtual environment active from a previous installation step, disable it now by running the `deactivate` command. This will avoid errors on systems where `sudo` has been configured to preserve the user's current environment. + ```no-highlight sudo /opt/netbox/upgrade.sh ``` From ab9c253310dc36dca2aa685dc97cf9d43a518d5e Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 8 Dec 2022 08:59:26 -0500 Subject: [PATCH 09/13] Fixes #11128: Disable ordering changelog table by object to avoid exception --- docs/release-notes/version-3.3.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-3.3.md b/docs/release-notes/version-3.3.md index f5bd53b80..4dd717f9b 100644 --- a/docs/release-notes/version-3.3.md +++ b/docs/release-notes/version-3.3.md @@ -12,6 +12,7 @@ * [#11041](https://github.com/netbox-community/netbox/issues/11041) - Correct power utilization percentage precision * [#11087](https://github.com/netbox-community/netbox/issues/11087) - Fix background color of bottom banner content * [#11101](https://github.com/netbox-community/netbox/issues/11101) - Correct circuits count under site view +* [#11128](https://github.com/netbox-community/netbox/issues/11128) - Disable ordering changelog table by object to avoid exception --- From 080a001118e43669fbce56a66c88e30712d1c424 Mon Sep 17 00:00:00 2001 From: kkthxbye-code Date: Mon, 5 Dec 2022 10:04:28 +0100 Subject: [PATCH 10/13] Allow redefining internally used queues --- docs/configuration/miscellaneous.md | 16 ++++++++++++++++ netbox/extras/models/models.py | 4 +++- netbox/extras/webhooks.py | 4 +++- netbox/netbox/settings.py | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/configuration/miscellaneous.md b/docs/configuration/miscellaneous.md index 614e90eac..4eb090554 100644 --- a/docs/configuration/miscellaneous.md +++ b/docs/configuration/miscellaneous.md @@ -141,6 +141,22 @@ When determining the primary IP address for a device, IPv6 is preferred over IPv --- +## QUEUE_MAPPINGS + +Allows changing which queues are used internally for background tasks. + +```python +QUEUE_MAPPINGS = { + 'webhook': 'low', + 'report': 'high', + 'script': 'high', +} +``` + +If no queue is defined the queue named `default` will be used. + +--- + ## RELEASE_CHECK_URL Default: None (disabled) diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 95a414225..402047194 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -21,6 +21,7 @@ from extras.choices import * from extras.constants import * from extras.conditions import ConditionSet from extras.utils import FeatureQuery, image_upload +from netbox.config import get_config from netbox.models import ChangeLoggedModel from netbox.models.features import ( CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, JobResultsMixin, TagsMixin, WebhooksMixin, @@ -681,7 +682,8 @@ class JobResult(models.Model): job_id=uuid.uuid4() ) - queue = django_rq.get_queue("default") + rq_queue_name = get_config().QUEUE_MAPPINGS.get(obj_type.name, 'default') + queue = django_rq.get_queue(rq_queue_name) if schedule_at: job_result.status = JobResultStatusChoices.STATUS_SCHEDULED diff --git a/netbox/extras/webhooks.py b/netbox/extras/webhooks.py index a93be7934..18dcd0cfe 100644 --- a/netbox/extras/webhooks.py +++ b/netbox/extras/webhooks.py @@ -5,6 +5,7 @@ from django.contrib.contenttypes.models import ContentType from django.utils import timezone from django_rq import get_queue +from netbox.config import get_config from netbox.registry import registry from utilities.api import get_serializer_for_model from utilities.utils import serialize_object @@ -78,7 +79,8 @@ def flush_webhooks(queue): """ Flush a list of object representation to RQ for webhook processing. """ - rq_queue = get_queue('default') + rq_queue_name = get_config().QUEUE_MAPPINGS.get('webhook', 'default') + rq_queue = get_queue(rq_queue_name) webhooks_cache = { 'type_create': {}, 'type_update': {}, diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 4dbf48c36..15017f966 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -101,6 +101,7 @@ MEDIA_ROOT = getattr(configuration, 'MEDIA_ROOT', os.path.join(BASE_DIR, 'media' METRICS_ENABLED = getattr(configuration, 'METRICS_ENABLED', False) PLUGINS = getattr(configuration, 'PLUGINS', []) PLUGINS_CONFIG = getattr(configuration, 'PLUGINS_CONFIG', {}) +QUEUE_MAPPINGS = getattr(configuration, 'QUEUE_MAPPINGS', {}) RELEASE_CHECK_URL = getattr(configuration, 'RELEASE_CHECK_URL', None) REMOTE_AUTH_AUTO_CREATE_USER = getattr(configuration, 'REMOTE_AUTH_AUTO_CREATE_USER', False) REMOTE_AUTH_BACKEND = getattr(configuration, 'REMOTE_AUTH_BACKEND', 'netbox.authentication.RemoteUserBackend') From d53ddd611bbf8d3b5057c2394447412c7b017e0c Mon Sep 17 00:00:00 2001 From: kkthxbye-code Date: Mon, 5 Dec 2022 10:22:51 +0100 Subject: [PATCH 11/13] Add any queues defined in QUEUE_MAPPINGS to RQ_QUEUES --- netbox/netbox/settings.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index 15017f966..fb5b6ee10 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -645,6 +645,11 @@ RQ_QUEUES = { 'low': RQ_PARAMS, } +# Add any queues defined in QUEUE_MAPPINGS +RQ_QUEUES.update({ + queue: RQ_PARAMS for queue in set(QUEUE_MAPPINGS.values()) if queue not in RQ_QUEUES +}) + # # Plugins From 6ffd8aa320ec86ebca7588b032954caa1b7fee15 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 8 Dec 2022 09:58:52 -0500 Subject: [PATCH 12/13] Introduce constants for RQ queue names --- netbox/extras/models/models.py | 3 ++- netbox/extras/webhooks.py | 3 ++- netbox/netbox/constants.py | 5 +++++ netbox/netbox/settings.py | 7 ++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index 402047194..3f9d1d17e 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -22,6 +22,7 @@ from extras.constants import * from extras.conditions import ConditionSet from extras.utils import FeatureQuery, image_upload from netbox.config import get_config +from netbox.constants import RQ_QUEUE_DEFAULT from netbox.models import ChangeLoggedModel from netbox.models.features import ( CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, JobResultsMixin, TagsMixin, WebhooksMixin, @@ -682,7 +683,7 @@ class JobResult(models.Model): job_id=uuid.uuid4() ) - rq_queue_name = get_config().QUEUE_MAPPINGS.get(obj_type.name, 'default') + rq_queue_name = get_config().QUEUE_MAPPINGS.get(obj_type.name, RQ_QUEUE_DEFAULT) queue = django_rq.get_queue(rq_queue_name) if schedule_at: diff --git a/netbox/extras/webhooks.py b/netbox/extras/webhooks.py index 18dcd0cfe..23702949a 100644 --- a/netbox/extras/webhooks.py +++ b/netbox/extras/webhooks.py @@ -6,6 +6,7 @@ from django.utils import timezone from django_rq import get_queue from netbox.config import get_config +from netbox.constants import RQ_QUEUE_DEFAULT from netbox.registry import registry from utilities.api import get_serializer_for_model from utilities.utils import serialize_object @@ -79,7 +80,7 @@ def flush_webhooks(queue): """ Flush a list of object representation to RQ for webhook processing. """ - rq_queue_name = get_config().QUEUE_MAPPINGS.get('webhook', 'default') + rq_queue_name = get_config().QUEUE_MAPPINGS.get('webhook', RQ_QUEUE_DEFAULT) rq_queue = get_queue(rq_queue_name) webhooks_cache = { 'type_create': {}, diff --git a/netbox/netbox/constants.py b/netbox/netbox/constants.py index c8054b3b0..0889f6a5c 100644 --- a/netbox/netbox/constants.py +++ b/netbox/netbox/constants.py @@ -1,2 +1,7 @@ # Prefix for nested serializers NESTED_SERIALIZER_PREFIX = 'Nested' + +# RQ queue names +RQ_QUEUE_DEFAULT = 'default' +RQ_QUEUE_HIGH = 'high' +RQ_QUEUE_LOW = 'low' diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index fb5b6ee10..a43e16ab3 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -17,6 +17,7 @@ from extras.plugins import PluginConfig from sentry_sdk.integrations.django import DjangoIntegration from netbox.config import PARAMS +from netbox.constants import RQ_QUEUE_DEFAULT, RQ_QUEUE_HIGH, RQ_QUEUE_LOW # @@ -640,9 +641,9 @@ else: } RQ_QUEUES = { - 'high': RQ_PARAMS, - 'default': RQ_PARAMS, - 'low': RQ_PARAMS, + RQ_QUEUE_HIGH: RQ_PARAMS, + RQ_QUEUE_DEFAULT: RQ_PARAMS, + RQ_QUEUE_LOW: RQ_PARAMS, } # Add any queues defined in QUEUE_MAPPINGS From 62b0f034e79bf23c7dcb2ba9dd9348aa7021c61c Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 8 Dec 2022 10:00:21 -0500 Subject: [PATCH 13/13] Changelog for #11022 --- docs/release-notes/version-3.4.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-3.4.md b/docs/release-notes/version-3.4.md index e52df0ef1..f1d4f2cdf 100644 --- a/docs/release-notes/version-3.4.md +++ b/docs/release-notes/version-3.4.md @@ -6,6 +6,7 @@ * [#815](https://github.com/netbox-community/netbox/issues/815) - Enable specifying terminations when bulk importing circuits * [#11090](https://github.com/netbox-community/netbox/issues/11090) - Add regular expression support to global search engine +* [#11022](https://github.com/netbox-community/netbox/issues/11022) - Introduce `QUEUE_MAPPINGS` configuration parameter to allow customization of background task prioritization ### Bug Fixes