In the previous video, we already learn about the differences between send_command and send_config set. 2
Next, in this video, we are going to learn how to automate multiple router at once using netmiko. 3
In this case, we will show the interface on all router. 4
Let’s just start. 5
Create new file, let’s say the name is netmiko_looping.py. 6
And then let’s copy and paste the script from netmiko_basic.py. 7
Here we can see that we define a dictionary for router 1, if you remember the ip address 8
of router 1 is 10.10.10.1, router 2 is 10.10.10.2, router 3 is 10.10.10.3 and others, 9
Let’s check on on gns3. 10
Here we can see that we have a pattern. 11
Router 1 is 10.10.10.1, router 2 is 10.10.10.2 and others. 12
The differences is only in the last number, the first 3 number is same, 13
So here, we can do looping like this, for n in range 1,6, 14
This is means that we do looping on number 1 until 5. 15
And then let’s add an indentation to this script. 16
So this script will become part of looping. 17
Next, we can change this number become n, so we need to use f string here, and then 18
change this become n. 19
And then for the router variable, let’s just change this become r, 20
and then here we also need to change it to r. 21
Okay we have done here, 22
the device type of all router will be same, the ip address will be different, the username 23
and password also will be same on all router, and then connect to the router, this is will 24
be based on the looping, when the n is 1, so we connect to router 1, when the n is 2, 25
so we connect to router 2, and others. 26
And then here, let’s say we just want to send command to show the interface, 27
so we can comment this script, and then uncomment this script, 28
Let’s also add exclude unassign here. 29
And then here, we also need to change this variable to r. 30
Last, we print the output. 31
Let’s move this script to the end, 32
Okay so now we just need 16 lines of code. 33
This is very simple compared to paramiko. 34
Save this, 35
Back to the terminal, ls, here we can see that we have netmiko_looping.py, let’s execute 36
this script. 37
Okay here we can see that router 1 is success, router 2 success, router 3 success, router 4 38
success and router 5 also success. 39
But here we can see that we don’t have divider between router, so the output is not too good. 40
Back to sublime, and let’s add a divider. 41
Save, let’s execute the script again, 42
okay router 1 success, router 2, router 3, router 4, and router 5. 43
Okay so now we are success to remote multiple router at once using netmiko. 44
I think enough for this video 45
Thank you for watching and see you on the next video.