netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Bulk-rename for devices

Open do9xe opened this issue 2 years ago • 16 comments

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

do9xe avatar Feb 23 '22 09:02 do9xe

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

ydc-dg avatar Feb 25 '22 22:02 ydc-dg

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 avatar Mar 10 '22 23:03 Sawborg

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

jeremystretch avatar Apr 06 '22 21:04 jeremystretch

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] avatar Jun 06 '22 04:06 github-actions[bot]

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

cpund avatar Jun 13 '22 19:06 cpund

@cpund - All yours.

kkthxbye-code avatar Jun 13 '22 19:06 kkthxbye-code

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 avatar Jun 30 '22 05:06 cpund

@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 avatar Jun 30 '22 13:06 jeremystretch

@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 avatar Jun 30 '22 15:06 cpund

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 avatar Jun 30 '22 16:06 cpund

@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 avatar Jun 30 '22 18:06 cpund

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

jeremystretch avatar Jun 30 '22 19:06 jeremystretch

@jeremystretch pr submitted

cpund avatar Jun 30 '22 20:06 cpund

@jeremystretch any thoughts on this?

cpund avatar Jul 19 '22 20:07 cpund

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

jeremystretch avatar Jul 27 '22 18:07 jeremystretch

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

jeremystretch avatar Jul 27 '22 20:07 jeremystretch