Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson committed Feb 17, 2023
1 parent 81f701b commit 42bb2da
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 52 deletions.
4 changes: 2 additions & 2 deletions netbox_napalm_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
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."
version = "version"
base_url = "netbox_napalm_plugin"


config = NapalmConfig
config = NapalmPlatformConfig
8 changes: 4 additions & 4 deletions netbox_napalm_plugin/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions netbox_napalm_plugin/api/urls.py
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions netbox_napalm_plugin/api/views.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
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
from rest_framework.decorators import action
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")
Expand Down
6 changes: 3 additions & 3 deletions netbox_napalm_plugin/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -21,5 +21,5 @@ class NapalmPlatformFilterSet(NetBoxModelFilterSet):
)

class Meta:
model = NapalmPlatform
model = NapalmPlatformConfig
fields = ["id", "napalm_driver"]
6 changes: 3 additions & 3 deletions netbox_napalm_plugin/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion netbox_napalm_plugin/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="NapalmPlatform",
name="NapalmPlatformConfig",
fields=[
(
"id",
Expand Down
4 changes: 2 additions & 2 deletions netbox_napalm_plugin/migrations/0002_auto_20230215_1752.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions netbox_napalm_plugin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from netbox.models import NetBoxModel


class NapalmPlatform(NetBoxModel):
class NapalmPlatformConfig(NetBoxModel):
platform = models.OneToOneField(
Platform,
on_delete=models.CASCADE,
Expand Down Expand Up @@ -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])
4 changes: 2 additions & 2 deletions netbox_napalm_plugin/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
),
Expand Down
8 changes: 4 additions & 4 deletions netbox_napalm_plugin/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ <h5 class="card-header">Device Configuration</h5>
{% endblock %}

{% block data %}
<span data-object-url="{% url 'plugins-api:netbox_napalm_plugin-api:napalmplatform-napalm' pk=object.pk %}?method=get_config"></span>
<span data-object-url="{% url 'plugins-api:netbox_napalm_plugin-api:napalmplatformconfig-napalm' pk=object.pk %}?method=get_config"></span>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ <h5 class="d-inline">LLDP Neighbors</h5>
{% endblock %}

{% block data %}
<span data-object-url="{% url 'plugins-api:netbox_napalm_plugin-api:napalmplatform-napalm' pk=object.pk %}?method=get_lldp_neighbors_detail"></span>
<span data-object-url="{% url 'plugins-api:netbox_napalm_plugin-api:napalmplatformconfig-napalm' pk=object.pk %}?method=get_lldp_neighbors_detail"></span>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,5 @@ <h5 class="card-header">Environment</h5>
{% endblock %}

{% block data %}
<span data-object-url="{% url 'plugins-api:netbox_napalm_plugin-api:napalmplatform-napalm' pk=object.pk %}?method=get_facts&method=get_environment"></span>
<span data-object-url="{% url 'plugins-api:netbox_napalm_plugin-api:napalmplatformconfig-napalm' pk=object.pk %}?method=get_facts&method=get_environment"></span>
{% endblock %}
18 changes: 9 additions & 9 deletions netbox_napalm_plugin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:pk>/", views.NapalmPlatformView.as_view(), name="napalmplatform"),
path("napalm/<int:pk>/", views.NapalmPlatformConfigView.as_view(), name="napalmplatformconfig"),
path(
"napalm/<int:pk>/edit/",
views.NapalmPlatformEditView.as_view(),
name="napalmplatform_edit",
views.NapalmPlatformConfigEditView.as_view(),
name="napalmplatformconfig_edit",
),
path(
"napalm/<int:pk>/delete/",
views.NapalmPlatformDeleteView.as_view(),
name="napalmplatform_delete",
views.NapalmPlatformConfigDeleteView.as_view(),
name="napalmplatformconfig_delete",
),
path(
"napalm/<int:pk>/changelog/",
ObjectChangeLogView.as_view(),
name="napalmplatform_changelog",
kwargs={"model": models.NapalmPlatform},
name="napalmplatformconfig_changelog",
kwargs={"model": models.NapalmPlatformConfig},
),
)
20 changes: 10 additions & 10 deletions netbox_napalm_plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 42bb2da

Please sign in to comment.