diff --git a/netbox/ipam/models/ip.py b/netbox/ipam/models/ip.py
index 81c3ef34a..8369b3c58 100644
--- a/netbox/ipam/models/ip.py
+++ b/netbox/ipam/models/ip.py
@@ -248,9 +248,9 @@ 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)
+ return utilization
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
@@ -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,9 +558,9 @@ 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)
+ return utilization
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
diff --git a/netbox/utilities/templates/helpers/utilization_graph.html b/netbox/utilities/templates/helpers/utilization_graph.html
index 04b0391bf..1d6bc44d6 100644
--- a/netbox/utilities/templates/helpers/utilization_graph.html
+++ b/netbox/utilities/templates/helpers/utilization_graph.html
@@ -9,7 +9,7 @@
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="{{ utilization }}"
- {% if is_full_danger %}
+ {% if utilization == 100 %}
class="progress-bar"
style="width: {{ utilization }}%; background-color: #800080;"
{% else %}
@@ -17,10 +17,10 @@
style="width: {{ utilization }}%;"
{% endif %}
>
- {% if utilization >= 25 %}{{ utilization }}%{% endif %}
+ {% if utilization >= 25 %}{{ utilization|floatformat:-2 }}%{% endif %}
{% if utilization < 25 %}
- {{ utilization }}%
+ {{ utilization|floatformat:-2 }}%
{% endif %}
-{% endif %}
\ No newline at end of file
+{% endif %}
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py
index cfba03b87..0e45cb581 100644
--- a/netbox/utilities/templatetags/helpers.py
+++ b/netbox/utilities/templatetags/helpers.py
@@ -389,9 +389,6 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
"""
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:
bar_class = 'bg-danger'
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'
else:
bar_class = 'bg-gray'
- is_full_danger = False
return {
'utilization': utilization,
'bar_class': bar_class,
- 'is_full_danger': is_full_danger,
}