Bulk-rename for devices #6135

Closed
opened 2025-12-29 19:37:09 +01:00 by adam · 16 comments
Owner

Originally created by @do9xe on GitHub (Feb 23, 2022).

Originally assigned to: @cpund on GitHub.

NetBox version

v3.1.6

Feature type

New functionality

Proposed functionality

Currently there is no bulk-rename functionality for devices. There is only a bulk-rename for interfaces. I would like to request to get the same bulk-rename functionality with (regex-)search/replace for devices.

Use case

We are currently facing a renumbering of the rooms and buildings of our organisation to a more unique scheme. As our devices names in netbox contain some location info it would be a big help to rename the devices with the bulk-rename functionality.

Database changes

No response

External dependencies

No response

Originally created by @do9xe on GitHub (Feb 23, 2022). Originally assigned to: @cpund on GitHub. ### NetBox version v3.1.6 ### Feature type New functionality ### Proposed functionality Currently there is no bulk-rename functionality for devices. There is only a bulk-rename for interfaces. I would like to request to get the same bulk-rename functionality with (regex-)search/replace for devices. ### Use case We are currently facing a renumbering of the rooms and buildings of our organisation to a more unique scheme. As our devices names in netbox contain some location info it would be a big help to rename the devices with the bulk-rename functionality. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 19:37:09 +01:00
adam closed this issue 2025-12-29 19:37:09 +01:00
Author
Owner

@ydc-dg commented on GitHub (Feb 25, 2022):

I‘m missing the bulk-rename functionality for devices as well. Example: When we need to change naming of patch panels.

@ydc-dg commented on GitHub (Feb 25, 2022): I‘m missing the bulk-rename functionality for devices as well. Example: When we need to change naming of patch panels.
Author
Owner

@Sawborg commented on GitHub (Mar 11, 2022):

This feature would be super useful for us as well. Being able to update the names for multiple devices when they "move" using a search/replace feature (e.g. updating the hostname/location prefix) would helpful.

@Sawborg commented on GitHub (Mar 11, 2022): This feature would be super useful for us as well. Being able to update the names for multiple devices when they "move" using a search/replace feature (e.g. updating the hostname/location prefix) would helpful.
Author
Owner

@jeremystretch commented on GitHub (Apr 6, 2022):

This probably applies to roughly any object with a name field; not just devices. (As noted, it exists already for device components.)

@jeremystretch commented on GitHub (Apr 6, 2022): This probably applies to roughly any object with a `name` field; not just devices. (As noted, it exists already for device components.)
Author
Owner

@github-actions[bot] commented on GitHub (Jun 6, 2022):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jun 6, 2022): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@cpund commented on GitHub (Jun 13, 2022):

@jeremystretch I'll take a crack at this issue.

@cpund commented on GitHub (Jun 13, 2022): @jeremystretch I'll take a crack at this issue.
Author
Owner

@kkthxbye-code commented on GitHub (Jun 13, 2022):

@cpund - All yours.

@kkthxbye-code commented on GitHub (Jun 13, 2022): @cpund - All yours.
Author
Owner

@cpund commented on GitHub (Jun 30, 2022):

Got the initial work for renaming devices done I believe. Just trying to understand how to properly craft the return_url. I could just generically return the user to /dcim/devices/, but if they originally arrived at rename via a filtered /dcim/devices/ page from a site or rack, or whichever, it would just dump them to the general view rather than that original filtered view.

@cpund commented on GitHub (Jun 30, 2022): Got the initial work for renaming devices done I believe. Just trying to understand how to properly craft the return_url. I could just generically return the user to /dcim/devices/, but if they originally arrived at rename via a filtered /dcim/devices/ page from a site or rack, or whichever, it would just dump them to the general view rather than that original filtered view.
Author
Owner

@jeremystretch commented on GitHub (Jun 30, 2022):

@cpund feel free to submit a PR with what you have now, and I'm happy to suggest a patch for the return URL (assuming there is a feasible approach).

