Skip to content

Commit

Permalink
adds vms tab on device object view #15328
Browse files Browse the repository at this point in the history
  • Loading branch information
abhi1693 authored and jeremystretch committed May 9, 2024
1 parent 2a06e19 commit 08923d7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
from utilities.query import count_related
from utilities.query_functions import CollateAsChar
from utilities.views import GetReturnURLMixin, ObjectPermissionRequiredMixin, ViewTab, register_model_view
from virtualization.filtersets import VirtualMachineFilterSet
from virtualization.models import VirtualMachine
from virtualization.tables import VirtualMachineTable
from . import filtersets, forms, tables
from .choices import DeviceFaceChoices
from .models import *
Expand Down Expand Up @@ -2085,6 +2087,25 @@ def get_extra_context(self, request, instance):
}


@register_model_view(Device, 'virtual-machines')
class DeviceVirtualMachinesView(generic.ObjectChildrenView):
queryset = Device.objects.all()
child_model = VirtualMachine
table = VirtualMachineTable
filterset = VirtualMachineFilterSet
template_name = 'generic/object_children.html'
tab = ViewTab(
label=_('Virtual Machines'),
badge=lambda obj: VirtualMachine.objects.filter(cluster=obj.cluster, device=obj).count(),
weight=2200,
hide_if_empty=True,
permission='virtualization.view_virtualmachine'
)

def get_children(self, request, parent):
return self.child_model.objects.restrict(request.user, 'view').filter(cluster=parent.cluster, device=parent)


class DeviceBulkImportView(generic.BulkImportView):
queryset = Device.objects.all()
model_form = forms.DeviceImportForm
Expand Down

0 comments on commit 08923d7

Please sign in to comment.