Skip to content

Commit

Permalink
formfilters, filtersets added for all object types
Browse files Browse the repository at this point in the history
  • Loading branch information
viroge committed Feb 9, 2023
1 parent 609a176 commit eca527d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 78 deletions.
66 changes: 43 additions & 23 deletions netbox_storage/filtersets.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,56 @@
from netbox.filtersets import NetBoxModelFilterSet
from .models import LUN, StorageSession, Datastore
from .models import StoragePool, LUN, StorageSession, Datastore, VMDK


# class StorageLUNFilterSet(NetBoxModelFilterSet):
class StoragePoolFilterSet(NetBoxModelFilterSet):

# class Meta:
# model = StorageLUN
# fields = ('id', 'storage_pool', 'name',)
class Meta:
model = StoragePool
fields = ('id', 'name', 'device')

# def search(self, queryset, name, value):
# return queryset.filter(description__icontains=value)
def search(self, queryset, name, value):
return queryset.filter(description__icontains=value)


# class StorageSessionFilterSet(NetBoxModelFilterSet):
class LUNFilterSet(NetBoxModelFilterSet):

# class Meta:
# model = StorageSession
# fields = (
# 'id', 'name', 'cluster', 'storage_lun_groups',
# )
class Meta:
model = LUN
fields = ('id', 'storage_pool', 'name',)

# def search(self, queryset, name, value):
# return queryset.filter(description__icontains=value)
def search(self, queryset, name, value):
return queryset.filter(description__icontains=value)


# class StorageLUNGroupFilterSet(NetBoxModelFilterSet):
class DatastoreFilterSet(NetBoxModelFilterSet):

# class Meta:
# model = StorageLUNGroup
# fields = (
# 'id', 'storage_pool_allocation', 'name', 'vm',
# )
class Meta:
model = Datastore
fields = ('id', 'lun', 'name',)

# def search(self, queryset, name, value):
# return queryset.filter(description__icontains=value)
def search(self, queryset, name, value):
return queryset.filter(description__icontains=value)


class StorageSessionFilterSet(NetBoxModelFilterSet):

class Meta:
model = StorageSession
fields = (
'id', 'name', 'cluster', 'datastores',
)

def search(self, queryset, name, value):
return queryset.filter(description__icontains=value)


class VMDKFilterSet(NetBoxModelFilterSet):

class Meta:
model = VMDK
fields = (
'id', 'name', 'vm', 'datastore',
)

def search(self, queryset, name, value):
return queryset.filter(description__icontains=value)
106 changes: 59 additions & 47 deletions netbox_storage/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# Regular forms
#

