From 81e603894553be436d1378ad249c7e3fd3715bc6 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:22:10 +0000 Subject: [PATCH 01/11] [skip ci] Updated CHANGELOG.md --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 407c990..46f2ee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## [Unreleased](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/tree/HEAD) + +[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/compare/v0.2.2...HEAD) + +**Closed issues:** + +- Form Invalid When Importing Data Types via API Due to Missing "\_init\_time" Field [\#43](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/issues/43) + +**Merged pull requests:** + +- Release v0.3.2 [\#46](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/pull/46) ([kprince28](https://github.com/kprince28)) +- Add the \_init\_time in the form data [\#44](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/pull/44) ([kprince28](https://github.com/kprince28)) + +## [v0.2.2](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/tree/v0.2.2) (2024-03-11) + +[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/compare/v0.3.1...v0.2.2) + ## [v0.3.1](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/tree/v0.3.1) (2024-03-11) [Full Changelog](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/compare/v0.2.1...v0.3.1) From 144c3ece7c7ab6e89b2e5e39ad6c4fef10bc0093 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Tue, 12 Mar 2024 11:32:42 +0530 Subject: [PATCH 02/11] test cases added #39 --- netbox_metatype_importer/api/views.py | 19 ++++----- netbox_metatype_importer/tests/__init__.py | 0 .../tests/test_filtersets.py | 41 +++++++++++++++++++ netbox_metatype_importer/tests/test_models.py | 28 +++++++++++++ netbox_metatype_importer/utils.py | 35 ++++++++-------- 5 files changed, 94 insertions(+), 29 deletions(-) create mode 100644 netbox_metatype_importer/tests/__init__.py create mode 100644 netbox_metatype_importer/tests/test_filtersets.py create mode 100644 netbox_metatype_importer/tests/test_models.py diff --git a/netbox_metatype_importer/api/views.py b/netbox_metatype_importer/api/views.py index bc97436..b999ec2 100644 --- a/netbox_metatype_importer/api/views.py +++ b/netbox_metatype_importer/api/views.py @@ -58,11 +58,7 @@ def create(self, request, *args, **kwargs): try: loaded, created, updated = load_data(self.type_choice) - response_data = { - 'loaded': loaded, - 'created': created, - 'updated': updated - } + response_data = {'loaded': loaded, 'created': created, 'updated': updated} return Response(response_data, status=status.HTTP_200_OK) except Exception as e: return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) @@ -122,7 +118,7 @@ def create(self, request, *args, **kwargs): _mdt.save() vendors_for_cre = set(model.objects.filter(pk__in=pk_list).values_list('vendor', flat=True).distinct()) for vendor, name, sha in model.objects.filter(pk__in=pk_list, is_imported=False).values_list( - 'vendor', 'name', 'sha' + 'vendor', 'name', 'sha' ): query_data[sha] = f'{vendor}/{name}' if not query_data: @@ -192,13 +188,16 @@ def create(self, request, *args, **kwargs): if imported_dt: if errored: - return Response({'message': f'Imported: {len(imported_dt)}, Failed: {errored}'}, - status=status.HTTP_206_PARTIAL_CONTENT) + return Response( + {'message': f'Imported: {len(imported_dt)}, Failed: {errored}'}, + status=status.HTTP_206_PARTIAL_CONTENT, + ) else: qparams = urlencode({'id': imported_dt}, doseq=True) url = reverse(f'dcim:{str(self.type).replace("-", "").rstrip("s")}_list') + '?' + qparams - return Response({'message': f'Imported: {len(imported_dt)}', 'url': url}, - status=status.HTTP_201_CREATED) + return Response( + {'message': f'Imported: {len(imported_dt)}', 'url': url}, status=status.HTTP_201_CREATED + ) else: return Response({'error': f'Can not import {self.type}'}, status=status.HTTP_400_BAD_REQUEST) diff --git a/netbox_metatype_importer/tests/__init__.py b/netbox_metatype_importer/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/netbox_metatype_importer/tests/test_filtersets.py b/netbox_metatype_importer/tests/test_filtersets.py new file mode 100644 index 0000000..133336c --- /dev/null +++ b/netbox_metatype_importer/tests/test_filtersets.py @@ -0,0 +1,41 @@ +from django.test import TestCase + +from ..filters import * +from ..models import * + +class MetatypeImporterTests(TestCase): + queryset = MetaType.objects.all() + filterset = MetaTypeFilterSet + + @classmethod + def setUpTestData(cls): + meta_types = ( + MetaType( + name='Test Metatype 1', + vendor='Test Vendor 1', + type=TypeChoices.TYPE_DEVICE, + sha='sha256', + download_url='https://www.testurl1.com/', + is_new=False, + imported_dt=1, + is_imported=True, + ), + MetaType( + name='Test Metatype 2', + vendor='Test Vendor 2', + type=TypeChoices.TYPE_DEVICE, + sha='sha256', + download_url='https://www.testurl2.com/', + is_new=False, + imported_dt=2, + is_imported=True, + ), + ) + MetaType.objects.bulk_create(meta_types) + + def test_meta_types(self): + meta_types = MetaType.objects.all()[:2] + params = {"name": 'Test Metatype 1'} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) + params = {"vendor": meta_types[0].vendor} + self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1) diff --git a/netbox_metatype_importer/tests/test_models.py b/netbox_metatype_importer/tests/test_models.py new file mode 100644 index 0000000..8917d50 --- /dev/null +++ b/netbox_metatype_importer/tests/test_models.py @@ -0,0 +1,28 @@ +from django.test import TestCase + +from ..models import * +from ..choices import * + + +class TestMetaTypeImporter(TestCase): + def test_metatype_creation(self): + metatype = MetaType.objects.create( + name='Test Metatype', + vendor='Test Vendor', + type=TypeChoices.TYPE_DEVICE, + sha='sha256', + download_url='https://www.testurl.com/', + is_new=False, + imported_dt=1, + is_imported=True, + ) + + self.assertEqual(metatype.__str__(), 'Test Metatype') + self.assertEqual(metatype.name, 'Test Metatype') + self.assertEqual(metatype.vendor, 'Test Vendor') + self.assertEqual(metatype.type, TypeChoices.TYPE_DEVICE) + self.assertEqual(metatype.sha, 'sha256') + self.assertEqual(metatype.download_url, 'https://www.testurl.com/') + self.assertEqual(metatype.is_new, False) + self.assertEqual(metatype.imported_dt, 1) + self.assertEqual(metatype.is_imported, True) \ No newline at end of file diff --git a/netbox_metatype_importer/utils.py b/netbox_metatype_importer/utils.py index fc6614a..b88eb54 100644 --- a/netbox_metatype_importer/utils.py +++ b/netbox_metatype_importer/utils.py @@ -38,28 +38,25 @@ def load_data(type_choice): meta_type.save() continue except ObjectDoesNotExist: - MetaType.objects.create( - vendor=vendor, - name=model, - sha=model_data['sha'], - type=type_choice - ) + MetaType.objects.create(vendor=vendor, name=model, sha=model_data['sha'], type=type_choice) created += 1 return loaded, created, updated def related_object_forms(): - return OrderedDict(( - ('console-ports', forms.ConsolePortTemplateImportForm), - ('console-server-ports', forms.ConsoleServerPortTemplateImportForm), - ('power-ports', forms.PowerPortTemplateImportForm), - ('power-outlets', forms.PowerOutletTemplateImportForm), - ('interfaces', forms.InterfaceTemplateImportForm), - ('rear-ports', forms.RearPortTemplateImportForm), - ('front-ports', forms.FrontPortTemplateImportForm), - ('device-bays', forms.DeviceBayTemplateImportForm), - ('inventory-items', forms.InventoryItemTemplateImportForm), - ('module-bays', forms.ModuleBayTemplateImportForm), - ('device-bays', forms.DeviceBayTemplateImportForm) - )) + return OrderedDict( + ( + ('console-ports', forms.ConsolePortTemplateImportForm), + ('console-server-ports', forms.ConsoleServerPortTemplateImportForm), + ('power-ports', forms.PowerPortTemplateImportForm), + ('power-outlets', forms.PowerOutletTemplateImportForm), + ('interfaces', forms.InterfaceTemplateImportForm), + ('rear-ports', forms.RearPortTemplateImportForm), + ('front-ports', forms.FrontPortTemplateImportForm), + ('device-bays', forms.DeviceBayTemplateImportForm), + ('inventory-items', forms.InventoryItemTemplateImportForm), + ('module-bays', forms.ModuleBayTemplateImportForm), + ('device-bays', forms.DeviceBayTemplateImportForm), + ) + ) From d7c718b9e256b54d1cdd4fa4f3d46fd93ade7561 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Tue, 12 Mar 2024 11:33:05 +0530 Subject: [PATCH 03/11] lint fix #39 --- netbox_metatype_importer/tests/test_filtersets.py | 1 + netbox_metatype_importer/tests/test_models.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox_metatype_importer/tests/test_filtersets.py b/netbox_metatype_importer/tests/test_filtersets.py index 133336c..5273e37 100644 --- a/netbox_metatype_importer/tests/test_filtersets.py +++ b/netbox_metatype_importer/tests/test_filtersets.py @@ -3,6 +3,7 @@ from ..filters import * from ..models import * + class MetatypeImporterTests(TestCase): queryset = MetaType.objects.all() filterset = MetaTypeFilterSet diff --git a/netbox_metatype_importer/tests/test_models.py b/netbox_metatype_importer/tests/test_models.py index 8917d50..c4677df 100644 --- a/netbox_metatype_importer/tests/test_models.py +++ b/netbox_metatype_importer/tests/test_models.py @@ -25,4 +25,4 @@ def test_metatype_creation(self): self.assertEqual(metatype.download_url, 'https://www.testurl.com/') self.assertEqual(metatype.is_new, False) self.assertEqual(metatype.imported_dt, 1) - self.assertEqual(metatype.is_imported, True) \ No newline at end of file + self.assertEqual(metatype.is_imported, True) From 97e388e26ff33d1847c5590cd0f4cb5af8fe3194 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:29:38 +0000 Subject: [PATCH 04/11] [skip ci] Updated CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46f2ee5..b42fa21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,16 @@ ## [Unreleased](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/tree/HEAD) -[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/compare/v0.2.2...HEAD) +[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/compare/v0.3.2...HEAD) **Closed issues:** - Form Invalid When Importing Data Types via API Due to Missing "\_init\_time" Field [\#43](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/issues/43) +## [v0.3.2](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/tree/v0.3.2) (2024-03-11) + +[Full Changelog](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/compare/v0.2.2...v0.3.2) + **Merged pull requests:** - Release v0.3.2 [\#46](https://github.com/Onemind-Services-LLC/netbox-metatype-importer/pull/46) ([kprince28](https://github.com/kprince28)) From 1690cab1484d132b710265df534d6e6589f0876f Mon Sep 17 00:00:00 2001 From: Prince Kumar Date: Wed, 27 Mar 2024 10:40:51 +0530 Subject: [PATCH 05/11] update GitHub CI, and templates --- .github/labels.toml | 119 ------------------------------------ .github/release-drafter.yml | 43 ------------- 2 files changed, 162 deletions(-) delete mode 100644 .github/labels.toml delete mode 100644 .github/release-drafter.yml diff --git a/.github/labels.toml b/.github/labels.toml deleted file mode 100644 index b063e45..0000000 --- a/.github/labels.toml +++ /dev/null @@ -1,119 +0,0 @@ -["type: performance"] -color = "6572A4" -name = "type: performance" -description = "" - -["status: abandoned"] -color = "fc9580" -name = "status: abandoned" -description = "It's believed that this issue is no longer important to the requestor and no one else has shown an i" - -["status: accepted"] -color = "d66039" -name = "status: accepted" -description = "It's clear what the subject of the issue is about, and what the resolution should be." - -["status: available"] -color = "fcefa6" -name = "status: available" -description = "No one has claimed responsibility for resolving this issue." - -["status: blocked"] -color = "ffcc9e" -name = "status: blocked" -description = "There is another issue that needs to be resolved first, or a specific person is required to comment" - -["status: completed"] -color = "250077" -name = "status: completed" -description = "Nothing further to be done with this issue." - -["status: in progress"] -color = "f4c9a1" -name = "status: in progress" -description = "This issue is being worked on" - -["status: on hold"] -color = "c8a2f9" -name = "status: on hold" -description = "Similar to blocked, but is assigned to someone" - -["status: review needed"] -color = "e99695" -name = "status: review needed" -description = "The issue has a PR attached to it which needs to be reviewed." - -["type: breaking"] -color = "d6a30c" -name = "type: breaking" -description = "" - -["type: bug"] -color = "d73a4a" -name = "type: bug" -description = "Something isn't working" - -["type: dependencies"] -color = "0366d6" -name = "type: dependencies" -description = "Pull requests that update a dependency file" - -["type: deprecated"] -color = "2e0baa" -name = "type: deprecated" -description = "" - -["type: docs"] -color = "0075ca" -name = "type: docs" -description = "Improvements or additions to documentation" - -["type: duplicate"] -color = "cfd3d7" -name = "type: duplicate" -description = "This issue or pull request already exists" - -["type: feature"] -color = "a2eeef" -name = "type: feature" -description = "New feature or request" - -["type: help wanted"] -color = "008672" -name = "type: help wanted" -description = "Extra attention is needed" - -["type: invalid"] -color = "e4e669" -name = "type: invalid" -description = "This doesn't seem right" - -["type: maintenance"] -color = "c2e0c6" -name = "type: maintenance" -description = "" - -["type: question"] -color = "d876e3" -name = "type: question" -description = "Further information is requested" - -["type: security"] -color = "7dede7" -name = "type: security" -description = "Pull requests that address a security vulnerability" - -["type: tests"] -color = "F25F44" -name = "type: tests" -description = "" - -["type: wontfix"] -color = "ffffff" -name = "type: wontfix" -description = "This will not be worked on" - -["type: ui/ux"] -color = "5319E7" -name = "type: ui/ux" -description = "UI/UX design" diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index ea64bec..0000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,43 +0,0 @@ -name-template: "v$RESOLVED_VERSION" -tag-template: "v$RESOLVED_VERSION" -template: | - # What's Changed - $CHANGES -categories: - - title: "Breaking" - label: "type: breaking" - - title: "UI" - label: "type: ui/ux" - - title: "New" - label: "type: feature" - - title: "Security" - label: "type: security" - - title: "Bug Fixes" - label: "type: bug" - - title: "Testing" - label: "type: tests" - - title: "Maintenance" - label: "type: maintenance" - - title: "Performance Improvement" - label: "type: performance" - - title: "Documentation" - label: "type: docs" - - title: "Dependency Updates" - label: "type: dependencies" - -version-resolver: - major: - labels: - - "type: breaking" - minor: - labels: - - "type: feature" - patch: - labels: - - "type: bug" - - "type: maintenance" - - "type: docs" - - "type: dependencies" - - "type: security" - - "type: tests" - - "type: performance" From 414527c2e7705cf792bf4ea57d9b550649035402 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Mon, 3 Jun 2024 15:00:27 +0530 Subject: [PATCH 06/11] NB-17 support added for netbox v4 --- Dockerfile | 2 +- README.md | 1 + docker-compose.yml | 2 -- netbox_metatype_importer/__init__.py | 6 +++--- netbox_metatype_importer/api/serializers.py | 5 ++++- netbox_metatype_importer/api/urls.py | 16 ++++++++-------- netbox_metatype_importer/api/views.py | 2 +- netbox_metatype_importer/forms.py | 3 +-- netbox_metatype_importer/graphql/__init__.py | 0 netbox_metatype_importer/{ => graphql}/gql.py | 0 netbox_metatype_importer/navigation.py | 2 +- netbox_metatype_importer/utils.py | 2 +- netbox_metatype_importer/views.py | 4 +--- setup.py | 2 +- 14 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 netbox_metatype_importer/graphql/__init__.py rename netbox_metatype_importer/{ => graphql}/gql.py (100%) diff --git a/Dockerfile b/Dockerfile index 7fce067..2d858db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG NETBOX_VARIANT=v3.7 +ARG NETBOX_VARIANT=v4.0 FROM netboxcommunity/netbox:${NETBOX_VARIANT} diff --git a/README.md b/README.md index 8018e14..6e9c730 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ To use GraphQL API you need to set GitHub personal access token in plugin settin | 3.5.x | 0.1.x | | 3.6.x | 0.2.x | | 3.7.x | 0.3.x | +| 4.0.x | 0.4.x | ## Installation diff --git a/docker-compose.yml b/docker-compose.yml index 4a1024e..b66dc46 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.4' - services: netbox: build: diff --git a/netbox_metatype_importer/__init__.py b/netbox_metatype_importer/__init__.py index e4d8bc3..29ed146 100644 --- a/netbox_metatype_importer/__init__.py +++ b/netbox_metatype_importer/__init__.py @@ -1,6 +1,6 @@ from importlib.metadata import metadata -from extras.plugins import PluginConfig +from netbox.plugins import PluginConfig metadata = metadata('netbox_metatype_importer') @@ -13,8 +13,8 @@ class NetBoxMetatypeImporterConfig(PluginConfig): author = metadata.get('Author') author_email = metadata.get('Author-email') base_url = "meta-types" - min_version = '3.7.0' - max_version = '3.7.99' + min_version = '4.0.0' + max_version = '4.0.99' default_settings = { 'repo_owner': 'netbox-community', 'repo': 'devicetype-library', diff --git a/netbox_metatype_importer/api/serializers.py b/netbox_metatype_importer/api/serializers.py index 97e1405..504efc4 100644 --- a/netbox_metatype_importer/api/serializers.py +++ b/netbox_metatype_importer/api/serializers.py @@ -1,9 +1,12 @@ from rest_framework import serializers +from rest_framework.serializers import HyperlinkedIdentityField -from ..models import MetaType +from netbox_metatype_importer.models import MetaType class MetaTypeSerializer(serializers.ModelSerializer): + url = HyperlinkedIdentityField(view_name="plugins-api:netbox_metatype_importer-api:metatype-detail") class Meta: model = MetaType fields = "__all__" + brief_fields = ("id", "url", "display", "name", "description") diff --git a/netbox_metatype_importer/api/urls.py b/netbox_metatype_importer/api/urls.py index 8bd075c..a7eb57d 100644 --- a/netbox_metatype_importer/api/urls.py +++ b/netbox_metatype_importer/api/urls.py @@ -1,17 +1,17 @@ from netbox.api.routers import NetBoxRouter -from . import views +from .views import DeviceTypeListViewSet, ModuleTypeListViewSet, MetaDeviceTypeLoadViewSet, MetaModuleTypeLoadViewSet, MetaDeviceTypeImportViewSet, MetaModuleTypeImportViewSet, MetaTypeRootView router = NetBoxRouter() -router.APIRootView = views.MetaTypeRootView +router.APIRootView = MetaTypeRootView -router.register('device-types', views.DeviceTypeListViewSet, basename='device-types') -router.register('module-types', views.ModuleTypeListViewSet, basename="module-types") +router.register('device-types', DeviceTypeListViewSet, basename='device-types') +router.register('module-types', ModuleTypeListViewSet, basename="module-types") -router.register('device-type-load', views.MetaDeviceTypeLoadViewSet, basename='device-type-load') -router.register('module-type-load', views.MetaModuleTypeLoadViewSet, basename="module-type-load") +router.register('device-type-load', MetaDeviceTypeLoadViewSet, basename='device-type-load') +router.register('module-type-load', MetaModuleTypeLoadViewSet, basename="module-type-load") -router.register('device-type-import', views.MetaDeviceTypeImportViewSet, basename='device-type-import') -router.register('module-type-import', views.MetaModuleTypeImportViewSet, basename="module-type-import") +router.register('device-type-import', MetaDeviceTypeImportViewSet, basename='device-type-import') +router.register('module-type-import', MetaModuleTypeImportViewSet, basename="module-type-import") urlpatterns = router.urls diff --git a/netbox_metatype_importer/api/views.py b/netbox_metatype_importer/api/views.py index 08581dd..e138af7 100644 --- a/netbox_metatype_importer/api/views.py +++ b/netbox_metatype_importer/api/views.py @@ -19,7 +19,7 @@ from utilities.forms.bulk_import import BulkImportForm from . import serializers from ..choices import TypeChoices -from ..gql import GQLError, GitHubGqlAPI +from netbox_metatype_importer.graphql.gql import GQLError, GitHubGqlAPI from ..models import MetaType from ..utils import * diff --git a/netbox_metatype_importer/forms.py b/netbox_metatype_importer/forms.py index 21aee21..61e695e 100644 --- a/netbox_metatype_importer/forms.py +++ b/netbox_metatype_importer/forms.py @@ -1,10 +1,9 @@ from django import forms -from utilities.forms import BootstrapMixin from .models import MetaType -class MetaTypeFilterForm(BootstrapMixin, forms.Form): +class MetaTypeFilterForm(forms.Form): q = forms.CharField(required=False, label='Name') vendor = forms.CharField(required=False, label='Vendor') diff --git a/netbox_metatype_importer/graphql/__init__.py b/netbox_metatype_importer/graphql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/netbox_metatype_importer/gql.py b/netbox_metatype_importer/graphql/gql.py similarity index 100% rename from netbox_metatype_importer/gql.py rename to netbox_metatype_importer/graphql/gql.py diff --git a/netbox_metatype_importer/navigation.py b/netbox_metatype_importer/navigation.py index 91ad936..484c94a 100644 --- a/netbox_metatype_importer/navigation.py +++ b/netbox_metatype_importer/navigation.py @@ -1,4 +1,4 @@ -from extras.plugins import PluginMenuItem +from netbox.plugins import PluginMenuItem menu_items = ( PluginMenuItem( diff --git a/netbox_metatype_importer/utils.py b/netbox_metatype_importer/utils.py index b88eb54..6b9ce93 100644 --- a/netbox_metatype_importer/utils.py +++ b/netbox_metatype_importer/utils.py @@ -4,7 +4,7 @@ from django.core.exceptions import ObjectDoesNotExist from dcim import forms -from .gql import GitHubGqlAPI, GQLError +from netbox_metatype_importer.graphql.gql import GitHubGqlAPI, GQLError from .models import MetaType __all__ = ['load_data', 'related_object_forms'] diff --git a/netbox_metatype_importer/views.py b/netbox_metatype_importer/views.py index 2ecc3aa..d0c2519 100644 --- a/netbox_metatype_importer/views.py +++ b/netbox_metatype_importer/views.py @@ -1,9 +1,7 @@ -from collections import OrderedDict from urllib.parse import urlencode from django.conf import settings from django.contrib import messages -from django.core.exceptions import ObjectDoesNotExist from django.db import transaction from django.http import HttpResponseForbidden from django.shortcuts import redirect, reverse @@ -19,7 +17,7 @@ from .choices import TypeChoices from .filters import MetaTypeFilterSet from .forms import MetaTypeFilterForm -from .gql import GQLError, GitHubGqlAPI +from netbox_metatype_importer.graphql.gql import GQLError, GitHubGqlAPI from .models import MetaType from .tables import MetaTypeTable from .utils import * diff --git a/setup.py b/setup.py index e5c874a..a4b1a7e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='netbox-metatype-importer', - version='0.3.2', + version='0.4.0', description='Easily import Device and Module types from GitHub repo', long_description='Import MetaTypes into NetBox', long_description_content_type="text/markdown", From b8d323c2285d2510e015bbf7649e7658fe32c63f Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Mon, 3 Jun 2024 15:00:44 +0530 Subject: [PATCH 07/11] NB-17 lint fix --- netbox_metatype_importer/api/serializers.py | 1 + netbox_metatype_importer/api/urls.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/netbox_metatype_importer/api/serializers.py b/netbox_metatype_importer/api/serializers.py index 504efc4..3a9240f 100644 --- a/netbox_metatype_importer/api/serializers.py +++ b/netbox_metatype_importer/api/serializers.py @@ -6,6 +6,7 @@ class MetaTypeSerializer(serializers.ModelSerializer): url = HyperlinkedIdentityField(view_name="plugins-api:netbox_metatype_importer-api:metatype-detail") + class Meta: model = MetaType fields = "__all__" diff --git a/netbox_metatype_importer/api/urls.py b/netbox_metatype_importer/api/urls.py index a7eb57d..f41c657 100644 --- a/netbox_metatype_importer/api/urls.py +++ b/netbox_metatype_importer/api/urls.py @@ -1,6 +1,14 @@ from netbox.api.routers import NetBoxRouter -from .views import DeviceTypeListViewSet, ModuleTypeListViewSet, MetaDeviceTypeLoadViewSet, MetaModuleTypeLoadViewSet, MetaDeviceTypeImportViewSet, MetaModuleTypeImportViewSet, MetaTypeRootView +from .views import ( + DeviceTypeListViewSet, + ModuleTypeListViewSet, + MetaDeviceTypeLoadViewSet, + MetaModuleTypeLoadViewSet, + MetaDeviceTypeImportViewSet, + MetaModuleTypeImportViewSet, + MetaTypeRootView, +) router = NetBoxRouter() router.APIRootView = MetaTypeRootView From d6a75a91105930f4513d08b4c4b7f3d8a6bb2832 Mon Sep 17 00:00:00 2001 From: yash-pal1 Date: Mon, 3 Jun 2024 16:12:32 +0530 Subject: [PATCH 08/11] NB-17 workflow fix --- .github/ISSUE_TEMPLATE/1-bug-report.yml | 50 ---------------- .github/ISSUE_TEMPLATE/2-feature-request.yml | 57 ------------------- .../ISSUE_TEMPLATE/3-documentation-change.yml | 37 ------------ .github/ISSUE_TEMPLATE/4-housekeeping.yml | 25 -------- .github/ISSUE_TEMPLATE/5-deprecation.yml | 34 ----------- .github/workflows/ci.yml | 47 +++++++++++++-- 6 files changed, 43 insertions(+), 207 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/1-bug-report.yml delete mode 100644 .github/ISSUE_TEMPLATE/2-feature-request.yml delete mode 100644 .github/ISSUE_TEMPLATE/3-documentation-change.yml delete mode 100644 .github/ISSUE_TEMPLATE/4-housekeeping.yml delete mode 100644 .github/ISSUE_TEMPLATE/5-deprecation.yml diff --git a/.github/ISSUE_TEMPLATE/1-bug-report.yml b/.github/ISSUE_TEMPLATE/1-bug-report.yml deleted file mode 100644 index 279f3a9..0000000 --- a/.github/ISSUE_TEMPLATE/1-bug-report.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- -name: 🐞 Bug Report -description: Report a Reproducible Bug in the Current Release of this NetBox Plugin -labels: [ "type: bug" ] -assignees: "kprince28" -body: - - type: markdown - attributes: - value: > - **Note:** This form is exclusively for reporting _reproducible bugs_ in the current NetBox plugin installation. - - - type: input - attributes: - label: NetBox Version - description: Indicate the version of NetBox you are currently running. - placeholder: v3.6.9 - validations: - required: true - - - type: input - attributes: - label: NetBox Plugin Version - description: Please specify the version of the NetBox plugin you are currently using. - placeholder: v0.2.0 - validations: - required: true - - - type: textarea - attributes: - label: Steps to Reproduce - description: > - When submitting a bug report for the NetBox plugin, it's essential to provide comprehensive step-by-step instructions for reproducing the issue on a clean, empty NetBox installation. These instructions should be clear enough for someone else to follow effortlessly and must encompass the creation of any necessary objects, configuration changes, and a complete accounting of the actions being taken. Remember, the goal is to ensure that the problem can be replicated precisely using the current stable release of the NetBox plugin. - validations: - required: true - - - type: textarea - attributes: - label: Expected Behavior - description: Describe what you expected to happen. - placeholder: A new widget should have been created with the specified attributes. - validations: - required: true - - - type: textarea - attributes: - label: Observed Behavior - description: Describe what actually happened. - placeholder: A TypeError exception was raised - validations: - required: true diff --git a/.github/ISSUE_TEMPLATE/2-feature-request.yml b/.github/ISSUE_TEMPLATE/2-feature-request.yml deleted file mode 100644 index 68e1840..0000000 --- a/.github/ISSUE_TEMPLATE/2-feature-request.yml +++ /dev/null @@ -1,57 +0,0 @@ ---- -name: ✨ Feature Request -description: Propose a new feature or enhancement -labels: [ "type: feature" ] -assignees: "kprince28" -body: - - type: markdown - attributes: - value: > - **NOTE:** This form is exclusively for submitting well-considered proposals to expand or refine - NetBox Plugin's functionality. If you're grappling with a problem or still refining your feature idea, - please initiate a discussion instead. - - - type: input - attributes: - label: Current NetBox Version - description: What version of NetBox are you currently running? - placeholder: v3.6.9 - validations: - required: true - - - type: dropdown - attributes: - label: Feature Type - options: - - New Model for Plugin - - Modification to Existing Model - - Addition of a Function - - Removal of a Function - validations: - required: true - - - type: textarea - attributes: - label: Proposed Functionality - description: > - Provide a comprehensive description of the new feature or behavior you are suggesting. Include specific changes - to workflows, data models, and dependencies. The more detailed your proposal, the higher the chance it will be discussed. - Feature requests without a clear implementation plan may be declined. - validations: - required: true - - - type: textarea - attributes: - label: Use Case - description: > - Explain how implementing this functionality would benefit NetBox users, particularly within this plugin's context. - What problem does it address? - validations: - required: true - - - type: textarea - attributes: - label: External Dependencies - description: > - Enumerate any new external libraries or services that this feature would necessitate. - For example, does it require installing a new Python package? (Not all new features introduce dependencies.) diff --git a/.github/ISSUE_TEMPLATE/3-documentation-change.yml b/.github/ISSUE_TEMPLATE/3-documentation-change.yml deleted file mode 100644 index 4a60358..0000000 --- a/.github/ISSUE_TEMPLATE/3-documentation-change.yml +++ /dev/null @@ -1,37 +0,0 @@ ---- -name: 📖 Documentation Enhancement -description: Suggest an enhancement, addition, or modification to the NetBox plugin documentation. -labels: [ "type: docs" ] -assignees: "kprince28" -body: - - type: dropdown - attributes: - label: Change Type - description: Specify the nature of your documentation change. - options: - - Addition - - Correction - - Removal - - Cleanup (formatting, typos, etc.) - validations: - required: true - - - type: dropdown - attributes: - label: Documentation Section - description: Indicate the section of the documentation that this change primarily affects. - options: - - Installation Instructions - - Configuration Parameters - - Functionality/Features - - Administration/Development - - Other - validations: - required: true - - - type: textarea - attributes: - label: Proposed Changes - description: Please describe the proposed changes and explain their significance or necessity. - validations: - required: true diff --git a/.github/ISSUE_TEMPLATE/4-housekeeping.yml b/.github/ISSUE_TEMPLATE/4-housekeeping.yml deleted file mode 100644 index 2df4a75..0000000 --- a/.github/ISSUE_TEMPLATE/4-housekeeping.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: 🏡 Housekeeping -description: A codebase enhancement (for developers' use only) -labels: ["type: maintenance"] -assignees: "kprince28" -body: - - type: markdown - attributes: - value: > - **Important Note:** This template is intended for use by maintainers exclusively. Please refrain from submitting an issue using this template unless you have been specifically requested to do so. - - - type: textarea - attributes: - label: Proposed Changes - description: > - Please provide a detailed description of the new feature or behavior you are proposing. Include any specific modifications to workflows, data models, or the user interface. - validations: - required: true - - - type: textarea - attributes: - label: Justification - description: Please offer a rationale for the proposed changes. - validations: - required: true diff --git a/.github/ISSUE_TEMPLATE/5-deprecation.yml b/.github/ISSUE_TEMPLATE/5-deprecation.yml deleted file mode 100644 index 2404361..0000000 --- a/.github/ISSUE_TEMPLATE/5-deprecation.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: ⚠️ Deprecation Notice -description: A deprecation notice for outdated features or behaviors -labels: ["type: deprecated"] -assignees: "kprince28" -body: - - type: markdown - attributes: - value: > - **Important Note:** This template is intended to inform users and developers about the deprecation of certain features or behaviors in the project. If you have questions or need assistance with the transition, please comment on this issue. - - - type: textarea - attributes: - label: Deprecated Feature or Behavior - description: > - Please specify the feature or behavior that is being deprecated. Include relevant details such as the file, function, or component name. - validations: - required: true - - - type: textarea - attributes: - label: Deprecation Details - description: > - Provide information about why this feature or behavior is being deprecated. Explain any alternatives or recommended actions for users or developers to take. - validations: - required: true - - - type: textarea - attributes: - label: Timeline for Deprecation - description: > - Outline the timeline for the deprecation process, including any milestones, dates, or versions when the feature or behavior will be officially deprecated and removed. - validations: - required: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c982f4b..519a45d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,8 @@ on: - published workflow_dispatch: { } push: + branches: + - '*' tags: - v[0-9]+.[0-9]+.[0-9]+(-[a-zA-Z]+[0-9]+)? pull_request: @@ -16,10 +18,10 @@ on: jobs: pre_commit: name: Run lint rules - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-sh steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v4.1.1 - name: Set up Python uses: actions/setup-python@v4.7.0 @@ -29,12 +31,49 @@ jobs: - uses: pre-commit/action@v3.0.0 test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04-sh name: Runs plugin tests steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v4.1.1 + + - name: Login to Registry + uses: docker/login-action@v3 + with: + registry: registry.tangience.net + username: ${{ secrets.HARBOR_USERNAME }} + password: ${{ secrets.HARBOR_PASSWORD }} - name: Test the image run: ./test.sh + + changelog: + name: "Changelog Generator" + runs-on: ubuntu-22.04-sh + needs: + - test + timeout-minutes: 30 + if: github.event_name == 'release' + steps: + - name: Checkout code + uses: actions/checkout@v4.1.1 + + - name: "Generate changelog" + uses: charmixer/auto-changelog-action@v1.4 + with: + exclude_labels: "type: skip ci,status: abandoned,type: duplicate,type: question,type: wontfix,type: invalid" + token: ${{ secrets.GIT_TOKEN }} + + - name: Commit and push to dev + uses: EndBug/add-and-commit@v9.1.3 + env: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + with: + add: "CHANGELOG.md" + message: "[skip ci] Updated CHANGELOG.md" + new_branch: dev + push: origin dev --set-upstream + committer_name: GitHub Actions + committer_email: actions@github.com + default_author: github_actions From 13bf040119171b1e60a36b3cdf1c085b39e3df96 Mon Sep 17 00:00:00 2001 From: mjoshionemind Date: Wed, 3 Jul 2024 20:02:39 +0530 Subject: [PATCH 09/11] NB-17 reformat code --- netbox_metatype_importer/api/serializers.py | 3 +-- netbox_metatype_importer/api/views.py | 8 ++++---- .../netbox_metatype_importer/metadevicetype_list.html | 2 ++ .../netbox_metatype_importer/metamoduletype_list.html | 2 ++ netbox_metatype_importer/tests/test_models.py | 2 +- netbox_metatype_importer/utils.py | 2 +- netbox_metatype_importer/views.py | 4 ++-- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/netbox_metatype_importer/api/serializers.py b/netbox_metatype_importer/api/serializers.py index 3a9240f..390a3d2 100644 --- a/netbox_metatype_importer/api/serializers.py +++ b/netbox_metatype_importer/api/serializers.py @@ -1,8 +1,7 @@ +from netbox_metatype_importer.models import MetaType from rest_framework import serializers from rest_framework.serializers import HyperlinkedIdentityField -from netbox_metatype_importer.models import MetaType - class MetaTypeSerializer(serializers.ModelSerializer): url = HyperlinkedIdentityField(view_name="plugins-api:netbox_metatype_importer-api:metatype-detail") diff --git a/netbox_metatype_importer/api/views.py b/netbox_metatype_importer/api/views.py index e138af7..367ecbe 100644 --- a/netbox_metatype_importer/api/views.py +++ b/netbox_metatype_importer/api/views.py @@ -6,6 +6,9 @@ from django.db.models import Q from django.shortcuts import reverse from django.utils.text import slugify +from netbox_metatype_importer.filters import MetaTypeFilterSet +from netbox_metatype_importer.forms import MetaTypeFilterForm +from netbox_metatype_importer.graphql.gql import GQLError, GitHubGqlAPI from rest_framework import mixins as drf_mixins, status from rest_framework.response import Response from rest_framework.routers import APIRootView @@ -13,13 +16,10 @@ from dcim import forms from dcim.models import DeviceType, Manufacturer, ModuleType from netbox.api.viewsets import BaseViewSet -from netbox_metatype_importer.filters import MetaTypeFilterSet -from netbox_metatype_importer.forms import MetaTypeFilterForm from utilities.exceptions import AbortTransaction, PermissionsViolation from utilities.forms.bulk_import import BulkImportForm from . import serializers from ..choices import TypeChoices -from netbox_metatype_importer.graphql.gql import GQLError, GitHubGqlAPI from ..models import MetaType from ..utils import * @@ -117,7 +117,7 @@ def create(self, request, *args, **kwargs): _mdt.save() vendors_for_cre = set(model.objects.filter(pk__in=pk_list).values_list('vendor', flat=True).distinct()) for vendor, name, sha in model.objects.filter(pk__in=pk_list, is_imported=False).values_list( - 'vendor', 'name', 'sha' + 'vendor', 'name', 'sha' ): query_data[sha] = f'{vendor}/{name}' if not query_data: diff --git a/netbox_metatype_importer/templates/netbox_metatype_importer/metadevicetype_list.html b/netbox_metatype_importer/templates/netbox_metatype_importer/metadevicetype_list.html index d61ad37..5170450 100644 --- a/netbox_metatype_importer/templates/netbox_metatype_importer/metadevicetype_list.html +++ b/netbox_metatype_importer/templates/netbox_metatype_importer/metadevicetype_list.html @@ -22,6 +22,7 @@ {% if perms.netbox_metatype_importer.add_metadevicetype %}