Skip to content

Replace regex-based natural ordering of interfaces with a discrete field #3097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jeremystretch opened this issue Apr 22, 2019 · 7 comments
Closed
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user

Comments

@jeremystretch
Copy link
Member

Environment

  • Python version: 3.5.2
  • NetBox version: 2.5.10

Proposed Functionality

The current form of natural ordering for device interfaces was introduced in #2165. It employs a set of regular expressions evaluated at query time to determine the preferred order of rows being returned. This is generally not an issues when retrieving only the interfaces which belong to a particular device, however it imposes excessive delay when querying a large number of interfaces.

Now that the natural ordering logic is fairly mature, I'd like to ditch the regex-based ordering and instead save the ordering data in a dedicated field as an index on the Interface model. Logic similar to the regex currently in use will be evaluated when an object is being saved, and its output will be stored in the database. (A schema migration will take care of updating this field for all existing interfaces.)

The exact nature of the ordering data is yet to be determined.

Use Case

This approach will allow for much more efficient querying and greatly simplify the Interface manager.

Database Changes

  • Add one or more fields to the Interface model
  • Simplify or remove InterfaceManager

External Dependencies

None

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application labels Apr 22, 2019
@jeremystretch
Copy link
Member Author

I've played around with this a bit and I think it will be doable, but I need to figure out how best to store the values. Ordering is by:

  • Slot
  • Subslot
  • Position
  • Subposition
  • Type (alphanumeric)
  • ID
  • Channel
  • Virtual circuit

While it's possible to order on an array of numeric values, having the alphanumeric "type" value in the middle of the fields presents a problem. I'm also wondering if this is going down the wrong path, since ultimately we'll want to do something similar for other device components that may need different logic.

@millijuna
Copy link

The one thing I would still like to ask for is some way to control the ordering precedence. Right now, my biggest annoyance with Netbox is that it fouls up the ordering when dealing with the interfaces on my Cisco gear. This is because Cisco puts different interface types on the same subslot. As such, on my 3750Es, the ten gig interfaces are mixed into the middle of the GigabitEthernet, and a similar thing happens with the 3560s and so forth.

If there was some way to adjust the ordering precedence, so that I could have Slot, Subslot, Type, Position, Subposition would make me a happy camper.

@rkandilarov
Copy link

rkandilarov commented Apr 26, 2019

I would also like to have control over the ordering... But should this be per device? In our company ( extreme edge case) we have lot of virtual interfaces on some devices named like client.1234 (client.1234@interface) and I would like to see all "subinterfaces" right after the "base" interface.
But to be honest I doubt if such hipper customisation-feature deserves all the work hours.

P.S. Normally the prefix name of the virtual vlan interface is the same as the interface itself. Naming like client.1234@interface or more precisely virtual vlan interface client.1234 on real interface interface is possible using Cumulus Linux ifupdown2 tool on any Debian based linux.

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application and removed type: feature Introduction of new functionality to the application labels May 1, 2019
@jeremystretch jeremystretch added type: housekeeping Changes to the application which do not directly impact the end user and removed type: feature Introduction of new functionality to the application labels May 3, 2019
@steffann
Copy link
Contributor

steffann commented Dec 28, 2019

I played around with using a PostgreSQL composite field in https://github.com/steffann/netbox/tree/3097-interface-ordering. I'm not completely happy with the dependency and its implementation, but it seems to work.

@jeremystretch
Copy link
Member Author

@steffann That's an interesting approach! I have some reservations however about introducing new dependencies without fully mature migration support. Does it provide any significant benefit (other than convenience) over just adding the interface name part fields to the Interface model directly?

@steffann
Copy link
Contributor

@steffann That's an interesting approach! I have some reservations however about introducing new dependencies without fully mature migration support. Does it provide any significant benefit (other than convenience) over just adding the interface name part fields to the Interface model directly?

Nope, just convenience and simple ordering (order_by('_name_components') compared to order_by('_slot', '_subslot', '_position', '_subposition', '_type', '_id', '_channel', '_vc')). Technically embedding a kind of row type in another row boils down to logically equivalent to just adding more columns…

@jeremystretch
Copy link
Member Author

This was implemented under #3799.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

No branches or pull requests

4 participants