mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
* Closes #8232: Add color show full 100% utilization * change rounding * change rounding * fix hard code html * format
This commit is contained in:
parent
421f5a03aa
commit
1278429518
@ -412,7 +412,7 @@ class Rack(PrimaryModel):
|
||||
available_units.remove(u)
|
||||
|
||||
occupied_unit_count = self.u_height - len(available_units)
|
||||
percentage = int(float(occupied_unit_count) / self.u_height * 100)
|
||||
percentage = float(occupied_unit_count) / self.u_height * 100
|
||||
|
||||
return percentage
|
||||
|
||||
|
@ -248,7 +248,7 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
|
||||
"""
|
||||
queryset = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
||||
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
|
||||
utilization = int(float(child_prefixes.size) / self.prefix.size * 100)
|
||||
utilization = float(child_prefixes.size) / self.prefix.size * 100
|
||||
|
||||
return min(utilization, 100)
|
||||
|
||||
@ -548,7 +548,7 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
|
||||
vrf=self.vrf
|
||||
)
|
||||
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
|
||||
utilization = int(float(child_prefixes.size) / self.prefix.size * 100)
|
||||
utilization = float(child_prefixes.size) / self.prefix.size * 100
|
||||
else:
|
||||
# Compile an IPSet to avoid counting duplicate IPs
|
||||
child_ips = netaddr.IPSet(
|
||||
@ -558,7 +558,7 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
|
||||
prefix_size = self.prefix.size
|
||||
if self.prefix.version == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
|
||||
prefix_size -= 2
|
||||
utilization = int(float(child_ips.size) / prefix_size * 100)
|
||||
utilization = float(child_ips.size) / prefix_size * 100
|
||||
|
||||
return min(utilization, 100)
|
||||
|
||||
|
@ -12,10 +12,10 @@
|
||||
class="progress-bar {{ bar_class }}"
|
||||
style="width: {{ utilization }}%;"
|
||||
>
|
||||
{% if utilization >= 25 %}{{ utilization }}%{% endif %}
|
||||
{% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %}
|
||||
</div>
|
||||
{% if utilization < 25 %}
|
||||
<span class="ps-1">{{ utilization }}%</span>
|
||||
<span class="ps-1">{{ utilization|floatformat:-2 }}%</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
@ -389,7 +389,9 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
|
||||
"""
|
||||
Display a horizontal bar graph indicating a percentage of utilization.
|
||||
"""
|
||||
if danger_threshold and utilization >= danger_threshold:
|
||||
if utilization == 100:
|
||||
bar_class = 'bg-secondary'
|
||||
elif danger_threshold and utilization >= danger_threshold:
|
||||
bar_class = 'bg-danger'
|
||||
elif warning_threshold and utilization >= warning_threshold:
|
||||
bar_class = 'bg-warning'
|
||||
|
Loading…
Reference in New Issue
Block a user