12-08-2022 08:51 AM
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:
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:
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?
01-04-2023 06:43 PM
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
01-05-2023 06:40 AM
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:
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide