From c9eb8c5e9738c18a0edbd5adfa330b1bc0d8af2d Mon Sep 17 00:00:00 2001 From: bellwood Date: Fri, 15 Jul 2016 14:29:19 -0400 Subject: [PATCH 1/5] 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 # From 02969d334f058b04f617d02f35345b9fa2694f1d Mon Sep 17 00:00:00 2001 From: bellwood Date: Fri, 15 Jul 2016 14:30:27 -0400 Subject: [PATCH 2/5] update for rack utilization / space used --- netbox/dcim/tables.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py index dc66c3ab1..aa325c27c 100644 --- a/netbox/dcim/tables.py +++ b/netbox/dcim/tables.py @@ -48,6 +48,16 @@ STATUS_ICON = """ {% endif %} """ +UTILIZATION_GRAPH = """ +{% with record.get_utilization as percentage %} +
+ {% if percentage < 15 %}{{ percentage }}%{% endif %} +
+ {% if percentage >= 15 %}{{ percentage }}%{% endif %} +
+
+{% # # Sites @@ -98,6 +108,8 @@ class RackTable(BaseTable): facility_id = tables.Column(verbose_name='Facility ID') u_height = tables.Column(verbose_name='Height (U)') devices = tables.Column(accessor=Accessor('device_count'), verbose_name='Devices') + u_used = tables.Column(accessor=Accessor('get_used_units'), verbose_name='Space Used') + utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='Utilization') class Meta(BaseTable.Meta): model = Rack From b6d1819056315800e5d0863f8f55dbd08b48aa78 Mon Sep 17 00:00:00 2001 From: bellwood Date: Fri, 15 Jul 2016 17:09:22 -0400 Subject: [PATCH 3/5] fix PEP8 error --- netbox/dcim/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index e435be61e..169ddfbd1 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -355,6 +355,8 @@ class Rack(CreatedUpdatedModel): """ 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 # From de1e8a70dd006b7566dd31e1a7577afe4a55184a Mon Sep 17 00:00:00 2001 From: bellwood Date: Fri, 15 Jul 2016 17:11:45 -0400 Subject: [PATCH 4/5] fix enclosure and PEP8 errors --- netbox/dcim/tables.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/tables.py b/netbox/dcim/tables.py index aa325c27c..69c350e35 100644 --- a/netbox/dcim/tables.py +++ b/netbox/dcim/tables.py @@ -57,7 +57,9 @@ UTILIZATION_GRAPH = """ {% if percentage >= 15 %}{{ percentage }}%{% endif %} -{% +{% endwith %} +""" + # # Sites From 8762c738fdffaa0271ca23d0e38457f2ef7a9ae7 Mon Sep 17 00:00:00 2001 From: bellwood Date: Fri, 15 Jul 2016 17:17:57 -0400 Subject: [PATCH 5/5] PEP8 / whitespace, blah --- netbox/dcim/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/dcim/models.py b/netbox/dcim/models.py index 169ddfbd1..317e757b8 100644 --- a/netbox/dcim/models.py +++ b/netbox/dcim/models.py @@ -355,8 +355,8 @@ class Rack(CreatedUpdatedModel): """ 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 #