Expose device role in /dcim/interfaces/ connected_endpoints #2795

Closed
opened 2025-12-29 18:22:13 +01:00 by adam · 1 comment
Owner

Originally created by @n3wtype on GitHub (Aug 8, 2019).

Environment

  • Python version:
  • NetBox version:

Proposed Functionality

Expose device role in /dcim/interfaces/ connected_endpoints

now it looks like

{
  "count": 2982,
  "next": "https://<url>/api/dcim/interfaces/?limit=1000&offset=1000",
  "previous": null,
  "results": [
    {
      "id": 1352,
      "device": {
        "id": 60,
        "url": "https://<url>/api/dcim/devices/60/",
        "name": "sw1",
        "display_name": "sw1"
      },
      "name": "et-0/0/0",
      "type": {
        "value": 1600,
        "label": "QSFP28 (100GE)"
      },
      "form_factor": {
        "value": 1600,
        "label": "QSFP28 (100GE)"
      },
      "enabled": true,
      "lag": null,
      "mtu": null,
      "mac_address": null,
      "mgmt_only": false,
      "description": "",
      "connected_endpoint_type": "dcim.interface",
      "connected_endpoint": {
        "id": 1045,
        "url": "https://<url>/api/dcim/interfaces/1045/",
        "device": {
          "id": 52,
          "url": "https://<url>/api/dcim/devices/52/",
          "name": "vps1",
          "display_name": "vps1"
        },
        "name": "et-0/0/48",
        "cable": 250,
        "connection_status": {
          "value": true,
          "label": "Connected"
        }
      },
      "connection_status": {
        "value": true,
        "label": "Connected"
      },
      "cable": {
        "id": 250,
        "url": "https://<url>/api/dcim/cables/250/",
        "label": ""
      },
      "mode": null,
      "untagged_vlan": null,
      "tagged_vlans": [],
      "tags": [],
      "count_ipaddresses": 0
    }
}

after a change

{
  "count": 2982,
  "next": "https://<url>/api/dcim/interfaces/?limit=1000&offset=1000",
  "previous": null,
  "results": [
    {
      "id": 1352,
      "device": {
        "id": 60,
        "url": "https://<url>/api/dcim/devices/60/",
        "name": "sw1",
        "display_name": "sw1"
      },
      "name": "xe-0/0/0",
      "type": {
        "value": 1600,
        "label": "QSFP28 (100GE)"
      },
      "form_factor": {
        "value": 1600,
        "label": "QSFP28 (100GE)"
      },
      "enabled": true,
      "lag": null,
      "mtu": null,
      "mac_address": null,
      "mgmt_only": false,
      "description": "",
      "connected_endpoint_type": "dcim.interface",
      "connected_endpoint": {
        "id": 1045,
        "url": "https://<url>/api/dcim/interfaces/1045/",
        "device": {
          "id": 52,
          "url": "https://<url>/api/dcim/devices/52/",
          "name": "vps1",
          "display_name": "vps1"
          "device_role":  {
              "name": "vps"
          }
        },
        "name": "et-0/0/48",
        "cable": 250,
        "connection_status": {
          "value": true,
          "label": "Connected"
        }
      },
      "connection_status": {
        "value": true,
        "label": "Connected"
      },
      "cable": {
        "id": 250,
        "url": "https://<url>/api/dcim/cables/250/",
        "label": ""
      },
      "mode": null,
      "untagged_vlan": null,
      "tagged_vlans": [],
      "tags": [],
      "count_ipaddresses": 0
    }
}

Use Case

Let's say that I have an access switch and bunch of servers connected to it within netbox. Based on device_role.name of connected device I would like to do some automated configuration of access port. To do that I fetch a list of interfaces of this switch and look within connected_endpoint section. Currently device_role.name is not exposed by this api. So get this information I need to do additional API calls. Imagine I have 100+ switches with 48 ports connected to different devices. It make a lot of additional API calls. It would be lot simpler connected_endpoint section would provide this information right away. It would make automation based on data from netbox easier. Making automation decision based on data from netbox keeps netbox consistent with actual configuration and for bigger environments it could be reasonable to provide some more data right away to avoid massive amount of additional API calls.

Database Changes

As far as I'm aware no additional schema change is required. The only required change is probably additional JOIN in orm to fetch device_role.name for each device.

External Dependencies

n/a

Originally created by @n3wtype on GitHub (Aug 8, 2019). ### Environment * Python version: <!-- Example: 3.6 --> * NetBox version: <!-- Example: 2.6.1 --> ### Proposed Functionality Expose device role in /dcim/interfaces/ connected_endpoints now it looks like ``` { "count": 2982, "next": "https://<url>/api/dcim/interfaces/?limit=1000&offset=1000", "previous": null, "results": [ { "id": 1352, "device": { "id": 60, "url": "https://<url>/api/dcim/devices/60/", "name": "sw1", "display_name": "sw1" }, "name": "et-0/0/0", "type": { "value": 1600, "label": "QSFP28 (100GE)" }, "form_factor": { "value": 1600, "label": "QSFP28 (100GE)" }, "enabled": true, "lag": null, "mtu": null, "mac_address": null, "mgmt_only": false, "description": "", "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 1045, "url": "https://<url>/api/dcim/interfaces/1045/", "device": { "id": 52, "url": "https://<url>/api/dcim/devices/52/", "name": "vps1", "display_name": "vps1" }, "name": "et-0/0/48", "cable": 250, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 250, "url": "https://<url>/api/dcim/cables/250/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } } ``` after a change ``` { "count": 2982, "next": "https://<url>/api/dcim/interfaces/?limit=1000&offset=1000", "previous": null, "results": [ { "id": 1352, "device": { "id": 60, "url": "https://<url>/api/dcim/devices/60/", "name": "sw1", "display_name": "sw1" }, "name": "xe-0/0/0", "type": { "value": 1600, "label": "QSFP28 (100GE)" }, "form_factor": { "value": 1600, "label": "QSFP28 (100GE)" }, "enabled": true, "lag": null, "mtu": null, "mac_address": null, "mgmt_only": false, "description": "", "connected_endpoint_type": "dcim.interface", "connected_endpoint": { "id": 1045, "url": "https://<url>/api/dcim/interfaces/1045/", "device": { "id": 52, "url": "https://<url>/api/dcim/devices/52/", "name": "vps1", "display_name": "vps1" "device_role": { "name": "vps" } }, "name": "et-0/0/48", "cable": 250, "connection_status": { "value": true, "label": "Connected" } }, "connection_status": { "value": true, "label": "Connected" }, "cable": { "id": 250, "url": "https://<url>/api/dcim/cables/250/", "label": "" }, "mode": null, "untagged_vlan": null, "tagged_vlans": [], "tags": [], "count_ipaddresses": 0 } } ``` ### Use Case Let's say that I have an access switch and bunch of servers connected to it within netbox. Based on device_role.name of connected device I would like to do some automated configuration of access port. To do that I fetch a list of interfaces of this switch and look within connected_endpoint section. Currently device_role.name is not exposed by this api. So get this information I need to do additional API calls. Imagine I have 100+ switches with 48 ports connected to different devices. It make a lot of additional API calls. It would be lot simpler connected_endpoint section would provide this information right away. It would make automation based on data from netbox easier. Making automation decision based on data from netbox keeps netbox consistent with actual configuration and for bigger environments it could be reasonable to provide some more data right away to avoid massive amount of additional API calls. ### Database Changes As far as I'm aware no additional schema change is required. The only required change is probably additional JOIN in orm to fetch device_role.name for each device. ### External Dependencies n/a
adam closed this issue 2025-12-29 18:22:14 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 8, 2019):

This would introduce excessive overhead for the request. It's the same reason the response doesn't include the connected device's site, rack, etc. You'll need to make a separate API request for the device if you need that information.

@jeremystretch commented on GitHub (Aug 8, 2019): This would introduce excessive overhead for the request. It's the same reason the response doesn't include the connected device's site, rack, etc. You'll need to make a separate API request for the device if you need that information.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2795