/api/dcim/devices/?position=XX only returns a device if position is == rather than contains #1977

Closed
opened 2025-12-29 17:21:04 +01:00 by adam · 2 comments
Owner

Originally created by @pm17788 on GitHub (Aug 28, 2018).

Environment

  • Python version: 3.5.2
  • NetBox version: 2.4.3

Proposed Functionality

Currently, given a multi-U device, querying a rack and position only returns the device when position strictly matches. So, if a 3U device is in rack 2048, position 30, a query for /api/dcim/devices/?rack_id=2048&position31 or /api/dcim/devices/?rack_id=2048&position32 won't return the device entry.

Use Case

When trying to 'rack' a device, when an error is returned reading:

server391 to A-17[u: 33] in use1 {"non_field_errors":["U33 is already occupied or does not have sufficient space to accommodate a(n) 4U (4U)."]}

It would be nice to be able to query the rack and those positions and find out what is blocking things. To do so currently would require build a virtual rack model in-memory and then walk it, which seems to duplicate what NetBox already has codified.

Database Changes

None, AFAIK

External Dependencies

None, AFAIK

Originally created by @pm17788 on GitHub (Aug 28, 2018). ### Environment * Python version: 3.5.2 * NetBox version: 2.4.3 ### Proposed Functionality Currently, given a multi-U device, querying a `rack` and `position` only returns the device when position strictly matches. So, if a 3U device is in rack 2048, position 30, a query for `/api/dcim/devices/?rack_id=2048&position31` or `/api/dcim/devices/?rack_id=2048&position32` won't return the device entry. ### Use Case When trying to 'rack' a device, when an error is returned reading: ``` server391 to A-17[u: 33] in use1 {"non_field_errors":["U33 is already occupied or does not have sufficient space to accommodate a(n) 4U (4U)."]} ``` It would be nice to be able to query the rack and those positions and find out what is blocking things. To do so currently would require build a virtual rack model in-memory and then walk it, which seems to duplicate what NetBox already has codified. ### Database Changes None, AFAIK ### External Dependencies None, AFAIK
adam closed this issue 2025-12-29 17:21:04 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 5, 2018):

unit is an explicit field on the device model and altering how it is evaluated may be dangerous. Additionally, the rack face must also be considered when determining whether a particular rack unit is available or occupied.

Alternatively, there is an API endpoint which lists the device present (if any) in each unit: /api/dcim/racks/<pk>/units/. The rack face can be specified by passing ?face=0 (front) or ?face=1 (rear).

@jeremystretch commented on GitHub (Sep 5, 2018): `unit` is an explicit field on the device model and altering how it is evaluated may be dangerous. Additionally, the rack face must also be considered when determining whether a particular rack unit is available or occupied. Alternatively, there is an API endpoint which lists the device present (if any) in each unit: `/api/dcim/racks/<pk>/units/`. The rack face can be specified by passing `?face=0` (front) or `?face=1` (rear).
Author
Owner

@pm17788 commented on GitHub (Sep 6, 2018):

@jeremystretch: Fair enough. Apologies, didn't connect the /api/dcim/racks/<pk>/units/ endpoint to being Just The Thing I Need. Thank you.

@pm17788 commented on GitHub (Sep 6, 2018): @jeremystretch: Fair enough. Apologies, didn't connect the `/api/dcim/racks/<pk>/units/` endpoint to being Just The Thing I Need. Thank you.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1977