Skip to content

Provides a system to determine available interfaces in a range#812

Open
abates wants to merge 2 commits intonetworktocode:developfrom
abates:interface-slicer
Open

Provides a system to determine available interfaces in a range#812
abates wants to merge 2 commits intonetworktocode:developfrom
abates:interface-slicer

Conversation

@abates
Copy link
Contributor

@abates abates commented Feb 11, 2026

This request adds a method to slice lists of interfaces in order to facilitate provisioning. Sometimes upstream connections are placed within a given range of interfaces. For instance, a primary connection may always go in the range of Ethernet[1-24] and a secondary connection may go into Ethernet[25-48]. If a switch has all the interfaces Ethernet[1-48] available, then the two needed slices are returned. If a subset of needed interfaces are available, then only those interfaces in the subset are returned. For instance:

slice_interface_range(["Ethernet2", "Ethernet3", "Ethernet4", "Ethernet6", "Ethernet7", "Ethernet8"], "Ethernet1", "Ethernet5")

will effectively produce:

["Ethernet2", "Ethernet3", "Ethernet4"], ["Ethernet6", "Ethernet7", "Ethernet8"]

Comment on lines +467 to +468
up to (but not including) the next cut point. The final slice contains all
remaining interface names from the last cut point to the end of the sorted list. This
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me, but in my mind should also be extended to start. Having to always define the first element (Ethernet1 in tests below) seems off to me.

I could understand either both start and end needing to be explicit or neither being explicit, but start being explicit and end being implicit is a bit confusing to me.

@mpenning
Copy link

mpenning commented Mar 1, 2026

Suggestions for an API enhancement... using ciscoconfparse2 for API reference implementation...

Full-disclosure, I'm the ciscoconfparse2 owner...

Don't fear the GPL in my case... if I was going to fuss about GPL viral licensing, Cisco would already be hot sauce for using it all over the place with non-GPL licensing.

python
Python 3.13.0 (main, Dec  1 2024, 17:40:20) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from ciscoconfparse2 import CiscoRange
>>>
>>> intfs = CiscoRange("Ethernet2-4,6-8")
>>> for intf in intfs:
...     print(intf)
...
Ethernet2
Ethernet3
Ethernet4
Ethernet6
Ethernet7
Ethernet8
>>>
>>> CiscoRange("Ethernet2-4") in intfs
True
>>>
>>> CiscoRange("Ethernet47-48") in intfs
False
>>>

@itdependsnetworks
Copy link
Contributor

@mpenning wanted to start with a quick thanks for your open source contributions! Appreciate and notice all of your hard work over the years

Don't fear the GPL in my case

Our lawyers say otherwise, so while I understand the spirit of what you are saying, in practice my hands our tied.

@mpenning
Copy link

mpenning commented Mar 1, 2026

@itdependsnetworks

The point was twofold...

  • Yes, just use the GPL CiscoRange() if there were no such things as lawyers
  • If you don't adopt the GPL code, you can still use the CiscoRange() API, which doesn't require manually touching lists of string interface names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants