mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-26 18:38:38 -06:00
Adds title to Prefix utilization
This commit is contained in:
parent
0d27abc6fc
commit
fcc5fd6e31
@ -559,14 +559,14 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|||||||
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])
|
||||||
return int(float(child_prefixes.size) / self.prefix.size * 100)
|
return (int(float(child_prefixes.size) / self.prefix.size * 100), child_prefixes.size, self.prefix.size)
|
||||||
else:
|
else:
|
||||||
# Compile an IPSet to avoid counting duplicate IPs
|
# Compile an IPSet to avoid counting duplicate IPs
|
||||||
child_count = netaddr.IPSet([ip.address.ip for ip in self.get_child_ips()]).size
|
child_count = netaddr.IPSet([ip.address.ip for ip in self.get_child_ips()]).size
|
||||||
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
|
||||||
return int(float(child_count) / prefix_size * 100)
|
return (int(float(child_count) / prefix_size * 100), child_count, prefix_size)
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
|
||||||
|
@ -179,7 +179,8 @@ class TestPrefix(TestCase):
|
|||||||
Prefix(prefix=netaddr.IPNetwork('10.0.0.0/26')),
|
Prefix(prefix=netaddr.IPNetwork('10.0.0.0/26')),
|
||||||
Prefix(prefix=netaddr.IPNetwork('10.0.0.128/26')),
|
Prefix(prefix=netaddr.IPNetwork('10.0.0.128/26')),
|
||||||
))
|
))
|
||||||
self.assertEqual(prefix.get_utilization(), 50)
|
self.assertEqual(prefix.get_utilization()[0], 50)
|
||||||
|
self.assertEqual(prefix.get_utilization(), (50, 128, 256))
|
||||||
|
|
||||||
# Non-container Prefix
|
# Non-container Prefix
|
||||||
prefix.status = PrefixStatusChoices.STATUS_ACTIVE
|
prefix.status = PrefixStatusChoices.STATUS_ACTIVE
|
||||||
@ -188,7 +189,8 @@ class TestPrefix(TestCase):
|
|||||||
# Create 32 IPAddresses within the Prefix
|
# Create 32 IPAddresses within the Prefix
|
||||||
[IPAddress(address=netaddr.IPNetwork('10.0.0.{}/24'.format(i))) for i in range(1, 33)]
|
[IPAddress(address=netaddr.IPNetwork('10.0.0.{}/24'.format(i))) for i in range(1, 33)]
|
||||||
)
|
)
|
||||||
self.assertEqual(prefix.get_utilization(), 12) # ~= 12%
|
self.assertEqual(prefix.get_utilization()[0], 12) # ~= 12%
|
||||||
|
self.assertEqual(prefix.get_utilization(), (12, 30, 256))
|
||||||
|
|
||||||
#
|
#
|
||||||
# Uniqueness enforcement tests
|
# Uniqueness enforcement tests
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<div class="progress text-center">
|
<div title="Used: {{ util_count }}
Available: {{ num_available }}" class="progress text-center">
|
||||||
{% if utilization < 30 %}<span style="font-size: 12px;">{{ utilization }}%</span>{% endif %}
|
{% if utilization < 30 %}<span style="font-size: 12px;">{{ utilization }}%</span>{% endif %}
|
||||||
<div class="progress-bar progress-bar-{% if utilization >= danger_threshold %}danger{% elif utilization >= warning_threshold %}warning{% else %}success{% endif %}"
|
<div class="progress-bar progress-bar-{% if utilization >= danger_threshold %}danger{% elif utilization >= warning_threshold %}warning{% else %}success{% endif %}"
|
||||||
role="progressbar" aria-valuenow="{{ utilization }}" aria-valuemin="0" aria-valuemax="100" style="width: {% if utilization > 100 %}100{% else %}{{ utilization }}{% endif %}%">
|
role="progressbar" aria-valuenow="{{ utilization }}" aria-valuemin="0" aria-valuemax="100" style="width: {% if utilization > 100 %}100{% else %}{{ utilization }}{% endif %}%">
|
||||||
|
@ -235,9 +235,11 @@ 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.
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
'utilization': utilization,
|
'utilization': utilization[0],
|
||||||
'warning_threshold': warning_threshold,
|
'warning_threshold': warning_threshold,
|
||||||
'danger_threshold': danger_threshold,
|
'danger_threshold': danger_threshold,
|
||||||
|
'util_count': utilization[1],
|
||||||
|
'num_available': utilization[2],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user