no Restconf, no Netconf only napalm
Muhammad Rafi
Sr. Network Engineer @Cisco | MSc | BS | CCIE Enterprise | DevNet Expert
Following my last post regarding the nxos interface table, I have built another script for IOS/IOXE devices to pull multiple tables (i.e. Facts, Interfaces, ARP and VRF) but this time I have used napalm instead of netmiko, I could have done this via netmiko with textFSM or pyATS/Genie but napalm makes it so much easier. I believe you have to go with whatever option you think best suits for the job you are doing, like in legacy IOS device, I could not have done this via restconf/netconf but I do have an option to use either napalm or netmiko.
In my last nxos post, we did have an option to pull the information in JSON format and we then converted(deserialize) the JSON object to python dictionary and parse the desired output in the table format but here napalm does very good job and may already provide you the Python dictionary or list depending on the output. So, all we have to do is, just parse the values and generate the tables.
The other fancy thing in this script that I have created a class called IosTables with some methods rather than using only Python functions which I utilised in my last nxos script, thus this script may also give you an idea how to use classes in Python and instantiate an object in Python when you are doing network automation.
One important thing to notice that, I comment out the last line of the script print(device.vrf_table(vrf='')) and the reason why I did, because when I was running this script for IOSXE device with multiple vrfs, it was throwing me constant KeyError, which I raised it with napalm and apparently it has been labelled as a bug, so it may fix in later napalm version if this is a true bug.
Here is the reference for the issue I raised.
https://github.com/napalm-automation/napalm/issues/1350
You may uncomment that line if you running the script for IOS devices.
Enough of tables, right? I have another script to pull the same data what we used for interface table and generate a CSV file, it may be helpful for interface auditing purpose.
All of these are only educational purpose and you may change as per your need. if you see any error or mistakes in my post, please do give me a chance to correct it.
Thanks,
-Rafi
Please find the code here;
- IOS Tables script – https://github.com/muhammad-rafi/Python3_Network_Automation/blob/main/napalm_scripts/napalm_ios_tables.py
- Interfaces stats with .csv script – https://github.com/muhammad-rafi/Python3_Network_Automation/blob/main/napalm_scripts/ios_interface_csv.py
Solutions Architect @ Novatiq | CCIE#45033
4 年Have you looked at Nornir?