Skip to content

Commit

Permalink
4.0 related changes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
viroge committed Sep 26, 2024
1 parent 8d22581 commit 6f94057
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 203 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.vscode
.vscode
*.egg-info/
__pycache__/
5 changes: 2 additions & 3 deletions netbox_storage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#from extras.plugins import PluginConfig
from netbox.plugins import PluginConfig

class NetBoxStorageConfig(PluginConfig):
name = 'netbox_storage'
verbose_name = ' NetBox Storage'
description = 'Netbox Storage Administration Plugin'
version = '0.6.3'
version = '0.7.0'
base_url = 'storage'
min_version = "3.4.0"
min_version = "4.0.0"
author = 'Gabor Somogyvari'


Expand Down
93 changes: 25 additions & 68 deletions netbox_storage/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,89 +1,34 @@
from rest_framework import serializers

from virtualization.api.serializers import NestedClusterSerializer, NestedVirtualMachineSerializer
from dcim.api.serializers import NestedDeviceSerializer
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
from virtualization.api.serializers import ClusterSerializer, VirtualMachineSerializer
from dcim.api.serializers import DeviceSerializer
from netbox.api.serializers import NetBoxModelSerializer
from netbox.api.fields import SerializedPKRelatedField
from ..models import StoragePool, LUN, StorageSession, Datastore, VMDK


#
# Nested serializers
#

class NestedStoragePoolSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:storagepool-detail'
)

class Meta:
model = StoragePool
fields = ('id', 'url', 'display', 'name')


class NestedLUNSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:lun-detail'
)

class Meta:
model = LUN
fields = ('id', 'url', 'display', 'name')


class NestedDatastoreSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:datastore-detail'
)

class Meta:
model = Datastore
fields = ('id', 'url', 'display', 'name')


class NestedStorageSessionSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:storagesession-detail'
)

class Meta:
model = StorageSession
fields = ('id', 'url', 'display', 'name')


class NestedVMDKSerializer(WritableNestedSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:vmdk-detail'
)

class Meta:
model = VMDK
fields = ('id', 'url', 'display', 'name')


#
# Regular serializers
#

class StoragePoolSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:storagepool-detail'
)
device = NestedDeviceSerializer()
device = DeviceSerializer(nested=True)

class Meta:
model = StoragePool
fields = (
'id', 'url', 'display', 'name', 'size', 'device', 'description',
'tags', 'custom_fields', 'created', 'last_updated',
)
brief_fields = (
'id', 'url', 'display', 'name', 'size', 'device',
)


class LUNSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:lun-detail'
)
storage_pool = NestedStoragePoolSerializer()
storage_pool = StoragePoolSerializer(nested=True)

class Meta:
model = LUN
Expand All @@ -92,6 +37,9 @@ class Meta:
'description', 'tags', 'custom_fields',
'created', 'last_updated',
)
brief_fields = (
'id', 'url', 'display', 'name', 'size', 'storage_pool',
)


class DatastoreSerializer(NetBoxModelSerializer):
Expand All @@ -100,7 +48,7 @@ class DatastoreSerializer(NetBoxModelSerializer):
)
lun = SerializedPKRelatedField(
queryset=LUN.objects.all(),
serializer=NestedLUNSerializer,
serializer=LUNSerializer,
many=True
)

Expand All @@ -110,16 +58,19 @@ class Meta:
'id', 'url', 'display', 'name', 'lun',
'description', 'tags', 'custom_fields', 'created', 'last_updated',
)
brief_fields = (
'id', 'url', 'display', 'name', 'lun',
)


class StorageSessionSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:storagesession-detail'
)
cluster = NestedClusterSerializer()
cluster = ClusterSerializer(nested=True)
datastores = SerializedPKRelatedField(
queryset=Datastore.objects.all(),
serializer=NestedDatastoreSerializer,
serializer=DatastoreSerializer,
many=True
)

Expand All @@ -129,18 +80,24 @@ class Meta:
'id', 'url', 'display', 'name', 'cluster', 'datastores',
'description', 'tags', 'custom_fields', 'created', 'last_updated',
)
brief_fields = (
'id', 'url', 'display', 'name', 'cluster', 'datastores',
)


class VMDKSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(
view_name='plugins-api:netbox_storage-api:vmdk-detail'
)
datastore = NestedDatastoreSerializer()
vm = NestedVirtualMachineSerializer()
datastore = DatastoreSerializer(nested=True)
vm = VirtualMachineSerializer(nested=True)

