mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
Fixes inconsistent return; adds discrete arguments
This commit is contained in:
parent
d106a2e711
commit
ca2b0dd91c
@ -562,7 +562,7 @@ class Rack(ChangeLoggedModel, CustomFieldModel):
|
|||||||
if power_stats:
|
if power_stats:
|
||||||
allocated_draw_total = sum(x['allocated_draw_total'] or 0 for x in power_stats)
|
allocated_draw_total = sum(x['allocated_draw_total'] or 0 for x in power_stats)
|
||||||
available_power_total = sum(x['available_power'] for x in power_stats)
|
available_power_total = sum(x['available_power'] for x in power_stats)
|
||||||
return int(allocated_draw_total / available_power_total * 100) or (0, 0)
|
return (allocated_draw_total, available_power_total) or (0, 0)
|
||||||
return (0, 0)
|
return (0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ RIR_UTILIZATION = """
|
|||||||
|
|
||||||
UTILIZATION_GRAPH = """
|
UTILIZATION_GRAPH = """
|
||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
{% if record.pk %}{% utilization_graph record.get_utilization %}{% else %}—{% endif %}
|
{% if record.pk %}{% utilization_graph record.get_utilization[0], record.get_utilization[1] %}{% else %}—{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ROLE_PREFIX_COUNT = """
|
ROLE_PREFIX_COUNT = """
|
||||||
|
@ -152,7 +152,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Utilization</td>
|
<td>Utilization</td>
|
||||||
<td>{% utilization_graph rack.get_utilization %}</td>
|
<td>{% utilization_graph rack.get_utilization[0] rack.get_utilization[1] %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -183,7 +183,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Utilization</td>
|
<td>Utilization</td>
|
||||||
<td>{% utilization_graph prefix.get_utilization %}</td>
|
<td>{% utilization_graph prefix.get_utilization[0] prefix.get_utilization[1] %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -230,22 +230,22 @@ def querystring(request, **kwargs):
|
|||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
|
@register.inclusion_tag('utilities/templatetags/utilization_graph.html')
|
||||||
def utilization_graph(data_input, warning_threshold=75, danger_threshold=90):
|
def utilization_graph(used_count, total, warning_threshold=75, danger_threshold=90):
|
||||||
"""
|
"""
|
||||||
Display a horizontal bar graph indicating a percentage of utilization.
|
Display a horizontal bar graph indicating a percentage of utilization.
|
||||||
"""
|
"""
|
||||||
# Check for possible division by zero error
|
# Check for possible division by zero error
|
||||||
if data_input[1] == 0:
|
if total == 0:
|
||||||
utilization = 0
|
utilization = 0
|
||||||
else:
|
else:
|
||||||
utilization = int(float(data_input[0]) / data_input[1] * 100)
|
utilization = int(float(used_count) / total * 100)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'utilization': utilization,
|
'utilization': utilization,
|
||||||
'warning_threshold': warning_threshold,
|
'warning_threshold': warning_threshold,
|
||||||
'danger_threshold': danger_threshold,
|
'danger_threshold': danger_threshold,
|
||||||
'utilization_count': data_input[0],
|
'utilization_count': used_count,
|
||||||
'total_count': data_input[1],
|
'total_count': total,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user