Network automation use case
As we have now interacted with multiple sections of Python and device interaction, let's create a use case to incorporate what we have learned so far. The use case is as follows:
Log into the router and fetch some information:
task1()
: Show the version, show the IP in brief, show the clock, and show the configured usernames on the router.task2()
: Create another username on thetest
router with the passwordtest
and check whether we can log in successfully with the newly created username.task3()
: Log in with the newly created usernametest
, and delete all the other usernames from therunning-config
. Once this is done, return all the current usernames configured on the router to confirm whether only thetest
username is configured on the router.
Let's build a script to tackle these tasks one by one:
from netmiko import ConnectHandler device = ConnectHandler(device_type='cisco_ios', ip='192.168.255.249', username='cisco', password='cisco') def task1(): output ...