mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
Merge 8762c738fd
into 0bd2aa9289
This commit is contained in:
commit
4262bae1c9
@ -360,6 +360,20 @@ 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
|
||||
|
@ -48,6 +48,18 @@ STATUS_ICON = """
|
||||
{% endif %}
|
||||
"""
|
||||
|
||||
UTILIZATION_GRAPH = """
|
||||
{% with record.get_utilization as percentage %}
|
||||
<div class="progress text-center">
|
||||
{% if percentage < 15 %}<span style="font-size: 12px;">{{ percentage }}%</span>{% endif %}
|
||||
<div class="progress-bar progress-bar-{% if percentage >= 90 %}danger{% elif percentage >= 75 %}warning{% else %}success{% endif %}"
|
||||
role="progressbar" aria-valuenow="{{ percentage }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ percentage }}%">
|
||||
{% if percentage >= 15 %}{{ percentage }}%{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
"""
|
||||
|
||||
|
||||
#
|
||||
# Sites
|
||||
@ -98,6 +110,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
|
||||
|
Loading…
Reference in New Issue
Block a user