netbox
netbox copied to clipboard
Bulk-rename for devices
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
I‘m missing the bulk-rename functionality for devices as well. Example: When we need to change naming of patch panels.
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.
This probably applies to roughly any object with a name
field; not just devices. (As noted, it exists already for device components.)
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.
@jeremystretch I'll take a crack at this issue.
@cpund - All yours.
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 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 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.
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.
@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 please put a PR in with what you have so far (a draft is fine) so we can review together.
@jeremystretch pr submitted
@jeremystretch any thoughts on this?
Sorry, I still need to look into this. Have been trying to keep up with v3.3 work.
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