netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Add 'utilization' field to IPRangeSerializer

Open icovada opened this issue 1 year ago • 1 comments

NetBox version

v3.7.4

Feature type

Change to existing functionality

Proposed functionality

Show the "utilization" field in the API response for IPRange

Use case

Allowing users to keep track of IP Range utilization via API

Database changes

None

External dependencies

None

icovada avatar Mar 15 '24 09:03 icovada

Code already existing at https://github.com/netbox-community/netbox/commit/6f4e16d25a401a7ec1ee0f6c302f7c518a24365a

Waiting to be assigned this issue to create a PR

icovada avatar Mar 15 '24 09:03 icovada

It is not sufficient to merely add the utilization field to the serializer, or this would have already been done. As it stands, your change would effect a new database query to fetch all the IP addresses for each individual IP range returned in an API response. (Take a look at the utilization property defined on the IPRange mode.) This would substantially degrade performance.

This is somewhat similar to #7845, but might be doable by annotating the count of IP addresses for each range on the queryset. @icovada would you like to own that work?

jeremystretch avatar Apr 03 '24 13:04 jeremystretch