class StoragePoolForm(NetBoxModelForm):
device = DynamicModelChoiceField(
queryset=Device.objects.all()
Expand Down Expand Up @@ -72,57 +73,68 @@ class Meta:
#
# Filter forms
#
# class StoragePoolAllocationFilterForm(NetBoxModelFilterSetForm):
# model = StoragePoolAllocation
# storage_pool = forms.ModelMultipleChoiceField(
# queryset=StoragePool.objects.all(),
# required=False
# )
# name = forms.CharField(
# required=False
# )
# allocation_type = forms.MultipleChoiceField(
# choices=AllocationTypes,
# required=False
# )

class StoragePoolFilterForm(NetBoxModelFilterSetForm):
model = StoragePool
device = DynamicModelMultipleChoiceField(
queryset=Device.objects.all(),
required=False
)
name = forms.CharField(
required=False
)

# class StorageSessionFilterForm(NetBoxModelFilterSetForm):
# model = StorageSession
# storage_pool_allocation = forms.ModelMultipleChoiceField(
# queryset=StoragePoolAllocation.objects.all(),
# required=False
# )
# name = forms.CharField(
# required=False
# )
# session_type = forms.MultipleChoiceField(
# choices=SessionTypes,
# required=False
# )
# source = DynamicModelChoiceField(
# queryset=IPAddress.objects.all(),
# required=False
# )
# destination = DynamicModelChoiceField(
# queryset=IPAddress.objects.all(),
# required=False
# )

class LUNFilterForm(NetBoxModelFilterSetForm):
model = LUN
storage_pool = DynamicModelMultipleChoiceField(
queryset=StoragePool.objects.all(),
required=False
)
name = forms.CharField(
required=False
)

# class StorageSpaceAllocationFilterForm(NetBoxModelFilterSetForm):
# model = StorageSpaceAllocation
# storage_pool_allocation = forms.ModelMultipleChoiceField(
# queryset=StoragePoolAllocation.objects.all(),
# required=False
# )
# vm = DynamicModelChoiceField(
# queryset=VirtualMachine.objects.all(),
# required=False
# )
# name = forms.CharField(
# required=False
# )

class DatastoreFilterForm(NetBoxModelFilterSetForm):
model = Datastore
lun = DynamicModelMultipleChoiceField(
queryset=LUN.objects.all(),
required=False
)
name = forms.CharField(
required=False
)


class StorageSessionFilterForm(NetBoxModelFilterSetForm):
model = StorageSession
cluster = DynamicModelMultipleChoiceField(
queryset=Cluster.objects.all(),
required=False
)
datastores = DynamicModelMultipleChoiceField(
queryset=Datastore.objects.all(),
required=False
)
name = forms.CharField(
required=False
)


class VMDKFilterForm(NetBoxModelFilterSetForm):
model = VMDK
datastore = DynamicModelMultipleChoiceField(
queryset=Datastore.objects.all(),
required=False
)
vm = DynamicModelMultipleChoiceField(
queryset=VirtualMachine.objects.all(),
required=False
)
name = forms.CharField(
required=False
)


# #
Expand Down
18 changes: 10 additions & 8 deletions netbox_storage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def get_extra_context(self, request, instance):
class StoragePoolListView(generic.ObjectListView):
queryset = models.StoragePool.objects.all()
table = tables.StoragePoolTable
filterset = filtersets.StoragePoolFilterSet
filterset_form = forms.StoragePoolFilterForm


class StoragePoolEditView(generic.ObjectEditView):
Expand Down Expand Up @@ -49,8 +51,8 @@ class LUNView(generic.ObjectView):
class LUNListView(generic.ObjectListView):
queryset = models.LUN.objects.all()
table = tables.LUNTable
# filterset = filtersets.StorageLUNFilterSet
# filterset_form = forms.StorageLUNFilterForm
filterset = filtersets.LUNFilterSet
filterset_form = forms.LUNFilterForm


class LUNEditView(generic.ObjectEditView):
Expand Down Expand Up @@ -85,8 +87,8 @@ def get_extra_context(self, request, instance):
class DatastoreListView(generic.ObjectListView):
queryset = models.Datastore.objects.all()
table = tables.DatastoreTable
# filterset = filtersets.StorageLUNGroupFilterSet
# filterset_form = forms.StorageLUNGroupFilterForm
filterset = filtersets.DatastoreFilterSet
filterset_form = forms.DatastoreFilterForm


class DatastoreEditView(generic.ObjectEditView):
Expand All @@ -109,8 +111,8 @@ class StorageSessionView(generic.ObjectView):
class StorageSessionListView(generic.ObjectListView):
queryset = models.StorageSession.objects.all()
table = tables.StorageSessionTable
# filterset = filtersets.StorageSessionFilterSet
# filterset_form = forms.StorageSessionFilterForm
filterset = filtersets.StorageSessionFilterSet
filterset_form = forms.StorageSessionFilterForm


class StorageSessionEditView(generic.ObjectEditView):
Expand All @@ -133,8 +135,8 @@ class VMDKView(generic.ObjectView):
class VMDKListView(generic.ObjectListView):
queryset = models.VMDK.objects.all()
table = tables.VMDKTable
# filterset = filtersets.StorageSessionFilterSet
# filterset_form = forms.StorageSessionFilterForm
filterset = filtersets.VMDKFilterSet
filterset_form = forms.VMDKFilterForm


class VMDKEditView(generic.ObjectEditView):
Expand Down

0 comments on commit eca527d

Please sign in to comment.