mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Fixes #6812: Limit reported prefix utilization to 100%
This commit is contained in:
parent
a1eb4dc807
commit
0c214932ba
@ -17,6 +17,7 @@
|
|||||||
* [#6778](https://github.com/netbox-community/netbox/issues/6778) - Rack reservation should display rack's location
|
* [#6778](https://github.com/netbox-community/netbox/issues/6778) - Rack reservation should display rack's location
|
||||||
* [#6780](https://github.com/netbox-community/netbox/issues/6780) - Include rack location in navigation breadcrumbs
|
* [#6780](https://github.com/netbox-community/netbox/issues/6780) - Include rack location in navigation breadcrumbs
|
||||||
* [#6794](https://github.com/netbox-community/netbox/issues/6794) - Fix device name display on device status view
|
* [#6794](https://github.com/netbox-community/netbox/issues/6794) - Fix device name display on device status view
|
||||||
|
* [#6812](https://github.com/netbox-community/netbox/issues/6812) - Limit reported prefix utilization to 100%
|
||||||
* [#6822](https://github.com/netbox-community/netbox/issues/6822) - Use consistent maximum value for interface MTU
|
* [#6822](https://github.com/netbox-community/netbox/issues/6822) - Use consistent maximum value for interface MTU
|
||||||
|
|
||||||
### Other Changes
|
### Other Changes
|
||||||
|
@ -181,7 +181,9 @@ class Aggregate(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])
|
||||||
return int(float(child_prefixes.size) / self.prefix.size * 100)
|
utilization = int(float(child_prefixes.size) / self.prefix.size * 100)
|
||||||
|
|
||||||
|
return min(utilization, 100)
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'webhooks')
|
||||||
@ -502,14 +504,16 @@ class Prefix(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])
|
||||||
return int(float(child_prefixes.size) / self.prefix.size * 100)
|
utilization = int(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_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)
|
utilization = int(float(child_count) / prefix_size * 100)
|
||||||
|
|
||||||
|
return min(utilization, 100)
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
|
Loading…
Reference in New Issue
Block a user