diff --git a/netbox_napalm_plugin/__init__.py b/netbox_napalm_plugin/__init__.py index 4a0b194..3c9c976 100644 --- a/netbox_napalm_plugin/__init__.py +++ b/netbox_napalm_plugin/__init__.py @@ -8,7 +8,7 @@ from extras.plugins import PluginConfig -class NapalmConfig(PluginConfig): +class NapalmPlatformConfig(PluginConfig): name = "netbox_napalm_plugin" verbose_name = "NetBox Napalm Plugin" description = "NetBox plugin for Napalm." @@ -16,4 +16,4 @@ class NapalmConfig(PluginConfig): base_url = "netbox_napalm_plugin" -config = NapalmConfig +config = NapalmPlatformConfig diff --git a/netbox_napalm_plugin/api/serializers.py b/netbox_napalm_plugin/api/serializers.py index 684aad6..f44c658 100644 --- a/netbox_napalm_plugin/api/serializers.py +++ b/netbox_napalm_plugin/api/serializers.py @@ -2,17 +2,17 @@ from netbox.api.serializers import NetBoxModelSerializer from rest_framework import serializers -from netbox_napalm_plugin.models import NapalmPlatform +from netbox_napalm_plugin.models import NapalmPlatformConfig -class NapalmPlatformSerializer(NetBoxModelSerializer): +class NapalmPlatformConfigSerializer(NetBoxModelSerializer): url = serializers.HyperlinkedIdentityField( - view_name="plugins-api:netbox_napalm_plugin-api:napalmplatform-detail" + view_name="plugins-api:netbox_napalm_plugin-api:napalmplatformconfig-detail" ) platform = NestedPlatformSerializer() class Meta: - model = NapalmPlatform + model = NapalmPlatformConfig fields = [ "id", "url", diff --git a/netbox_napalm_plugin/api/urls.py b/netbox_napalm_plugin/api/urls.py index ffb4171..6fa8bfd 100644 --- a/netbox_napalm_plugin/api/urls.py +++ b/netbox_napalm_plugin/api/urls.py @@ -1,8 +1,8 @@ # api/urls.py from netbox.api.routers import NetBoxRouter -from .views import NapalmPlatformViewSet +from .views import NapalmPlatformConfigViewSet router = NetBoxRouter() -router.register("napalmplatform", NapalmPlatformViewSet) +router.register("napalmplatformconfig", NapalmPlatformConfigViewSet) urlpatterns = router.urls diff --git a/netbox_napalm_plugin/api/views.py b/netbox_napalm_plugin/api/views.py index c44810a..a058550 100644 --- a/netbox_napalm_plugin/api/views.py +++ b/netbox_napalm_plugin/api/views.py @@ -1,5 +1,6 @@ from dcim.models import Device from django.shortcuts import get_object_or_404, redirect, render +from netbox.api.exceptions import ServiceUnavailable from netbox.api.pagination import StripCountAnnotationsPaginator from netbox.api.viewsets import NetBoxModelViewSet from netbox.config import get_config @@ -7,18 +8,18 @@ from rest_framework.response import Response from netbox_napalm_plugin import filtersets -from netbox_napalm_plugin.models import NapalmPlatform +from netbox_napalm_plugin.models import NapalmPlatformConfig from . import serializers -class NapalmPlatformViewSet(NetBoxModelViewSet): - queryset = NapalmPlatform.objects.prefetch_related( +class NapalmPlatformConfigViewSet(NetBoxModelViewSet): + queryset = NapalmPlatformConfig.objects.prefetch_related( "platform", "tags", ) - serializer_class = serializers.NapalmPlatformSerializer - filterset_class = filtersets.NapalmPlatformFilterSet + serializer_class = serializers.NapalmPlatformConfigSerializer + filterset_class = filtersets.NapalmPlatformConfigFilterSet pagination_class = StripCountAnnotationsPaginator @action(detail=True, url_path="napalm") diff --git a/netbox_napalm_plugin/filtersets.py b/netbox_napalm_plugin/filtersets.py index 7d9dcc7..0b93fa8 100644 --- a/netbox_napalm_plugin/filtersets.py +++ b/netbox_napalm_plugin/filtersets.py @@ -4,10 +4,10 @@ from netbox.filtersets import (NetBoxModelFilterSet, OrganizationalModelFilterSet) -from .models import NapalmPlatform +from .models import NapalmPlatformConfig -class NapalmPlatformFilterSet(NetBoxModelFilterSet): +class NapalmPlatformConfigFilterSet(NetBoxModelFilterSet): platform_id = django_filters.ModelMultipleChoiceFilter( field_name="platform", queryset=Platform.objects.all(), @@ -21,5 +21,5 @@ class NapalmPlatformFilterSet(NetBoxModelFilterSet): ) class Meta: - model = NapalmPlatform + model = NapalmPlatformConfig fields = ["id", "napalm_driver"] diff --git a/netbox_napalm_plugin/forms.py b/netbox_napalm_plugin/forms.py index 62aa920..faaac6d 100644 --- a/netbox_napalm_plugin/forms.py +++ b/netbox_napalm_plugin/forms.py @@ -3,12 +3,12 @@ from netbox.forms import NetBoxModelFilterSetForm, NetBoxModelForm from utilities.forms.fields import CommentField, DynamicModelChoiceField -from .models import NapalmPlatform +from .models import NapalmPlatformConfig -class NapalmPlatformForm(NetBoxModelForm): +class NapalmPlatformConfigForm(NetBoxModelForm): class Meta: - model = NapalmPlatform + model = NapalmPlatformConfig fields = ( "platform", "napalm_driver", diff --git a/netbox_napalm_plugin/migrations/0001_initial.py b/netbox_napalm_plugin/migrations/0001_initial.py index 40abe32..ad0192c 100644 --- a/netbox_napalm_plugin/migrations/0001_initial.py +++ b/netbox_napalm_plugin/migrations/0001_initial.py @@ -16,7 +16,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name="NapalmPlatform", + name="NapalmPlatformConfig", fields=[ ( "id", diff --git a/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py b/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py index 7f8ac0e..7ae5a48 100644 --- a/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py +++ b/netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py @@ -5,10 +5,10 @@ def migrate_napalm(apps, schema_editor): Platform = apps.get_model("dcim", "Platform") - NapalmPlatform = apps.get_model("netbox_napalm_plugin", "NapalmPlatform") + NapalmPlatformConfig = apps.get_model("netbox_napalm_plugin", "NapalmPlatformConfig") qs = Platform.objects.all().exclude(napalm_driver__exact="") for platform in qs: - NapalmPlatform.objects.create( + NapalmPlatformConfig.objects.create( platform=platform, napalm_driver=platform.napalm_driver, napalm_args=platform.napalm_args, diff --git a/netbox_napalm_plugin/models.py b/netbox_napalm_plugin/models.py index e80784b..d61fa7d 100644 --- a/netbox_napalm_plugin/models.py +++ b/netbox_napalm_plugin/models.py @@ -5,7 +5,7 @@ from netbox.models import NetBoxModel -class NapalmPlatform(NetBoxModel): +class NapalmPlatformConfig(NetBoxModel): platform = models.OneToOneField( Platform, on_delete=models.CASCADE, @@ -35,4 +35,4 @@ def __str__(self): return f"{self.platform.name} -> {self.napalm_driver}" def get_absolute_url(self): - return reverse("plugins:netbox_napalm_plugin:napalmplatform", args=[self.pk]) + return reverse("plugins:netbox_napalm_plugin:napalmplatformconfig", args=[self.pk]) diff --git a/netbox_napalm_plugin/navigation.py b/netbox_napalm_plugin/navigation.py index bc7aed3..53de5a8 100644 --- a/netbox_napalm_plugin/navigation.py +++ b/netbox_napalm_plugin/navigation.py @@ -3,7 +3,7 @@ plugin_buttons = [ PluginMenuButton( - link="plugins:netbox_napalm_plugin:napalmplatform_add", + link="plugins:netbox_napalm_plugin:napalmplatformconfig_add", title="Add", icon_class="mdi mdi-plus-thick", color=ButtonColorChoices.GREEN, @@ -12,7 +12,7 @@ menu_items = ( PluginMenuItem( - link="plugins:netbox_napalm_plugin:napalmplatform_list", + link="plugins:netbox_napalm_plugin:napalmplatformconfig_list", link_text="Napalm", buttons=plugin_buttons, ), diff --git a/netbox_napalm_plugin/tables.py b/netbox_napalm_plugin/tables.py index a58dd21..ef5ad2f 100644 --- a/netbox_napalm_plugin/tables.py +++ b/netbox_napalm_plugin/tables.py @@ -2,19 +2,19 @@ from django_tables2.utils import Accessor from netbox.tables import ChoiceFieldColumn, NetBoxTable -from .models import NapalmPlatform +from .models import NapalmPlatformConfig -class NapalmPlatformTable(NetBoxTable): +class NapalmPlatformConfigTable(NetBoxTable): name = tables.Column( accessor=Accessor('platform__name'), linkify={ - 'viewname': 'plugins:netbox_napalm_plugin:napalmplatform', + 'viewname': 'plugins:netbox_napalm_plugin:napalmplatformconfig', 'args': [Accessor('pk')], } ) class Meta(NetBoxTable.Meta): - model = NapalmPlatform + model = NapalmPlatformConfig fields = ("pk", "name", "napalm_driver", "napalm_args", "actions") default_columns = ("name", "napalm_driver") diff --git a/netbox_napalm_plugin/templates/netbox_napalm_plugin/config.html b/netbox_napalm_plugin/templates/netbox_napalm_plugin/config.html index 525c1e1..84ee093 100644 --- a/netbox_napalm_plugin/templates/netbox_napalm_plugin/config.html +++ b/netbox_napalm_plugin/templates/netbox_napalm_plugin/config.html @@ -41,5 +41,5 @@
Device Configuration
{% endblock %} {% block data %} - + {% endblock %} diff --git a/netbox_napalm_plugin/templates/netbox_napalm_plugin/lldp_neighbors.html b/netbox_napalm_plugin/templates/netbox_napalm_plugin/lldp_neighbors.html index 917a7f0..6f661e4 100644 --- a/netbox_napalm_plugin/templates/netbox_napalm_plugin/lldp_neighbors.html +++ b/netbox_napalm_plugin/templates/netbox_napalm_plugin/lldp_neighbors.html @@ -62,5 +62,5 @@
LLDP Neighbors
{% endblock %} {% block data %} - + {% endblock %} diff --git a/netbox_napalm_plugin/templates/netbox_napalm_plugin/napalmplatform.html b/netbox_napalm_plugin/templates/netbox_napalm_plugin/napalmplatformconfig.html similarity index 100% rename from netbox_napalm_plugin/templates/netbox_napalm_plugin/napalmplatform.html rename to netbox_napalm_plugin/templates/netbox_napalm_plugin/napalmplatformconfig.html diff --git a/netbox_napalm_plugin/templates/netbox_napalm_plugin/status.html b/netbox_napalm_plugin/templates/netbox_napalm_plugin/status.html index a9e9435..16c2b43 100644 --- a/netbox_napalm_plugin/templates/netbox_napalm_plugin/status.html +++ b/netbox_napalm_plugin/templates/netbox_napalm_plugin/status.html @@ -89,5 +89,5 @@
Environment
{% endblock %} {% block data %} - + {% endblock %} diff --git a/netbox_napalm_plugin/urls.py b/netbox_napalm_plugin/urls.py index 3aad75b..be21f7c 100644 --- a/netbox_napalm_plugin/urls.py +++ b/netbox_napalm_plugin/urls.py @@ -4,25 +4,25 @@ from . import models, views urlpatterns = ( - path("napalm/", views.NapalmPlatformListView.as_view(), name="napalmplatform_list"), + path("napalm/", views.NapalmPlatformConfigListView.as_view(), name="napalmplatformconfig_list"), path( - "napalm/add/", views.NapalmPlatformEditView.as_view(), name="napalmplatform_add" + "napalm/add/", views.NapalmPlatformConfigEditView.as_view(), name="napalmplatformconfig_add" ), - path("napalm//", views.NapalmPlatformView.as_view(), name="napalmplatform"), + path("napalm//", views.NapalmPlatformConfigView.as_view(), name="napalmplatformconfig"), path( "napalm//edit/", - views.NapalmPlatformEditView.as_view(), - name="napalmplatform_edit", + views.NapalmPlatformConfigEditView.as_view(), + name="napalmplatformconfig_edit", ), path( "napalm//delete/", - views.NapalmPlatformDeleteView.as_view(), - name="napalmplatform_delete", + views.NapalmPlatformConfigDeleteView.as_view(), + name="napalmplatformconfig_delete", ), path( "napalm//changelog/", ObjectChangeLogView.as_view(), - name="napalmplatform_changelog", - kwargs={"model": models.NapalmPlatform}, + name="napalmplatformconfig_changelog", + kwargs={"model": models.NapalmPlatformConfig}, ), ) diff --git a/netbox_napalm_plugin/views.py b/netbox_napalm_plugin/views.py index f40ef06..b3ef94f 100644 --- a/netbox_napalm_plugin/views.py +++ b/netbox_napalm_plugin/views.py @@ -8,22 +8,22 @@ from . import filtersets, forms, models, tables -class NapalmPlatformView(generic.ObjectView): - queryset = models.NapalmPlatform.objects.all() +class NapalmPlatformConfigView(generic.ObjectView): + queryset = models.NapalmPlatformConfig.objects.all() -class NapalmPlatformListView(generic.ObjectListView): - queryset = models.NapalmPlatform.objects.all() - table = tables.NapalmPlatformTable +class NapalmPlatformConfigListView(generic.ObjectListView): + queryset = models.NapalmPlatformConfig.objects.all() + table = tables.NapalmPlatformConfigTable -class NapalmPlatformEditView(generic.ObjectEditView): - queryset = models.NapalmPlatform.objects.all() - form = forms.NapalmPlatformForm +class NapalmPlatformConfigEditView(generic.ObjectEditView): + queryset = models.NapalmPlatformConfig.objects.all() + form = forms.NapalmPlatformConfigForm -class NapalmPlatformDeleteView(generic.ObjectDeleteView): - queryset = models.NapalmPlatform.objects.all() +class NapalmPlatformConfigDeleteView(generic.ObjectDeleteView): + queryset = models.NapalmPlatformConfig.objects.all() class NAPALMViewTab(ViewTab):