mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 04:58:16 -06:00
change rounding
This commit is contained in:
parent
d434c3d7e5
commit
497c325cc5
@ -248,9 +248,9 @@ class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
|
|||||||
"""
|
"""
|
||||||
queryset = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
queryset = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
||||||
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
|
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)
|
return utilization
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
@ -548,7 +548,7 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
|
|||||||
vrf=self.vrf
|
vrf=self.vrf
|
||||||
)
|
)
|
||||||
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
|
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:
|
else:
|
||||||
# Compile an IPSet to avoid counting duplicate IPs
|
# Compile an IPSet to avoid counting duplicate IPs
|
||||||
child_ips = netaddr.IPSet(
|
child_ips = netaddr.IPSet(
|
||||||
@ -558,9 +558,9 @@ class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
|
|||||||
prefix_size = self.prefix.size
|
prefix_size = self.prefix.size
|
||||||
if self.prefix.version == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
|
if self.prefix.version == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
|
||||||
prefix_size -= 2
|
prefix_size -= 2
|
||||||
utilization = int(float(child_ips.size) / prefix_size * 100)
|
utilization = float(child_ips.size) / prefix_size * 100
|
||||||
|
|
||||||
return min(utilization, 100)
|
return utilization
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
aria-valuemin="0"
|
aria-valuemin="0"
|
||||||
aria-valuemax="100"
|
aria-valuemax="100"
|
||||||
aria-valuenow="{{ utilization }}"
|
aria-valuenow="{{ utilization }}"
|
||||||
{% if is_full_danger %}
|
{% if utilization == 100 %}
|
||||||
class="progress-bar"
|
class="progress-bar"
|
||||||
style="width: {{ utilization }}%; background-color: #800080;"
|
style="width: {{ utilization }}%; background-color: #800080;"
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -17,10 +17,10 @@
|
|||||||
style="width: {{ utilization }}%;"
|
style="width: {{ utilization }}%;"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>
|
>
|
||||||
{% if utilization >= 25 %}{{ utilization }}%{% endif %}
|
{% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% if utilization < 25 %}
|
{% if utilization < 25 %}
|
||||||
<span class="ps-1">{{ utilization }}%</span>
|
<span class="ps-1">{{ utilization|floatformat:-2 }}%</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -389,9 +389,6 @@ def utilization_graph(utilization, 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.
|
||||||
"""
|
"""
|
||||||
is_full_danger = False
|
|
||||||
if utilization == 100:
|
|
||||||
is_full_danger = True
|
|
||||||
if danger_threshold and utilization >= danger_threshold:
|
if danger_threshold and utilization >= danger_threshold:
|
||||||
bar_class = 'bg-danger'
|
bar_class = 'bg-danger'
|
||||||
elif warning_threshold and utilization >= warning_threshold:
|
elif warning_threshold and utilization >= warning_threshold:
|
||||||
@ -400,11 +397,9 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
|
|||||||
bar_class = 'bg-success'
|
bar_class = 'bg-success'
|
||||||
else:
|
else:
|
||||||
bar_class = 'bg-gray'
|
bar_class = 'bg-gray'
|
||||||
is_full_danger = False
|
|
||||||
return {
|
return {
|
||||||
'utilization': utilization,
|
'utilization': utilization,
|
||||||
'bar_class': bar_class,
|
'bar_class': bar_class,
|
||||||
'is_full_danger': is_full_danger,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user