Skip to content

Commit 735fa4a

Browse files
kkthxbye-codejeremystretch
authored andcommitted
Add summed resource card to cluster view
1 parent c7108bb commit 735fa4a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

netbox/templates/virtualization/cluster.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,37 @@ <h5 class="card-header">
5555
{% plugin_left_page object %}
5656
</div>
5757
<div class="col col-md-6">
58+
<div class="card">
59+
<h5 class="card-header">Allocated Resources</h5>
60+
<div class="card-body">
61+
<table class="table table-hover attr-table">
62+
<tr>
63+
<th scope="row"><i class="mdi mdi-gauge"></i> Virtual CPUs</th>
64+
<td>{{ vcpus_sum|placeholder }}</td>
65+
</tr>
66+
<tr>
67+
<th scope="row"><i class="mdi mdi-chip"></i> Memory</th>
68+
<td>
69+
{% if memory_sum %}
70+
{{ memory_sum|humanize_megabytes }}
71+
{% else %}
72+
{{ ''|placeholder }}
73+
{% endif %}
74+
</td>
75+
</tr>
76+
<tr>
77+
<th scope="row"><i class="mdi mdi-harddisk"></i> Disk Space</th>
78+
<td>
79+
{% if disk_sum %}
80+
{{ disk_sum }} GB
81+
{% else %}
82+
{{ ''|placeholder }}
83+
{% endif %}
84+
</td>
85+
</tr>
86+
</table>
87+
</div>
88+
</div>
5889
{% include 'inc/panels/custom_fields.html' %}
5990
{% include 'inc/panels/tags.html' %}
6091
{% include 'inc/panels/contacts.html' %}

netbox/virtualization/views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.contrib import messages
22
from django.db import transaction
3-
from django.db.models import Prefetch
3+
from django.db.models import Prefetch, Sum
44
from django.shortcuts import get_object_or_404, redirect, render
55
from django.urls import reverse
66
from django.utils.translation import gettext as _
@@ -169,6 +169,9 @@ class ClusterListView(generic.ObjectListView):
169169
class ClusterView(generic.ObjectView):
170170
queryset = Cluster.objects.all()
171171

172+
def get_extra_context(self, request, instance):
173+
return instance.virtual_machines.aggregate(vcpus_sum=Sum('vcpus'), memory_sum=Sum('memory'), disk_sum=Sum('disk'))
174+
172175

173176
@register_model_view(Cluster, 'virtualmachines', path='virtual-machines')
174177
class ClusterVirtualMachinesView(generic.ObjectChildrenView):

0 commit comments

Comments
 (0)