From c9eb8c5e9738c18a0edbd5adfa330b1bc0d8af2d Mon Sep 17 00:00:00 2001 From: bellwood Date: Fri, 15 Jul 2016 14:29:19 -0400 Subject: [PATCH] update for rack utilization / space used --- netbox/dcim/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 8bf97224c..e435be61e 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -342,7 +342,19 @@ class Rack(CreatedUpdatedModel): def get_0u_devices(self): return self.devices.filter(position=0) + def get_used_units(self): + """ + Determine how many rack units are used considering both faces of the rack. + """ + used_units = int(len(self.get_available_units(u_height=1, rack_face=None, exclude=list()))) + return int(self.u_height - used_units) + def get_utilization(self): + """ + Determine the utilization rate of the rack and return it as a percentage. + """ + num_available_units = len(self.get_available_units(u_height=1, rack_face=None, exclude=list())) + return int(float(self.u_height - num_available_units) / self.u_height * 100) # # Device Types #