Selaa lähdekoodia

Closes #3297: Include reserved units when calculating rack utilization

Jeremy Stretch 6 vuotta sitten
vanhempi
commit
f54774f6a1
3 muutettua tiedostoa jossa 19 lisäystä ja 3 poistoa
  1. 1 0
      CHANGELOG.md
  2. 14 3
      netbox/dcim/models.py
  3. 4 0
      netbox/templates/dcim/rack.html

+ 1 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@ v2.6.5 (FUTURE)
 
 ## Enhancements
 
+* [#3297](https://github.com/netbox-community/netbox/issues/3297) -  Include reserved units when calculating rack utilization
 * [#3347](https://github.com/netbox-community/netbox/issues/3347) -  Extend upgrade script to automatically remove stale content types
 * [#3352](https://github.com/netbox-community/netbox/issues/3352) -  Enable filtering changelog API by `changed_object_id`
 * [#3524](https://github.com/netbox-community/netbox/issues/3524) -  Enable bulk editing of power outlet/power port associations

+ 14 - 3
netbox/dcim/models.py

@@ -732,10 +732,21 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
 
     def get_utilization(self):
         """
-        Determine the utilization rate of the rack and return it as a percentage.
+        Determine the utilization rate of the rack and return it as a percentage. Occupied and reserved units both count
+        as utilized.
         """
-        u_available = len(self.get_available_units())
-        return int(float(self.u_height - u_available) / self.u_height * 100)
+        # Determine unoccupied units
+        available_units = self.get_available_units()
+
+        # Remove reserved units
+        for u in self.get_reserved_units():
+            if u in available_units:
+                available_units.remove(u)
+
+        occupied_unit_count = self.u_height - len(available_units)
+        percentage = int(float(occupied_unit_count) / self.u_height * 100)
+
+        return percentage
 
     def get_power_utilization(self):
         """

+ 4 - 0
netbox/templates/dcim/rack.html

@@ -135,6 +135,10 @@
                         <a href="{% url 'dcim:device_list' %}?rack_id={{ rack.id }}">{{ rack.devices.count }}</a>
                     </td>
                 </tr>
+                    <tr>
+                        <td>Utilization</td>
+                        <td>{% utilization_graph rack.get_utilization %}</td>
+                    </tr>
             </table>
         </div>
         <div class="panel panel-default">