From b6d756e6d4034b865a6ad881edf39996518818a8 Mon Sep 17 00:00:00 2001 From: Renato Almeida de Oliveira Date: Sat, 20 Jul 2024 19:04:01 +0000 Subject: [PATCH 1/3] NetBox v4.0.x support --- nb_service/__init__.py | 2 +- nb_service/api/views.py | 4 ++-- nb_service/{filters.py => filtersets.py} | 4 ++-- nb_service/forms.py | 5 ++--- nb_service/navigation.py | 2 +- nb_service/tests/application/test_filters.py | 4 ++-- nb_service/tests/service/test_filters.py | 4 ++-- nb_service/views.py | 12 ++++++------ 8 files changed, 18 insertions(+), 19 deletions(-) rename nb_service/{filters.py => filtersets.py} (97%) diff --git a/nb_service/__init__.py b/nb_service/__init__.py index cb9ea9e..226d35e 100644 --- a/nb_service/__init__.py +++ b/nb_service/__init__.py @@ -1,4 +1,4 @@ -from extras.plugins import PluginConfig +from netbox.plugins import PluginConfig from .version import __version__ diff --git a/nb_service/api/views.py b/nb_service/api/views.py index 129151b..6b63a7b 100644 --- a/nb_service/api/views.py +++ b/nb_service/api/views.py @@ -1,13 +1,13 @@ from netbox.api.viewsets import NetBoxModelViewSet from nb_service import models -from nb_service import filters +from nb_service import filtersets from . import serializers class ICViewSet(NetBoxModelViewSet): queryset = models.IC.objects.all() serializer_class = serializers.ICSerializer - filterset_class = filters.ICFilter + filterset_class = filtersets.ICFilter class ServiceViewSet(NetBoxModelViewSet): diff --git a/nb_service/filters.py b/nb_service/filtersets.py similarity index 97% rename from nb_service/filters.py rename to nb_service/filtersets.py index 454ed86..c86d5c0 100644 --- a/nb_service/filters.py +++ b/nb_service/filtersets.py @@ -42,7 +42,7 @@ class Meta: "service", ] -class ServiceFilter(NetBoxModelFilterSet): +class ServiceFilterSet(NetBoxModelFilterSet): q = django_filters.CharFilter( method="search", @@ -79,7 +79,7 @@ class Meta: "clients", ] -class ApplicationFilter(NetBoxModelFilterSet): +class ApplicationFilterSet(NetBoxModelFilterSet): q = django_filters.CharFilter( method="search", diff --git a/nb_service/forms.py b/nb_service/forms.py index 2bc65ed..8341160 100644 --- a/nb_service/forms.py +++ b/nb_service/forms.py @@ -7,7 +7,6 @@ from ipam.choices import ServiceProtocolChoices from ipam.constants import SERVICE_PORT_MIN, SERVICE_PORT_MAX from virtualization.models import VirtualMachine -from utilities.forms import BootstrapMixin from utilities.forms.fields import ( DynamicModelMultipleChoiceField, DynamicModelChoiceField, @@ -163,7 +162,7 @@ class Meta: ] -class ServiceFilterForm(BootstrapMixin, forms.ModelForm): +class ServiceFilterForm(forms.ModelForm): q = forms.CharField( required=False, @@ -216,7 +215,7 @@ class Meta: fields = ["name", "clients", "comments", "backup_profile"] -class ApplicationFilterForm(BootstrapMixin, forms.ModelForm): +class ApplicationFilterForm(forms.ModelForm): q = forms.CharField( required=False, diff --git a/nb_service/navigation.py b/nb_service/navigation.py index 04f99de..fddf5de 100644 --- a/nb_service/navigation.py +++ b/nb_service/navigation.py @@ -1,4 +1,4 @@ -from extras.plugins import PluginMenuItem +from netbox.plugins import PluginMenuItem menu_items = ( diff --git a/nb_service/tests/application/test_filters.py b/nb_service/tests/application/test_filters.py index e82e251..83892c5 100644 --- a/nb_service/tests/application/test_filters.py +++ b/nb_service/tests/application/test_filters.py @@ -6,12 +6,12 @@ from ipam.choices import ServiceProtocolChoices from nb_service.models import Application -from nb_service.filters import ApplicationFilter +from nb_service.filtersets import ApplicationFilterSet class ApplicationFilterTestCase(TestCase, ChangeLoggedFilterSetTests): queryset = Application.objects.all() - filterset = ApplicationFilter + filterset = ApplicationFilterSet @classmethod def setUpTestData(cls): diff --git a/nb_service/tests/service/test_filters.py b/nb_service/tests/service/test_filters.py index e59356e..84a4287 100644 --- a/nb_service/tests/service/test_filters.py +++ b/nb_service/tests/service/test_filters.py @@ -4,12 +4,12 @@ from utilities.testing import ChangeLoggedFilterSetTests from nb_service.models import Service -from nb_service.filters import ServiceFilter +from nb_service.filtersets import ServiceFilterSet class ServiceFilterTestCase(TestCase, ChangeLoggedFilterSetTests): queryset = Service.objects.all() - filterset = ServiceFilter + filterset = ServiceFilterSet @classmethod def setUpTestData(cls): diff --git a/nb_service/views.py b/nb_service/views.py index 358b255..19f1b07 100644 --- a/nb_service/views.py +++ b/nb_service/views.py @@ -1,5 +1,5 @@ from . import models -from . import filters +from . import filtersets from . import forms from . import tables @@ -17,7 +17,7 @@ class ServiceListView(generic.ObjectListView): queryset = models.Service.objects.all() table = tables.ServiceTable - filterset = filters.ServiceFilter + filterset = filtersets.ServiceFilterSet filterset_form = forms.ServiceFilterForm class ServiceView(generic.ObjectView): @@ -89,7 +89,7 @@ class ServiceImportView(generic.BulkImportView): class ServiceBulkEditView(generic.BulkEditView): queryset = models.Service.objects.all() - filterset = filters.ServiceFilter + filterset = filtersets.ServiceFilterSet table = tables.ServiceTable form = forms.ServiceBulkEditForm @@ -147,7 +147,7 @@ class ICDeleteView(generic.ObjectDeleteView): class ApplicationListView(generic.ObjectListView): queryset = models.Application.objects.all() table = tables.ApplicationTable - filterset = filters.ApplicationFilter + filterset = filtersets.ApplicationFilterSet filterset_form = forms.ApplicationFilterForm @@ -206,7 +206,7 @@ class ApplicationImportView(generic.BulkImportView): class ApplicationBulkEditView(generic.BulkEditView): queryset = models.Application.objects.all() - filterset = filters.ApplicationFilter + filterset = filtersets.ApplicationFilterSet table = tables.ApplicationTable form = forms.ApplicationBulkEditForm @@ -220,7 +220,7 @@ class ApplicationDeleteView(generic.ObjectDeleteView): class RelationListView(generic.ObjectListView): queryset = models.Relation.objects.all() table = tables.RelationTable - filterset = filters.RelationFilter + filterset = filtersets.RelationFilter filterset_form = forms.RelationFilterForm class RelationView(generic.ObjectView): From e841acbadf94883f483a593419cdda687deaa8a9 Mon Sep 17 00:00:00 2001 From: Renato Almeida de Oliveira Date: Sun, 21 Jul 2024 19:31:50 +0000 Subject: [PATCH 2/3] Fix tests --- nb_service/filtersets.py | 1 + nb_service/tests/application/test_api.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nb_service/filtersets.py b/nb_service/filtersets.py index c86d5c0..4596e33 100644 --- a/nb_service/filtersets.py +++ b/nb_service/filtersets.py @@ -77,6 +77,7 @@ class Meta: "id", "name", "clients", + "backup_profile", ] class ApplicationFilterSet(NetBoxModelFilterSet): diff --git a/nb_service/tests/application/test_api.py b/nb_service/tests/application/test_api.py index 3c889dc..27af9b6 100644 --- a/nb_service/tests/application/test_api.py +++ b/nb_service/tests/application/test_api.py @@ -63,4 +63,4 @@ def setUpTestData(cls): "devices": [devices[0].pk, devices[1].pk], } - cls.brief_fields = ['display', 'id', 'name'] + cls.brief_fields = ['devices', 'display', 'id', 'name', 'ports', 'protocol', 'version', 'vm'] From 5aeffd5c75bcf26f5c614cfe0a50c1f94140bd2c Mon Sep 17 00:00:00 2001 From: Renato Almeida de Oliveira Date: Sun, 21 Jul 2024 19:34:17 +0000 Subject: [PATCH 3/3] version update --- nb_service/__init__.py | 2 +- nb_service/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nb_service/__init__.py b/nb_service/__init__.py index 226d35e..0ea0121 100644 --- a/nb_service/__init__.py +++ b/nb_service/__init__.py @@ -10,7 +10,7 @@ class NbserviceConfig(PluginConfig): version = __version__ author = 'Renato Almeida de Oliveira' author_email = 'renato.almeida.oliveira@gmail.com' - min_version = "3.5.0" + min_version = "4.0.0" required_settings = [] default_settings = {} diff --git a/nb_service/version.py b/nb_service/version.py index 8c0d5d5..528787c 100644 --- a/nb_service/version.py +++ b/nb_service/version.py @@ -1 +1 @@ -__version__ = "2.0.0" +__version__ = "3.0.0"