From 9cbe3ff5517ee904cb97716d29c4f1686aabeee2 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 13 Apr 2021 11:46:14 -0400 Subject: [PATCH 1/5] Enable close-stale-issue action --- .github/workflows/stale.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 1cd85d867..8fc85ead6 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -1,4 +1,5 @@ -name: 'Close stale issues and PRs' +# close-stale-issues (https://github.com/marketplace/actions/close-stale-issues) +name: 'Close stale issues/PRs' on: schedule: - cron: '0 4 * * *' @@ -9,7 +10,6 @@ jobs: steps: - uses: actions/stale@v3 with: - debug-only: true close-issue-message: > This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the @@ -19,7 +19,7 @@ jobs: This PR has been automatically closed due to lack of activity. days-before-stale: 45 days-before-close: 15 - exempt-issue-labels: "status: accepted,status: blocked,status: needs milestone" + exempt-issue-labels: 'status: accepted,status: blocked,status: needs milestone' remove-stale-when-updated: false stale-issue-label: 'pending closure' stale-issue-message: > @@ -27,7 +27,7 @@ jobs: recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md). - stale-pr-label: "pending closure" + stale-pr-label: 'pending closure' stale-pr-message: > This PR has been automatically marked as stale because it has not had recent activity. It will be closed automatically if no further action is From d54bf5f75eef3b93ab0641a527576eed0a8eb7de Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 13 Apr 2021 11:52:32 -0400 Subject: [PATCH 2/5] Fixes #6144: Fix MAC address field display in VM interfaces search form --- docs/release-notes/version-2.10.md | 8 ++++++++ netbox/virtualization/forms.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index d2ce57484..2ea0b7bbf 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -1,5 +1,13 @@ # NetBox v2.10 +## v2.10.10 (FUTURE) + +### Bug Fixes + +* [#6144](https://github.com/netbox-community/netbox/issues/6144) - Fix MAC address field display in VM interfaces search form + +--- + ## v2.10.9 (2021-04-12) ### Enhancements diff --git a/netbox/virtualization/forms.py b/netbox/virtualization/forms.py index 20d0e4ad8..a3e6c4cf4 100644 --- a/netbox/virtualization/forms.py +++ b/netbox/virtualization/forms.py @@ -765,7 +765,7 @@ class VMInterfaceBulkRenameForm(BulkRenameForm): ) -class VMInterfaceFilterForm(forms.Form): +class VMInterfaceFilterForm(BootstrapMixin, forms.Form): model = VMInterface cluster_id = DynamicModelMultipleChoiceField( queryset=Cluster.objects.all(), From c249cd4ffd07d0d05f40f9bb1421ec76c2f5cae6 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 13 Apr 2021 12:05:44 -0400 Subject: [PATCH 3/5] Fixes #6152: Fix custom field filtering for cables, virtual chassis --- docs/release-notes/version-2.10.md | 1 + netbox/dcim/filters.py | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index 2ea0b7bbf..974eb00b0 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -5,6 +5,7 @@ ### Bug Fixes * [#6144](https://github.com/netbox-community/netbox/issues/6144) - Fix MAC address field display in VM interfaces search form +* [#6152](https://github.com/netbox-community/netbox/issues/6152) - Fix custom field filtering for cables, virtual chassis --- diff --git a/netbox/dcim/filters.py b/netbox/dcim/filters.py index 9c8a8a79a..dff552910 100644 --- a/netbox/dcim/filters.py +++ b/netbox/dcim/filters.py @@ -1,6 +1,5 @@ import django_filters from django.contrib.auth.models import User -from django.db.models import Count from extras.filters import CustomFieldModelFilterSet, LocalConfigContextFilterSet, CreatedUpdatedFilterSet from tenancy.filters import TenancyFilterSet @@ -1011,7 +1010,7 @@ class InventoryItemFilterSet(BaseFilterSet, DeviceComponentFilterSet): return queryset.filter(qs_filter) -class VirtualChassisFilterSet(BaseFilterSet): +class VirtualChassisFilterSet(BaseFilterSet, CustomFieldModelFilterSet): q = django_filters.CharFilter( method='search', label='Search', @@ -1078,7 +1077,7 @@ class VirtualChassisFilterSet(BaseFilterSet): return queryset.filter(qs_filter).distinct() -class CableFilterSet(BaseFilterSet): +class CableFilterSet(BaseFilterSet, CustomFieldModelFilterSet): q = django_filters.CharFilter( method='search', label='Search', From 1fba4b7e32f18e643f6483068062c71a2019c807 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 13 Apr 2021 13:23:25 -0400 Subject: [PATCH 4/5] Fixes #5419: Update parent device/VM when deleting a primary IP --- docs/release-notes/version-2.10.md | 1 + netbox/ipam/apps.py | 3 +++ netbox/ipam/signals.py | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 netbox/ipam/signals.py diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index 974eb00b0..2675bac5f 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -4,6 +4,7 @@ ### Bug Fixes +* [#5419](https://github.com/netbox-community/netbox/issues/5419) - Update parent device/VM when deleting a primary IP * [#6144](https://github.com/netbox-community/netbox/issues/6144) - Fix MAC address field display in VM interfaces search form * [#6152](https://github.com/netbox-community/netbox/issues/6152) - Fix custom field filtering for cables, virtual chassis diff --git a/netbox/ipam/apps.py b/netbox/ipam/apps.py index fd4af74b0..413c8c1bc 100644 --- a/netbox/ipam/apps.py +++ b/netbox/ipam/apps.py @@ -4,3 +4,6 @@ from django.apps import AppConfig class IPAMConfig(AppConfig): name = "ipam" verbose_name = "IPAM" + + def ready(self): + import ipam.signals diff --git a/netbox/ipam/signals.py b/netbox/ipam/signals.py new file mode 100644 index 000000000..a8fce8310 --- /dev/null +++ b/netbox/ipam/signals.py @@ -0,0 +1,21 @@ +from django.db.models.signals import pre_delete +from django.dispatch import receiver + +from dcim.models import Device +from virtualization.models import VirtualMachine +from .models import IPAddress + + +@receiver(pre_delete, sender=IPAddress) +def clear_primary_ip(instance, **kwargs): + """ + When an IPAddress is deleted, trigger save() on any Devices/VirtualMachines for which it + was a primary IP. + """ + field_name = f'primary_ip{instance.family}' + device = Device.objects.filter(**{field_name: instance}).first() + if device: + device.save() + virtualmachine = VirtualMachine.objects.filter(**{field_name: instance}).first() + if virtualmachine: + virtualmachine.save() From cc433388f5811823913bcf0e310d0af3f05a710d Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 13 Apr 2021 13:48:22 -0400 Subject: [PATCH 5/5] Fixes #6056: Optimize change log cleanup --- docs/release-notes/version-2.10.md | 1 + netbox/extras/signals.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/version-2.10.md b/docs/release-notes/version-2.10.md index 2675bac5f..69db03724 100644 --- a/docs/release-notes/version-2.10.md +++ b/docs/release-notes/version-2.10.md @@ -5,6 +5,7 @@ ### Bug Fixes * [#5419](https://github.com/netbox-community/netbox/issues/5419) - Update parent device/VM when deleting a primary IP +* [#6056](https://github.com/netbox-community/netbox/issues/6056) - Optimize change log cleanup * [#6144](https://github.com/netbox-community/netbox/issues/6144) - Fix MAC address field display in VM interfaces search form * [#6152](https://github.com/netbox-community/netbox/issues/6152) - Fix custom field filtering for cables, virtual chassis diff --git a/netbox/extras/signals.py b/netbox/extras/signals.py index 0d6295e5b..9eeb4ce45 100644 --- a/netbox/extras/signals.py +++ b/netbox/extras/signals.py @@ -4,6 +4,7 @@ from datetime import timedelta from cacheops.signals import cache_invalidated, cache_read from django.conf import settings from django.contrib.contenttypes.models import ContentType +from django.db import DEFAULT_DB_ALIAS from django.db.models.signals import m2m_changed, pre_delete from django.utils import timezone from django_prometheus.models import model_deletes, model_inserts, model_updates @@ -52,7 +53,7 @@ def _handle_changed_object(request, sender, instance, **kwargs): # Housekeeping: 0.1% chance of clearing out expired ObjectChanges if settings.CHANGELOG_RETENTION and random.randint(1, 1000) == 1: cutoff = timezone.now() - timedelta(days=settings.CHANGELOG_RETENTION) - ObjectChange.objects.filter(time__lt=cutoff).delete() + ObjectChange.objects.filter(time__lt=cutoff)._raw_delete(using=DEFAULT_DB_ALIAS) def _handle_deleted_object(request, sender, instance, **kwargs):