Răsfoiți Sursa

Closes #6620: Show assigned VMs count under device role view

jeremystretch 4 ani în urmă
părinte
comite
4292d88a92

+ 4 - 0
docs/release-notes/version-2.11.md

@@ -2,6 +2,10 @@
 
 ## v2.11.8 (FUTURE)
 
+### Enhancements
+
+* [#6620](https://github.com/netbox-community/netbox/issues/6620) - Show assigned VMs count under device role view
+
 ### Bug Fixes
 
 * [#6626](https://github.com/netbox-community/netbox/issues/6626) - Fix site field on VM search form; add site group

+ 2 - 0
netbox/dcim/views.py

@@ -1169,6 +1169,8 @@ class DeviceRoleView(generic.ObjectView):
 
         return {
             'devices_table': devices_table,
+            'device_count': Device.objects.filter(device_role=instance).count(),
+            'virtualmachine_count': VirtualMachine.objects.filter(role=instance).count(),
         }
 
 

+ 11 - 1
netbox/templates/dcim/devicerole.html

@@ -42,7 +42,17 @@
         <tr>
           <td>Devices</td>
           <td>
-            <a href="{% url 'dcim:device_list' %}?role_id={{ object.pk }}">{{ devices_table.rows|length }}</a>
+            <a href="{% url 'dcim:device_list' %}?role_id={{ object.pk }}">{{ device_count }}</a>
+          </td>
+        </tr>
+        <tr>
+          <td>Virtual Machines</td>
+          <td>
+            {% if object.vm_role %}
+              <a href="{% url 'virtualization:virtualmachine_list' %}?role_id={{ object.pk }}">{{ virtualmachine_count }}</a>
+            {% else %}
+              &mdash;
+            {% endif %}
           </td>
         </tr>
       </table>