Add the parent prefix to the ip-address query response via the api #2540

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

Originally created by @phurrelmann on GitHub (Apr 23, 2019).

Environment

  • Python version: 3.7.3 (dev), 3.5.3 (test)
  • NetBox version: 2.6-dev (dev), 2.5.10 (test)

Proposed Functionality

Currently when querying an ip-address via the API the response does not contain any reference to its parent prefix. The reference to the parent prefix should be present in the API response like it is visible in the WebUI. At least the id and the prefix should be included. Further prefix details could be easily retrieved via the prefix id then.

WebUI:
webui_ip-address

Current API-Response:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 5063,
      "family": {
        "value": 4,
        "label": "IPv4"
      },
      "address": "10.100.16.105/30",
      "vrf": null,
      "tenant": {
        "id": 2,
        "url": "http://127.0.0.1:8000/api/tenancy/tenants/2/",
        "name": "XXX",
        "slug": "xxx"
      },
      "status": {
        "value": 1,
        "label": "Active"
      },
      "role": null,
      "interface": null,
      "nat_inside": null,
      "nat_outside": null,
      "dns_name": "",
      "description": "xxx",
      "tags": [],
      "created": "2018-04-24",
      "last_updated": "2018-04-24T08:31:13.842911Z"
    }
  ]
}

Proposed API-Response:

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 5063,
      "family": {
        "value": 4,
        "label": "IPv4"
      },
      "address": "10.100.16.105/30",
      "vrf": null,
      "tenant": {
        "id": 2,
        "url": "http://127.0.0.1:8000/api/tenancy/tenants/2/",
        "name": "XXX",
        "slug": "xxx"
      },
      "status": {
        "value": 1,
        "label": "Active"
      },
      "parent_prefix": {
        "id": 611,
        "prefix": "10.100.16.104/30"
      },
      "role": null,
      "interface": null,
      "nat_inside": null,
      "nat_outside": null,
      "dns_name": "",
      "description": "xxx",
      "tags": [],
      "created": "2018-04-24",
      "last_updated": "2018-04-24T08:31:13.842911Z"
    }
  ]
}

Use Case

Using the API there is currently no direct connection/relation between an IP-address and its parent prefix. This enhancement would simplify the usage of the API and brings the API and WebUI in sync.

Real word Use-Case:
We have quite a lot of prefixes that contain BGP-cluster addresses with a /32 prefix length.
Due to the different prefix length (prefix vs. IP-address) it requires additional API calls to get the correct prefix for an IP-address and some additional logic is needed.

Database Changes

none, all information is already existing

External Dependencies

none

Originally created by @phurrelmann on GitHub (Apr 23, 2019). <!-- NOTE: This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.7.3 (dev), 3.5.3 (test) * NetBox version: 2.6-dev (dev), 2.5.10 (test) <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Currently when querying an ip-address via the API the response does not contain any reference to its parent prefix. The reference to the parent prefix should be present in the API response like it is visible in the WebUI. At least the id and the prefix should be included. Further prefix details could be easily retrieved via the prefix id then. WebUI: ![webui_ip-address](https://user-images.githubusercontent.com/10113716/56570945-3214ed00-65bc-11e9-868b-4ecd2bffa743.png) Current API-Response: ```yaml { "count": 1, "next": null, "previous": null, "results": [ { "id": 5063, "family": { "value": 4, "label": "IPv4" }, "address": "10.100.16.105/30", "vrf": null, "tenant": { "id": 2, "url": "http://127.0.0.1:8000/api/tenancy/tenants/2/", "name": "XXX", "slug": "xxx" }, "status": { "value": 1, "label": "Active" }, "role": null, "interface": null, "nat_inside": null, "nat_outside": null, "dns_name": "", "description": "xxx", "tags": [], "created": "2018-04-24", "last_updated": "2018-04-24T08:31:13.842911Z" } ] } ``` Proposed API-Response: ```yaml { "count": 1, "next": null, "previous": null, "results": [ { "id": 5063, "family": { "value": 4, "label": "IPv4" }, "address": "10.100.16.105/30", "vrf": null, "tenant": { "id": 2, "url": "http://127.0.0.1:8000/api/tenancy/tenants/2/", "name": "XXX", "slug": "xxx" }, "status": { "value": 1, "label": "Active" }, "parent_prefix": { "id": 611, "prefix": "10.100.16.104/30" }, "role": null, "interface": null, "nat_inside": null, "nat_outside": null, "dns_name": "", "description": "xxx", "tags": [], "created": "2018-04-24", "last_updated": "2018-04-24T08:31:13.842911Z" } ] } ``` <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Using the API there is currently no direct connection/relation between an IP-address and its parent prefix. This enhancement would simplify the usage of the API and brings the API and WebUI in sync. Real word Use-Case: We have quite a lot of prefixes that contain BGP-cluster addresses with a /32 prefix length. Due to the different prefix length (prefix vs. IP-address) it requires additional API calls to get the correct prefix for an IP-address and some additional logic is needed. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes none, all information is already existing <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies none
adam closed this issue 2025-12-29 18:19:48 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 23, 2019):

Using the API there is currently no direct connection/relation between an IP-address and its parent prefix.

This is because there is no direct relationship between them in the database. Whether an IP address belongs to a particular prefix is a function of its assigned VRF and address. This can change dynamically as prefixes are added, changed, and deleted, without any direct action taken on the IP address itself. Thus, a separate API call is necessary to retrieve all prefixes which contain a given IP (there are typically several parent prefixes forming a hierarchy).

@jeremystretch commented on GitHub (Apr 23, 2019): > Using the API there is currently no direct connection/relation between an IP-address and its parent prefix. This is because there is no direct relationship between them in the database. Whether an IP address belongs to a particular prefix is a function of its assigned VRF and address. This can change dynamically as prefixes are added, changed, and deleted, without any direct action taken on the IP address itself. Thus, a separate API call is necessary to retrieve all prefixes which contain a given IP (there are typically several parent prefixes forming a hierarchy).
Author
Owner

@andrewsav-bt commented on GitHub (Jan 8, 2020):

@jeremystretch but what if we do not have virtual routing in our networks, how are they linked then?

In the webui I can get all IPs of a prefix at https://netbox/ipam/prefixes/{id}/ip-addresses/ without any VRFs. How do I get this same list from the API?

Related: https://github.com/netbox-community/netbox/issues/2129

@andrewsav-bt commented on GitHub (Jan 8, 2020): @jeremystretch but what if we do not have virtual routing in our networks, how are they linked then? In the webui I can get all IPs of a prefix at `https://netbox/ipam/prefixes/{id}/ip-addresses/` without any VRFs. How do I get this same list from the API? Related: https://github.com/netbox-community/netbox/issues/2129
Author
Owner

@jeremystretch commented on GitHub (Jan 8, 2020):

Please avoid commenting on long-closed issues. The mailing list is available for general discussion.

@jeremystretch commented on GitHub (Jan 8, 2020): Please avoid commenting on long-closed issues. The [mailing list](https://groups.google.com/forum/#!forum/netbox-discuss) is available for general discussion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2540