netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.92k stars 2.56k forks source link

Add Prefix utilization to API #9649

Open empusas opened 2 years ago

empusas commented 2 years ago

NetBox version

v3.2.6

Feature type

New functionality

Proposed functionality

Add the prefix utilization to the API. The utilization is a useful information for people who use the Netbox API for their own automation. The code to add is simple as the models.py for IPAM has already the required function used by the Web UI.

Code to add to the prefix serializer:

utilization = serializers.SerializerMethodField('get_utilization')

def get_utilization(self, obj):
    utilization = obj.get_utilization()
    return utilization

I am happy to make the changes and create a pull request if the feature is accepted.

Use case

API users get the utilization of a prefix in a percentage value. That would be helpful to create reports or get an overview about IP usage.

Database changes

NA

External dependencies

NA

jeremystretch commented 2 years ago

The manner in which prefix utilization is currently calculated is too inefficient to include by default in REST API responses. Marking this as blocked by #7845, which, if implemented, should make this feasible.