Netbox has a handy feature in the interface section that permits the bulk edit of interface names. This is really handy when you have switch stacks and want the name to represent the full port name so the CLI and netbox agree.
In my example I have member 2 of a stack. When created ports are named 1 to 52. For automation one could have a config context or other custom field that permits a member id, such that a python script could find the right interface. However, a more simple way and one that helps human users of netbox is simply to have member two’s interface named 2/1 , 2/2 etc.
Another example is where CLI commands require more than a number to identify a port. HP Comware won’t permit operations by referring to port 12. It needs to be G1/2. Other reasons for renaming might well exist.
Go to the interface section of a device, scroll to the bottom and find the rename icon:

Once interfaces have been selected and the rename button clicked, you get the option to type the search string (regex) and replace string. The preview button is useful here to make sure you will get what you want because there is no ctrl-z with netbox. In the example below my strings aren’t right and won’t provide what I want. Notice also how each interface has a white background. That means it doesn’t match the search string.

In the below example the matched lines have a green background.

The magic to bulk rename is the search strings in this final example. The find string should be (\d+) and the replace string must be my_text\1

Using this combination you can make all the member 2 switch interfaces 2/1, 2,2…. very easily and quickly
Leave a comment