Expose Power Panel/Feed Details From UI in /api/dcim/racks #5075

Closed
opened 2025-12-29 19:23:51 +01:00 by adam · 6 comments
Owner

Originally created by @bellwood on GitHub (Jul 20, 2021).

NetBox version

v2.10.10

Feature type

Change to existing functionality

Proposed functionality

Currently, via the API, the only information about power exposed in /api/dcim/racks/ is powerfeed_count via powerfeed_count=count_related(PowerFeed, 'rack') in netbox/dcim/api/views.py

It would be beneficial to have the same related power panels/feeds data exposed via the API that is also visible in the UI, specifically:

-power panel: id, name
-power feed: id, name, status, type

Use case

Having the above exposed for the rack endpoint gives an API caller a quick glance at power related details and provides the relationship details needed to make additional REST queries should further details about those panels/feeds be desired.

Database changes

None

External dependencies

None

Originally created by @bellwood on GitHub (Jul 20, 2021). ### NetBox version v2.10.10 ### Feature type Change to existing functionality ### Proposed functionality Currently, via the API, the only information about power exposed in `/api/dcim/racks/` is `powerfeed_count` via `powerfeed_count=count_related(PowerFeed, 'rack')` in `netbox/dcim/api/views.py` It would be beneficial to have the same related power panels/feeds data exposed via the API that is also visible in the UI, specifically: -power panel: id, name -power feed: id, name, status, type ### Use case Having the above exposed for the rack endpoint gives an API caller a quick glance at power related details and provides the relationship details needed to make additional REST queries should further details about those panels/feeds be desired. ### Database changes None ### External dependencies None
adam added the type: feature label 2025-12-29 19:23:51 +01:00
adam closed this issue 2025-12-29 19:23:51 +01:00
Author
Owner

@bellwood commented on GitHub (Aug 3, 2021):

Please assign to me, I'll give this a whirl =)

@bellwood commented on GitHub (Aug 3, 2021): Please assign to me, I'll give this a whirl =)
Author
Owner

@jeremystretch commented on GitHub (Aug 4, 2021):

It would be beneficial to have the same related power panels/feeds data exposed via the API that is also visible in the UI,

As a general design pattern in the REST API, we don't include "downstream" related objects, as this imposes a significant performance penalty. For example, we don't include devices when fetching a site, or prefixes when fetching a VLAN, so we also wouldn't include power feeds or panels when fetching a rack.

Instead, you can make a second REST API call to the appropriate endpoint(s) to retrieve these related objects, filtering by the rack ID:

GET /api/dcim/power-panels/?rack_id=123

Edit: Alternatively, v3.0 will include a GraphQL API that may better serve your needs.

@jeremystretch commented on GitHub (Aug 4, 2021): > It would be beneficial to have the same related power panels/feeds data exposed via the API that is also visible in the UI, As a general design pattern in the REST API, we don't include "downstream" related objects, as this imposes a significant performance penalty. For example, we don't include devices when fetching a site, or prefixes when fetching a VLAN, so we also wouldn't include power feeds or panels when fetching a rack. Instead, you can make a second REST API call to the appropriate endpoint(s) to retrieve these related objects, filtering by the rack ID: ``` GET /api/dcim/power-panels/?rack_id=123 ``` Edit: Alternatively, v3.0 will include a GraphQL API that may better serve your needs.
Author
Owner

@bellwood commented on GitHub (Aug 4, 2021):

Roger that, thanks.

@bellwood commented on GitHub (Aug 4, 2021): Roger that, thanks.
Author
Owner

@bellwood commented on GitHub (Aug 5, 2021):

Would you be willing to consider a PR that simply adds 'powerfeed_set' to this API view since that only returns the ID's of the power feeds to the rack and not the entirety of the powerfeed objects?

@bellwood commented on GitHub (Aug 5, 2021): Would you be willing to consider a PR that simply adds 'powerfeed_set' to this API view since that only returns the ID's of the power feeds to the rack and not the entirety of the powerfeed objects?
Author
Owner

@jeremystretch commented on GitHub (Aug 5, 2021):

No, because it would incur an additional database hit just to deliver data that's identical to the query for /api/dcim/power-feeds/?rack_id=123. We need to ensure we're consistent with the REST API application-wide to avoid nasty performance hits.

@jeremystretch commented on GitHub (Aug 5, 2021): No, because it would incur an additional database hit just to deliver data that's identical to the query for `/api/dcim/power-feeds/?rack_id=123`. We need to ensure we're consistent with the REST API application-wide to avoid nasty performance hits.
Author
Owner

@bellwood commented on GitHub (Aug 5, 2021):

Had to ask, no worries =)

@bellwood commented on GitHub (Aug 5, 2021): Had to ask, no worries =)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5075