mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 03:27:21 -06:00
12596 Add Allocated Resources to Cluster API (#17956)
* 12596 Add Allocated Resources to Cluster API * 12596 Add Allocated Resources to Cluster API * 12596 Add Allocated Resources to Cluster API * 12596 Add Allocated Resources to Cluster API * 12596 review changes * 12596 review changes
This commit is contained in:
parent
03d413565f
commit
75aeaab8ee
@ -59,6 +59,14 @@ class ClusterSerializer(NetBoxModelSerializer):
|
||||
)
|
||||
scope_id = serializers.IntegerField(allow_null=True, required=False, default=None)
|
||||
scope = serializers.SerializerMethodField(read_only=True)
|
||||
allocated_vcpus = serializers.DecimalField(
|
||||
read_only=True,
|
||||
max_digits=8,
|
||||
decimal_places=2,
|
||||
|
||||
)
|
||||
allocated_memory = serializers.IntegerField(read_only=True)
|
||||
allocated_disk = serializers.IntegerField(read_only=True)
|
||||
|
||||
# Related object counts
|
||||
device_count = RelatedObjectCountField('devices')
|
||||
@ -69,7 +77,7 @@ class ClusterSerializer(NetBoxModelSerializer):
|
||||
fields = [
|
||||
'id', 'url', 'display_url', 'display', 'name', 'type', 'group', 'status', 'tenant', 'scope_type', 'scope_id', 'scope',
|
||||
'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count',
|
||||
'virtualmachine_count',
|
||||
'virtualmachine_count', 'allocated_vcpus', 'allocated_memory', 'allocated_disk'
|
||||
]
|
||||
brief_fields = ('id', 'url', 'display', 'name', 'description', 'virtualmachine_count')
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.db.models import Sum
|
||||
from rest_framework.routers import APIRootView
|
||||
|
||||
from extras.api.mixins import ConfigContextQuerySetMixin, RenderConfigMixin
|
||||
@ -33,7 +34,11 @@ class ClusterGroupViewSet(NetBoxModelViewSet):
|
||||
|
||||
|
||||
class ClusterViewSet(NetBoxModelViewSet):
|
||||
queryset = Cluster.objects.all()
|
||||
queryset = Cluster.objects.prefetch_related('virtual_machines').annotate(
|
||||
allocated_vcpus=Sum('virtual_machines__vcpus'),
|
||||
allocated_memory=Sum('virtual_machines__memory'),
|
||||
allocated_disk=Sum('virtual_machines__disk'),
|
||||
)
|
||||
serializer_class = serializers.ClusterSerializer
|
||||
filterset_class = filtersets.ClusterFilterSet
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user