diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cd8eb5e8..bb24017bc 100644 --- a/CHANGELOG.md +++ b/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 diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 302056edc..5ffd15842 100644 --- a/netbox/dcim/models.py +++ b/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): """ diff --git a/netbox/templates/dcim/rack.html b/netbox/templates/dcim/rack.html index 60a70c36c..2a347e6e6 100644 --- a/netbox/templates/dcim/rack.html +++ b/netbox/templates/dcim/rack.html @@ -135,6 +135,10 @@ {{ rack.devices.count }} + + Utilization + {% utilization_graph rack.get_utilization %} +