@jeremystretch commented on GitHub (Jun 30, 2022): @cpund feel free to submit a PR with what you have now, and I'm happy to suggest a patch for the return URL (assuming there _is_ a feasible approach).
Author
Owner

@cpund commented on GitHub (Jun 30, 2022):

@jeremystretch Yeah, I'm going to spend around an hour or so possibly more just reading up further on how template rendering, particularly using variables in template rendering, works with Django, to see if I can achieve this. But as you mention, there may not a feasible approach - I just don't simply know enough about Django to figure out what variables are available for use, or if I could possibly inject them to be used.

@cpund commented on GitHub (Jun 30, 2022): @jeremystretch Yeah, I'm going to spend around an hour or so possibly more just reading up further on how template rendering, particularly using variables in template rendering, works with Django, to see if I can achieve this. But as you mention, there may not a feasible approach - I just don't simply know enough about Django to figure out what variables are available for use, or if I could possibly inject them to be used.
Author
Owner

@cpund commented on GitHub (Jun 30, 2022):

Figured out how to return. Realized I could just use the request.GET.urlencode to bring that in. However, decided to see what would happen if I tried to rename a device without a name - spoiler: it doesn't like that. So now I'm trying to decide how best to factor in devices without a name, or maybe I just exclude them from being shown in the BulkRenameView.

@cpund commented on GitHub (Jun 30, 2022): Figured out how to return. Realized I could just use the request.GET.urlencode to bring that in. However, decided to see what would happen if I tried to rename a device without a name - spoiler: it doesn't like that. So now I'm trying to decide how best to factor in devices without a name, or maybe I just exclude them from being shown in the BulkRenameView.
Author
Owner

@cpund commented on GitHub (Jun 30, 2022):

@jeremystretch in your opinion, do you think it would be better to just omit any devices with a name not set, or send an error to the user that they cannot select a device with no name for bulk renaming? Or if a device has no name, pass an empty "" for the None value when the renaming function goes into the re module?

@cpund commented on GitHub (Jun 30, 2022): @jeremystretch in your opinion, do you think it would be better to just omit any devices with a name not set, or send an error to the user that they cannot select a device with no name for bulk renaming? Or if a device has no name, pass an empty "" for the None value when the renaming function goes into the re module?
Author
Owner

@jeremystretch commented on GitHub (Jun 30, 2022):

@cpund please put a PR in with what you have so far (a draft is fine) so we can review together.

@jeremystretch commented on GitHub (Jun 30, 2022): @cpund please put a PR in with what you have so far (a draft is fine) so we can review together.
Author
Owner

@cpund commented on GitHub (Jun 30, 2022):

@jeremystretch pr submitted

@cpund commented on GitHub (Jun 30, 2022): @jeremystretch pr submitted
Author
Owner

@cpund commented on GitHub (Jul 19, 2022):

@jeremystretch any thoughts on this?

@cpund commented on GitHub (Jul 19, 2022): @jeremystretch any thoughts on this?
Author
Owner

@jeremystretch commented on GitHub (Jul 27, 2022):

Sorry, I still need to look into this. Have been trying to keep up with v3.3 work.

@jeremystretch commented on GitHub (Jul 27, 2022): Sorry, I still need to look into this. Have been trying to keep up with v3.3 work.
Author
Owner

@jeremystretch commented on GitHub (Jul 27, 2022):

Or if a device has no name, pass an empty "" for the None value when the renaming function goes into the re module?

Yep, we should just need to change this line to reference obj.name or '':

6cee12b153/netbox/netbox/views/generic/bulk_views.py (L636)

@jeremystretch commented on GitHub (Jul 27, 2022): > Or if a device has no name, pass an empty "" for the None value when the renaming function goes into the re module? Yep, we should just need to change this line to reference `obj.name or ''`: https://github.com/netbox-community/netbox/blob/6cee12b1530597bf308ba39c661e456bd1802835/netbox/netbox/views/generic/bulk_views.py#L636
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6135