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
16.16k stars 2.59k forks source link

Add parent_prefix_id field to Prefix object / API #16636

Open tgoodsell-tempus opened 4 months ago

tgoodsell-tempus commented 4 months ago

NetBox version

v4.0.3

Feature type

Data model extension

Proposed functionality

Add a parent_prefix_id field to the Prefix API object which is populated with the ID value of the Parent Prefix object if it exists. This means the value would only be populated if this is a child of an actual created Prefix within the same VRF. Value would only be the direct parent (depth - 1 in the tree) value.

Use case

Currently, when you do a GET on a Prefix, you'll receive the children and _depth fields which help indicate where the Prefix is amongst a tier of next prefixes. However, you still must leverage a separate search function to find the particular parent prefix, when doing the API ops.

Adding this field would allow us to avoid needing to implement that search logic, which would be important for API clients performing Prefix management leveraging the hierarchical functions and the available prefix API.

Database changes

TBD: My first thought would be to add this onto the mechanism which populates _depth itself, just taking the ID of the _depth - 1 Prefix and adding that to the model via populating the new field. Otherwise we can leave the field as null.

External dependencies

No response

tgoodsell-tempus commented 4 months ago

Depending on if this idea is accepted, I would be willing to volunteer for implementation work.

arthanson commented 4 months ago

@tgoodsell-tempus good suggestion, there are some technical challenges behind it as it would be semi-blocked by #7845 would probably be done as part of that feature work.