cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
340
Views
3
Helpful
3
Replies

Python script for compare route in Nexus switch.

R T
Level 1
Level 1

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

3 Replies 3

ulineosan
Level 1
Level 1

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.

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

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

r.heitmann
Level 1
Level 1

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