cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
228
Views
0
Helpful
2
Replies

Netconf - Gather Interfaces from Cat9300 with multiple Interface types

ChrisMott30064
Beginner
Beginner

I'm developing a script to gather all the interfaces for a Cat9300, enable the user to select a single interface by interface number (ex 1/0/1), and make changes to that interface.

The script does a normal Netconf request for all Interfaces with the below Filter, which works great:

 

<filter xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
        <interface/>
    </native>
</filter>

It then puts all the interface into a Dictionary, each interface in a row, and does a search of the interface number, using the interface "name" of 1/1/1 (or any other interface number found in the query).

During testing on a Cat9300-48UXM with an NM-8X Network Module, I noticed that, searching for interface 1/1/1, there are actually four potential ports to choose from:

  • interface GigabitEthernet1/1/1
  • interface TenGigabitEthernet1/1/1
  • interface FortyGigabitEthernet1/1/1
  • interface TwentyFiveGigE1/1/1

This is an issue, as in my case the TenGig1/1/1 interface is configured and is in use, so I should NOT be able to change interface GigabitEthernet1/1/1.

For the script logic, I suppose I can create a temporary IF statement to see if my dictionary has multiple Interface Types for a given interface name (that will be interesting itself), but it would be better if we could remove the unneeded, not-programmed Interfaces.

Is there another Netconf Filter I could leverage to get the information I'm looking for without the Interface redundancy?

2 Replies 2

charliepdean
Beginner
Beginner

Hey Chris,

I came across your post battling a similar issue. Dealing with the several interface type names is an extremely painful.
For you particular issue, you could use a XPath filter to only get the interfaces you are interested in. For example, here's an xpath filter that only returns interface names that have a particular ACL configured: "/native/interface//name[../ip/access-group/in/acl[acl-name='DEFAULT-ACCESS']]"

For you problem, looks like you are looking for interfaces that do not have any configuration. You could create a filter that matches on any interface that is missing some or all configuration. Not exactly sure what the xpath query would look like.

https://www.w3schools.com/xml/xpath_intro.asp

-Charlie

ChrisMott30064
Beginner
Beginner

Charlie,

Thanks for the reply. Part of being a Beginner is figuring out which trail to follow, especially when the existing trails are rough-cut with some leading to nowhere. I'm writing all sorts of scripts to do various things in my lab for testing, failing more than succeeding, but that's part of the fun!

For this scenario, I figured out that a combination of Models did the trick. The initial Read query to the device uses the "Cisco-IOS-XE-interfaces-oper" Model, which exposes the "oper-status" data to the script. I then filter out any non-viable Interface via:

      if interface["oper-status"] != "if-oper-state-not-present":
This handles the scenario where a single port can be either Gig, TenGig, FortyGig, etc., as they only "become" that interface once a suitable SFP has been installed, but are otherwise "not-present".
 
To write updated data back to the switch, I use the "Cisco-IOS-XE-native" Model, which makes for more fun, as THAT Model demands to know the InterfaceType (Gig, TenGig, etc.), so I broke the Interface Type and Interface Number apart, put them into a Dictionary, and parsed/pulled as I needed.
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Recognize Your Peers