Include prefix utilization in API/model #4999

Closed
opened 2025-12-29 19:23:02 +01:00 by adam · 4 comments
Owner

Originally created by @PieterL75 on GitHub (Jun 15, 2021).

NetBox version

v2.11.6

Feature type

Data model extension

Proposed functionality

Currently, the prefix utilization is calculated after the database query has been made.
It would be great iw that utilization (in percent) is a value in the API of the prefix model.

Use case

This way, we could filter out 100% used prefixes when using ObjectVar dropdowns or other ways of programmatic selecting prefixes with available space, without the need for extra coding and database queries

Database changes

As per @jeremystretch : This could be changed, as we did with storing prefix depth and child count in #6087

External dependencies

No response

Originally created by @PieterL75 on GitHub (Jun 15, 2021). ### NetBox version v2.11.6 ### Feature type Data model extension ### Proposed functionality Currently, the prefix utilization is calculated after the database query has been made. It would be great iw that utilization (in percent) is a value in the API of the prefix model. ### Use case This way, we could filter out 100% used prefixes when using ObjectVar dropdowns or other ways of programmatic selecting prefixes with available space, without the need for extra coding and database queries ### Database changes As per @jeremystretch : This could be changed, as we did with storing prefix depth and child count in #6087 ### External dependencies _No response_
adam added the type: featurepending closurestatus: under review labels 2025-12-29 19:23:02 +01:00
adam closed this issue 2025-12-29 19:23:02 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 15, 2021):

There are two approaches to this:

  1. Pre-render and store the utilization for prefixes as changes are made in NetBox, then include this value in the API serializer
  2. Extend the serializer to call the get_utilization() method on demand

IMO the first option, while more challenging to implement, would be the preferred solution, as it also knocks out a good amount of overhead when viewing the prefixes list. The second option, because of the additional overhead it would impose on REST API requests, would probably need some mechanism to toggle its inclusion (similar to what we currently do with device/VM config contexts). I'd prefer to avoid that pattern where possible.

@jeremystretch commented on GitHub (Jun 15, 2021): There are two approaches to this: 1. Pre-render and store the utilization for prefixes as changes are made in NetBox, then include this value in the API serializer 2. Extend the serializer to call the `get_utilization()` method on demand IMO the first option, while more challenging to implement, would be the preferred solution, as it also knocks out a good amount of overhead when viewing the prefixes list. The second option, because of the additional overhead it would impose on REST API requests, would probably need some mechanism to toggle its inclusion (similar to what we currently do with device/VM config contexts). I'd prefer to avoid that pattern where possible.
Author
Owner

@github-actions[bot] commented on GitHub (Aug 15, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 15, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Sep 15, 2021):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Sep 15, 2021): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Author
Owner

@zombah commented on GitHub (Sep 22, 2021):

@jeremystretch I like the idea to be able get prefix utilization via api, if this feature acceptable i want volunteer to devel pr for this

@zombah commented on GitHub (Sep 22, 2021): @jeremystretch I like the idea to be able get prefix utilization via api, if this feature acceptable i want volunteer to devel pr for this
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4999