|
@@ -1,4 +1,5 @@
|
|
|
from django.contrib import messages
|
|
from django.contrib import messages
|
|
|
|
|
+from django.contrib.contenttypes.models import ContentType
|
|
|
from django.db import transaction
|
|
from django.db import transaction
|
|
|
from django.db.models import Prefetch, Sum
|
|
from django.db.models import Prefetch, Sum
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
@@ -10,7 +11,7 @@ from dcim.forms import DeviceFilterForm
|
|
|
from dcim.models import Device
|
|
from dcim.models import Device
|
|
|
from dcim.tables import DeviceTable
|
|
from dcim.tables import DeviceTable
|
|
|
from extras.views import ObjectConfigContextView, ObjectRenderConfigView
|
|
from extras.views import ObjectConfigContextView, ObjectRenderConfigView
|
|
|
-from ipam.models import IPAddress
|
|
|
|
|
|
|
+from ipam.models import IPAddress, VLANGroup
|
|
|
from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
|
|
from ipam.tables import InterfaceVLANTable, VLANTranslationRuleTable
|
|
|
from netbox.constants import DEFAULT_ACTION_PERMISSIONS
|
|
from netbox.constants import DEFAULT_ACTION_PERMISSIONS
|
|
|
from netbox.views import generic
|
|
from netbox.views import generic
|
|
@@ -168,15 +169,28 @@ class ClusterListView(generic.ObjectListView):
|
|
|
|
|
|
|
|
|
|
|
|
|
@register_model_view(Cluster)
|
|
@register_model_view(Cluster)
|
|
|
-class ClusterView(generic.ObjectView):
|
|
|
|
|
|
|
+class ClusterView(GetRelatedModelsMixin, generic.ObjectView):
|
|
|
queryset = Cluster.objects.all()
|
|
queryset = Cluster.objects.all()
|
|
|
|
|
|
|
|
def get_extra_context(self, request, instance):
|
|
def get_extra_context(self, request, instance):
|
|
|
- return instance.virtual_machines.aggregate(
|
|
|
|
|
- vcpus_sum=Sum('vcpus'),
|
|
|
|
|
- memory_sum=Sum('memory'),
|
|
|
|
|
- disk_sum=Sum('disk')
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ return {
|
|
|
|
|
+ **instance.virtual_machines.aggregate(
|
|
|
|
|
+ vcpus_sum=Sum('vcpus'),
|
|
|
|
|
+ memory_sum=Sum('memory'),
|
|
|
|
|
+ disk_sum=Sum('disk')
|
|
|
|
|
+ ),
|
|
|
|
|
+ 'related_models': self.get_related_models(
|
|
|
|
|
+ request,
|
|
|
|
|
+ instance,
|
|
|
|
|
+ omit=(),
|
|
|
|
|
+ extra=(
|
|
|
|
|
+ (VLANGroup.objects.restrict(request.user, 'view').filter(
|
|
|
|
|
+ scope_type=ContentType.objects.get_for_model(Cluster),
|
|
|
|
|
+ scope_id=instance.pk
|
|
|
|
|
+ ), 'cluster'),
|
|
|
|
|
+ )
|
|
|
|
|
+ ),
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
@register_model_view(Cluster, 'virtualmachines', path='virtual-machines')
|
|
@register_model_view(Cluster, 'virtualmachines', path='virtual-machines')
|