Improve natural sorting with mixed Gi/Te interfaces #1763

Closed
opened 2025-12-29 17:18:54 +01:00 by adam · 2 comments
Owner

Originally created by @candlerb on GitHub (Jun 1, 2018).

Issue type

[X] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.2
  • NetBox version: 2.3.3

Description

I realise that natural sorting is a difficult issue, but here is another anomoly: this is from a Dell Powerconnect N1548 which has Gi1/0/1-1/0/48 and Te1/0/1-1/0/4

image

It would be nice if natural sorting split the port name into (non-numeric) and (numeric) parts, and sorted them piecewise: when comparing the string parts use string ordering, when comparing the numeric parts compare numerically.

>>> ["Gi", 1, "/", 0, "/", 48] < ["Te", 1, "/", 0, "/", 1]
True

This would mean that all the "Gi" interfaces would come before all the "Te" interfaces.

When comparing a string with a number then pick a fixed order (e.g. string always comes before number).

Originally created by @candlerb on GitHub (Jun 1, 2018). ### Issue type [X] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.2 * NetBox version: 2.3.3 ### Description I realise that natural sorting is a difficult issue, but here is another anomoly: this is from a Dell Powerconnect N1548 which has Gi1/0/1-1/0/48 and Te1/0/1-1/0/4 ![image](https://user-images.githubusercontent.com/44789/40837405-4678dbb0-6592-11e8-8ca1-da37825f6f1d.png) It would be nice if natural sorting split the port name into (non-numeric) and (numeric) parts, and sorted them piecewise: when comparing the string parts use string ordering, when comparing the numeric parts compare numerically. ~~~ >>> ["Gi", 1, "/", 0, "/", 48] < ["Te", 1, "/", 0, "/", 1] True ~~~ This would mean that all the "Gi" interfaces would come before all the "Te" interfaces. When comparing a string with a number then pick a fixed order (e.g. string always comes before number).
adam closed this issue 2025-12-29 17:18:54 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jun 1, 2018):

Changing the interface ordering on the DeviceType from slot/position to name will order all Gi interfaces before all Te interfaces. NetBox supports both approaches because different platforms follow one or the other.

@jeremystretch commented on GitHub (Jun 1, 2018): Changing the interface ordering on the DeviceType from slot/position to name will order all `Gi` interfaces before all `Te` interfaces. NetBox supports both approaches because different platforms follow one or the other.
Author
Owner

@candlerb commented on GitHub (Jun 1, 2018):

Cool, that works. I thought it might put Gi1/0/10 before Gi1/0/2, but it doesn't :-)

Thank you!

@candlerb commented on GitHub (Jun 1, 2018): Cool, that works. I thought it might put Gi1/0/10 before Gi1/0/2, but it doesn't :-) Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1763