03-30-2025 10:58 PM - edited 03-30-2025 10:59 PM
I have referred to the route compare script at Github, and customized it and display the result in table format. It's working good on Cisco IOS platform, but it's failed at NXOS...
I tried to run it by comparing the "show ip route" results. And got the error message:-
============================================
Traceback (most recent call last):
File "/home/./route_compare.py", line 349, in <module>
main()
File "/home/./route_compare.py", line 324, in main
parse1.main(object1.result)
File "/home/./route_compare.py", line 232, in main
routes[nlocation]['ad{0}'.format(mroutecount)] = elements['ad']
IndexError: list index out of range
03-30-2025 11:54 PM
Nexus has a different output format than IOS; It doesn't look like the script is meant to work with Nexus-formatted output. The parseroute class seems to have failed to parse the file correctly resulting in a non-existent elements['ad']. You might try manually editing the Nexus output so each route is on a single line, but I suspect that won't be enough.
03-31-2025 02:16 AM
Based on your errors here when your script is trying to add wrapped routes or ECMP routes, but it can't find the "parent" route element this is why it appears to be failing due to the differences in route output format between IOS and NX.
You can fix this by adding a condition checking if routes
list is not empty before accessing nlocation
index
03-31-2025 04:49 AM
I'd like to suggest - before starting to parse NXOS-CLI-Output - there is a CLI-Pipe-Construct "JSON" available - so the NXOS provides easily to parse Output inJSON-Format
# show ip route | json
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