New API method for ip-addresses to get all parent prefixes like GUI #2761

Closed
opened 2025-12-29 18:21:50 +01:00 by adam · 3 comments
Owner

Originally created by @Renji-FR on GitHub (Jul 25, 2019).

Environment

  • Python version: 3.6.9
  • NetBox version: 59139502ac7d (v2.6.1)

Proposed Functionality

Create a new request (method) from ip-addresses API to get all parent prefixes like GUI.
Client can use built-in functions to get parent prefixes and avoid many API calls and many process to retrieve theses prefixes.

Use Case

From IP address, client would like retrieve all parent prefixes to retrieve after other informations like site.
Call:
curl -H "Accept: application/json; indent=4" -H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" "http://localhost:32768/api/ipam/ip-addresses/"
can return prefixes field like:

"prefixes":
{
    [
        "id": 1,
        "url": "http://localhost:32768/api/ipam/prefixes/1/",
        "name": "myPrefix",
        "slug": "myprefix",
    ],
    ...
}

Database Changes

Nothing change about database.

External Dependencies

Don't require any new dependency.

Originally created by @Renji-FR on GitHub (Jul 25, 2019). ### Environment * Python version: 3.6.9 * NetBox version: 59139502ac7d (v2.6.1) ### Proposed Functionality Create a new request (method) from ip-addresses API to get all parent prefixes like GUI. Client can use built-in functions to get parent prefixes and avoid many API calls and many process to retrieve theses prefixes. ### Use Case From IP address, client would like retrieve all parent prefixes to retrieve after other informations like site. Call: `curl -H "Accept: application/json; indent=4" -H "Authorization: Token 0123456789abcdef0123456789abcdef01234567" "http://localhost:32768/api/ipam/ip-addresses/"` can return prefixes field like: ```json "prefixes": { [ "id": 1, "url": "http://localhost:32768/api/ipam/prefixes/1/", "name": "myPrefix", "slug": "myprefix", ], ... } ``` ### Database Changes Nothing change about database. ### External Dependencies Don't require any new dependency.
adam closed this issue 2025-12-29 18:21:50 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 29, 2019):

You want the contains filter. Example: GET /api/ipam/prefixes/?contains=192.168.200.0/24 would return 192.168.0.0/16 and 192.168.128.0/18 as they both contain 192.168.200.0/24.

@jeremystretch commented on GitHub (Jul 29, 2019): You want the `contains` filter. Example: `GET /api/ipam/prefixes/?contains=192.168.200.0/24` would return 192.168.0.0/16 and 192.168.128.0/18 as they both _contain_ 192.168.200.0/24.
Author
Owner

@Renji-FR commented on GitHub (Jul 29, 2019):

@jeremystretch You use ipam/prefixes but my feature request use ipam/ip-addresses!
NetBox has built-in functions to retrieve parents prefixes from address.
GUI use it because from address page parent prefixes are returned.

To avoid many API calls, API can permit to retrieve parent prefixes from ip-addresses like GUI.

@Renji-FR commented on GitHub (Jul 29, 2019): @jeremystretch You use ipam/prefixes but my feature request use ipam/ip-addresses! NetBox has built-in functions to retrieve parents prefixes from address. GUI use it because from address page parent prefixes are returned. To avoid many API calls, API can permit to retrieve parent prefixes from ip-addresses like GUI.
Author
Owner

@Renji-FR commented on GitHub (Jul 29, 2019):

Your solution is correct only with VRF filter but we don't use built-in function.

@Renji-FR commented on GitHub (Jul 29, 2019): Your solution is correct only with VRF filter but we don't use built-in function.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2761