Skip to content

Commit

Permalink
Complete initial plugin! 0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorlin committed Dec 31, 2023
1 parent 1bc7f88 commit 66241e9
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions netbox_physical_storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ class NetBoxPhysicalStorageConfig(PluginConfig):
description = 'Manage physical storage interfaces and devices in NetBox.'
version = '0.0.1'
base_url = 'physical-storage'
min_version = '3.4.0'

config = NetBoxPhysicalStorageConfig
Empty file.
25 changes: 25 additions & 0 deletions netbox_physical_storage/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from rest_framework import serializers
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
from ..models import StorageDevice

class StorageDeviceSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_physical_storage-api:storagedevice-detail'
)
class Meta:
model = StorageDevice
fields = [
'id', 'url', 'name', 'storage_device_type', 'serial_number', 'mount_point', 'comments', 'tags', 'custom_fields', 'created',
'last_updated',
]

# TODO: This entire class may be unnecessary, as I don't know that we need nested serializers for this plugin.
# 2023-12-31: Bye 2023! See you in a year...
class NestedStorageDeviceSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_physical_storage-api:storagedevice-detail'
)

class Meta:
model = StorageDevice
fields = ('id', 'url', 'display', 'name')
9 changes: 9 additions & 0 deletions netbox_physical_storage/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from netbox.api.routers import NetBoxRouter
from . import views

app_name = 'netbox_physical_storage'

router = NetBoxRouter()
router.register('storage-devices', views.StorageDeviceViewSet)

urlpatterns = router.urls
8 changes: 8 additions & 0 deletions netbox_physical_storage/api/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from netbox.api.viewsets import NetBoxModelViewSet

from .. import filtersets, models
from .serializers import StorageDeviceSerializer

class StorageDeviceViewSet(NetBoxModelViewSet):
queryset = models.StorageDevice.objects.prefetch_related('tags')
serializer_class = StorageDeviceSerializer
16 changes: 16 additions & 0 deletions netbox_physical_storage/graphql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from graphene import ObjectType
from netbox.graphql.types import NetBoxObjectType
from netbox.graphql.fields import ObjectField, ObjectListField
from . import filtersets, models

class StorageDeviceType(NetBoxObjectType):

class Meta:
model = models.StorageDevice
fields = '__all__'

class Query(ObjectType):
storage_device = ObjectField(StorageDeviceType)
storage_device_list = ObjectListField(StorageDeviceType)

schema = Query
14 changes: 14 additions & 0 deletions netbox_physical_storage/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from netbox.search import SearchIndex, register_search
from .models import StorageDevice

@register_search

class StorageDeviceIndex(SearchIndex):
model = StorageDevice
fields = (
('name', 100),
('storage_device_type', 50),
('serial_number', 50),
('mount_point', 50),
('comments', 50),
)

0 comments on commit 66241e9

Please sign in to comment.