Add Device filtering by rack name #5381

Closed
opened 2025-12-29 19:27:20 +01:00 by adam · 4 comments
Owner

Originally created by @pspdbx on GitHub (Sep 16, 2021).

NetBox version

2.11.2

Feature type

New functionality

Proposed functionality

To iterate over the Devices in a rack, the only way to do it currently is nb.dcim.devices.filter(role="server", rack_id=<rack id integer>) , where nb is an instance of pynetbox client.

It requires tools that interact with Netbox make an additional call to check if the rack exists, and if it does, get its ID.

Proposed functionality:
nb.dcim.devices.filter(role="server", rack=<rack name string>) is far easier to read and adopt.

Use case

In many of datacenter automation workflows (think provisioning, dns/dhcp config gen, ip allocation etc.), it is common to iterate over racks. While I'm very glad there is a model in Netbox for Rack, it would be a huge benefit to be able to filter on Device based on rack name, without making additional calls to Netbox to fetch the rack ID.

Database changes

None required.

External dependencies

None.

Originally created by @pspdbx on GitHub (Sep 16, 2021). ### NetBox version 2.11.2 ### Feature type New functionality ### Proposed functionality To iterate over the Devices in a rack, the only way to do it currently is `nb.dcim.devices.filter(role="server", rack_id=<rack id integer>)` , where `nb` is an instance of pynetbox client. It requires tools that interact with Netbox make an additional call to check if the rack exists, and if it does, get its ID. Proposed functionality: `nb.dcim.devices.filter(role="server", rack=<rack name string>)` is far easier to read and adopt. ### Use case In many of datacenter automation workflows (think provisioning, dns/dhcp config gen, ip allocation etc.), it is common to iterate over racks. While I'm very glad there is a model in Netbox for Rack, it would be a huge benefit to be able to filter on `Device` based on rack name, without making additional calls to Netbox to fetch the rack ID. ### Database changes None required. ### External dependencies None.
adam added the type: feature label 2025-12-29 19:27:20 +01:00
adam closed this issue 2025-12-29 19:27:20 +01:00
Author
Owner

@jeremystretch commented on GitHub (Sep 16, 2021):

Filtering by rack name is not supported because rack names need not be unique. For example, filtering by ?rack=R101 would return devices belonging to any rack named R101, at any site. You could also limit the query by assigned site, but at that point it's more efficient to specify the rack by ID anyway.

@jeremystretch commented on GitHub (Sep 16, 2021): Filtering by rack name is not supported because rack names need not be unique. For example, filtering by `?rack=R101` would return devices belonging to _any_ rack named R101, at any site. You could also limit the query by assigned site, but at that point it's more efficient to specify the rack by ID anyway.
Author
Owner

@pspdbx commented on GitHub (Sep 17, 2021):

That makes sense, thank you @jeremystretch . Would adding a field for fqrack to the Rack model make sense? A fully qualified rack name that is guaranteed to be unique across all Sites.

@pspdbx commented on GitHub (Sep 17, 2021): That makes sense, thank you @jeremystretch . Would adding a field for fqrack to the `Rack` model make sense? A fully qualified rack name that is guaranteed to be unique across all Sites.
Author
Owner

@jeremystretch commented on GitHub (Sep 17, 2021):

No, that wouldn't make any sense.

@jeremystretch commented on GitHub (Sep 17, 2021): No, that wouldn't make any sense.
Author
Owner

@pspdbx commented on GitHub (Sep 17, 2021):

Ack, thanks for reviewing the request!

@pspdbx commented on GitHub (Sep 17, 2021): Ack, thanks for reviewing the request!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#5381