-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v4.3.7
Feature type
New functionality
Proposed functionality
Interfaces are sorted according a specific interface naturalization function
netbox/netbox/utilities/ordering.py
Line 51 in cf0ef92
| def naturalize_interface(value, max_length): |
This function suits very well for Cisco branded devices, but does not always work for other vendors.
There has been few proposals (can only find this one #9368 ) to address this, but for now non has been accepted. FR #20335 proposed several options, and the discussion thread ended with this proposal:
- provide different sorting mechanisms, which can be applied per Platform type
- also allow plugins to extend these sorting mechanisms
Proposed sorting algoritms
- Default: (current one) Similar in nature to naturalize(), but takes into account a particular naming format adapted from the old InterfaceManager
- Alphanumeric: Take an alphanumeric string and prepend all integers to
integer_placesplaces to ensure the strings are ordered naturally. (Arista) - Numeric: Take an alphanumeric string and prepend all integers to
integer_placesplaces to ensure the strings are ordered naturally, while ignoring the alpa part. (NetApp, JunOS, Arista)
Add new functions with a plugin or in configuration.py
FIELD_CHOICES = {
'dcim.Platform.interfacesorting+': (
('naturalsort' , 'Natural Interface Sorting', netbox_plugin.ordering.naturalsort),
)
}Other sorting option that could be implemented
- Numeric, but with mgmt_only interfaces first
A PoC can be found here, but that needs further coding before it can become a PR
https://github.com/PieterL75/netbox/tree/customize-naturlization
As a side effect, an extra option was implemented to the ChoiceSetMeta, adding the possibility to prevent a ChoiceSet to be replaced or extended. This probably need to go to a separate FR.
Use case
A recent poll in #netbox shows that there is a need for this: https://netdev-community.slack.com/archives/C01P0FRSXRV/p1757313471550629?thread_ts=1757065483.482359&cid=C01P0FRSXRV
| Platform OS | Current | Desired |
|---|---|---|
| Arista EOS | Ethernet48/1 | Ethernet1 |
| Ethernet48/2 | Ethernet2 | |
| Ethernet49/1 | Ethernet48/1 | |
| Ethernet49/2 | Ethernet48/2 | |
| Ethernet1 | Ethernet49/1 | |
| Ethernet2 | Ethernet49/2 | |
| Juniper JUNOS | ge-0/0/0 | ge-0/0/0 |
| ge-0/0/3 | xe-0/0/1 | |
| xe-0/0/1 | xe-0/0/2 | |
| xe-0/0/2 | ge-0/0/3 | |
| Netapp | 10a | e9a |
| 10b | e9e | |
| e9a | 10a | |
| e9e | 10b | |
| e11a | e11 | |
| e11e | e11 |
Database changes
Extra field on 'Platform'
model_name='platform',
name='interface_sorting',
field=models.CharField(default='default', max_length=100)
External dependencies
No response