-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
) |