Prefix Utilization is Always 0% #1382

Closed
opened 2025-12-29 16:31:57 +01:00 by adam · 5 comments
Owner

Originally created by @girlpunk on GitHub (Nov 3, 2017).

Issue type

[ ] Feature request
[X] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.3
  • NetBox version: 2.2.4

Description

Just noticed this after upgrading to the latest version and adding some new prefixes to subnet an existing prefix. After doing so, the utilization for the new prefixes shows the correct number of IPs, but the percentage is always 0%.
This appears to be caused by the get_utilization() function's IPAddress filter.

Steps to reproduce

  1. Create a Prefix
  2. Add IPs to the prefix
  3. Subnet the prefix by adding a child prefix. The prefix correctly identifies the IPs already added, and shows them in the list and utilization count, but not the percentage.
Originally created by @girlpunk on GitHub (Nov 3, 2017). ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [X] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.3 * NetBox version: 2.2.4 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) --> ### Description Just noticed this after upgrading to the latest version and adding some new prefixes to subnet an existing prefix. After doing so, the utilization for the new prefixes shows the correct number of IPs, but the percentage is always 0%. This appears to be caused by the get_utilization() function's IPAddress filter. #### Steps to reproduce 1. Create a Prefix 1. Add IPs to the prefix 1. Subnet the prefix by adding a child prefix. The prefix correctly identifies the IPs already added, and shows them in the list and utilization count, but not the percentage.
adam added the type: bug label 2025-12-29 16:31:57 +01:00
adam closed this issue 2025-12-29 16:31:57 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 3, 2017):

Utilization is counted differently depending on whether the prefix is designated as a container:

    def get_utilization(self):
        """
        Determine the utilization of the prefix and return it as a percentage. For Prefixes with a status of
        "container", calculate utilization based on child prefixes. For all others, count child IP addresses.
        """

Which type of prefix are you looking at?

@jeremystretch commented on GitHub (Nov 3, 2017): Utilization is counted differently depending on whether the prefix is designated as a container: ``` def get_utilization(self): """ Determine the utilization of the prefix and return it as a percentage. For Prefixes with a status of "container", calculate utilization based on child prefixes. For all others, count child IP addresses. """ ``` Which type of prefix are you looking at?
Author
Owner

@girlpunk commented on GitHub (Nov 6, 2017):

The Utilization on the child prefixes is the one I'm looking at. I've already set the parent to a container, and its utilization is showing correctly. The top child prefix in the screenshot below (192.168.42.0/27) has 10 IPs assigned, so should be showing about 30% usage.

image

@girlpunk commented on GitHub (Nov 6, 2017): The Utilization on the child prefixes is the one I'm looking at. I've already set the parent to a container, and its utilization is showing correctly. The top child prefix in the screenshot below (192.168.42.0/27) has 10 IPs assigned, so should be showing about 30% usage. ![image](https://user-images.githubusercontent.com/161093/32439945-ee90d11a-c2e8-11e7-8bad-82896fa6bd97.png)
Author
Owner

@jeremystretch commented on GitHub (Nov 6, 2017):

I think I see what's happening. Did you create those ten IPs with a mask larger than /27 (e.g. /24)? If so, the net_contained_or_equal filter won't count them (because a /24 obviously cannot be contained by a /27). Granted, we probably want to see all IPs within a prefix even if their masks are "wrong." I'm going to change the lookup to net_host_contained, which will return all IPs in the given prefix regardless of mask. Hopefully this won't break anything for people; I can't think of a situation where it would.

@jeremystretch commented on GitHub (Nov 6, 2017): I think I see what's happening. Did you create those ten IPs with a mask larger than /27 (e.g. /24)? If so, the `net_contained_or_equal` filter won't count them (because a /24 obviously cannot be contained by a /27). Granted, we probably want to see _all_ IPs within a prefix even if their masks are "wrong." I'm going to change the lookup to `net_host_contained`, which will return all IPs in the given prefix regardless of mask. Hopefully this won't break anything for people; I can't think of a situation where it would.
Author
Owner

@girlpunk commented on GitHub (Nov 6, 2017):

Yes, the IPs were created with /24, because that's the mask in use by the hosts (the subnetting is just for allocation and organisation). That would make sense as to why they're not detected then. Does the count on the prefix page use the net_host_contained function, as that is correct?

@girlpunk commented on GitHub (Nov 6, 2017): Yes, the IPs were created with /24, because that's the mask in use by the hosts (the subnetting is just for allocation and organisation). That would make sense as to why they're not detected then. Does the count on the prefix page use the `net_host_contained` function, as that is correct?
Author
Owner

@jeremystretch commented on GitHub (Nov 6, 2017):

@cyberjacob Yes, the count was using net_host_contained but the get_utilization() method on the prefix was using net_contained_or_equal.

@jeremystretch commented on GitHub (Nov 6, 2017): @cyberjacob Yes, the count was using `net_host_contained` but the `get_utilization()` method on the prefix was using `net_contained_or_equal`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1382