class Meta:
model = VMDK
fields = (
'id', 'url', 'display', 'vm', 'name', 'datastore',
'size', 'tags', 'custom_fields', 'created', 'last_updated',
)
brief_fields = (
'id', 'url', 'display', 'vm', 'name', 'datastore', 'size',
)
13 changes: 0 additions & 13 deletions netbox_storage/navigation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#from extras.plugins import PluginMenuButton, PluginMenuItem, PluginMenu
#from utilities.choices import ButtonColorChoices
from netbox.plugins import PluginMenuItem, PluginMenu, PluginMenuButton
from netbox.choices import ButtonColorChoices

storagepool_item = PluginMenuItem(
link='plugins:netbox_storage:storagepool_list',
Expand All @@ -12,14 +9,12 @@
link='plugins:netbox_storage:storagepool_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN,
permissions=['netbox_storage.add_storagepool'],
),
PluginMenuButton(
link='plugins:netbox_storage:storagepool_import',
title='Import',
icon_class='mdi mdi-upload',
color=ButtonColorChoices.CYAN,
permissions=['netbox_storage.add_storagepool'],
)
]
Expand All @@ -34,14 +29,12 @@
link='plugins:netbox_storage:lun_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN,
permissions=['netbox_storage.add_lun'],
),
PluginMenuButton(
link='plugins:netbox_storage:lun_import',
title='Import',
icon_class='mdi mdi-upload',
color=ButtonColorChoices.CYAN,
permissions=['netbox_storage.add_lun'],
)
]
Expand All @@ -56,14 +49,12 @@
link='plugins:netbox_storage:datastore_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN,
permissions=['netbox_storage.add_datastore'],
),
PluginMenuButton(
link='plugins:netbox_storage:datastore_import',
title='Import',
icon_class='mdi mdi-upload',
color=ButtonColorChoices.CYAN,
permissions=['netbox_storage.add_datastore'],
)
]
Expand All @@ -78,14 +69,12 @@
link='plugins:netbox_storage:storagesession_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN,
permissions=['netbox_storage.add_storagesession'],
),
PluginMenuButton(
link='plugins:netbox_storage:storagesession_import',
title='Import',
icon_class='mdi mdi-upload',
color=ButtonColorChoices.CYAN,
permissions=['netbox_storage.add_storagesession'],
)
]
Expand All @@ -100,14 +89,12 @@
link='plugins:netbox_storage:vmdk_add',
title='Add',
icon_class='mdi mdi-plus-thick',
color=ButtonColorChoices.GREEN,
permissions=['netbox_storage.add_vmdk'],
),
PluginMenuButton(
link='plugins:netbox_storage:vmdk_import',
title='Import',
icon_class='mdi mdi-upload',
color=ButtonColorChoices.CYAN,
permissions=['netbox_storage.add_vmdk'],
)
]
Expand Down
1 change: 0 additions & 1 deletion netbox_storage/template_content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#from extras.plugins import PluginTemplateExtension
from netbox.plugins import PluginTemplateExtension
from .models import VMDK

Expand Down
30 changes: 14 additions & 16 deletions netbox_storage/templates/netbox_storage/datastore.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">Datastore</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Utilization</th>
<td>{% utilization_graph object.get_utilization %}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description }}</td>
</tr>
</table>
</div>
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Utilization</th>
<td>{% utilization_graph object.get_utilization %}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description }}</td>
</tr>
</table>
</div>
{% include 'inc/panels/custom_fields.html' %}
</div>
Expand Down
50 changes: 24 additions & 26 deletions netbox_storage/templates/netbox_storage/lun.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">LUN</h5>
<div class="card-body">
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Storage pool</th>
<td>
<a href="{{ object.storage_pool.get_absolute_url }}">{{ object.storage_pool }}</a>
</td>
</tr>
<tr>
<th scope="row">Size</th>
<td>{{ object.size|filesizeformat }}</td>
</tr>
<tr>
<th scope="row">WWN</th>
<td>{{ object.wwn }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description }}</td>
</tr>
</table>
</div>
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Storage pool</th>
<td>
<a href="{{ object.storage_pool.get_absolute_url }}">{{ object.storage_pool }}</a>
</td>
</tr>
<tr>
<th scope="row">Size</th>
<td>{{ object.size|filesizeformat }}</td>
</tr>
<tr>
<th scope="row">WWN</th>
<td>{{ object.wwn }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description }}</td>
</tr>
</table>
</div>
{% include 'inc/panels/custom_fields.html' %}
</div>
Expand Down
Loading

0 comments on commit 6f94057

Please sign in to comment.