In the previous video, we already learn how to doing network automation using paramiko. 2
But the case is still very simple, which is to create only 1 loopback interface. 3
Now in this video, we are going to do more complex network automation. 4
Let’s say we want to create some interface loopback at once. Let’s just start. 5
Create a new file, 6
let’s say the name is paramiko_looping.py. 7
I will copy paste the script from the paramiko_basic.py, 8
and then later we will edit this. 9
Okay now let’s edit this script to create some interface at once. 10
Let’s say we will create interface loopback 4 until 6. 11
To do that, we will use looping, for n, this n is just a variable, you can use anything you want, 12
in range 4 until 7, if we looping between 4 until 7 like this, the result will be 4 until 6. 13
Let’s try it on python interpreter first. Here let’s type the script, for n in range 4 7, 14
let’s print the n, 15
Here we can see that the result is 4 until 6. So here 7 minus by 1. 16
If we type the looping between 4 until 6, the result will be only until 5. 17
Let’s try it, for n in range 4 6 18
Here we can see that the result is only until 5, 19
so if we want to create loopback 4 until 6, we need to looping on 4 until 7. 20
Here we need to have indentation we can block the script and then tab in the keyboard. 21
For the interface name, let’s change it using n, because we want the name of interface is loopback4 22
loopback5 and loopback 6, so we need to change this 3 become n. 23
We can use f string, f here, and then here let’s change become n. 24
So this n will be 4 5 and 6. 25
Next, for the ip address, we can see that the ip address is increment by 1 from the 26
loopback number. Loopback0, the ip address is 10.1.1.1, loopback1 the ip address is 10.1.1.2. 27
loopback2 the ip address is 10.1.1.3, and loopback3 the ip address is 10.1.1.4. 28
So the last number Is the loopback number increment by 1, 29
Now we can change this become n plus by 1. 30
And then here we need to use f string. So when we create interface loopback4, 31
the ip address will be 4 plus by 1, which is 5. When we create loopback5, the ip address will be 5 plus 32
by 1, which is 6. And when we create loopback6, the ip address will be 6 plus by 1, which is 7. 33
Okay we have done here, we using indentation here, 34
so this script will be looping, but the output script is outside looping. 35
Because we want to execute print output when all configuration is done. 36
And then here, configure terminal is also outside the looping, 37
because we only need to use configure terminal command 38
one time. We don’t need to type configure terminal every time create interface loopback. 39
save, let’s execute this script. 40
Ls, here we can see that we have paramiko_looping_interface.py, 41
let’s execute this, python paramiko_looping_interface.py. 42
just enter enter here, okay this is success to login to router 1, configure terminal, 43
and here we are success to configure loopback 4, the ip address is 10.1.1.5, configure loopback5, 44
the ip address is 10.1.1.6, and configure loopback6, the ip address is 10.1.1.7. 45
okay this is success. Let’s check on router 1, do show ip interface brief exclude unassign, 46
here we can see that we have interface loopback 4 until 6. 47
Okay so now we are success to create many interface at once. 48
Before moving to next video, 49
let’s remove all interface loopback on router 1, so here we have loopback 0 until 6, 50
let’s try to remove all of this loopback interface, we can use looping. 51
Let’s just comment this, 52
to comment multiple line of code, we can block the script, and then ctrl + /, 53
Here we can see that all script is become comment. 54
If we block the script again, and type ctrl + / again, the comment will be gone like this. 55
If I type ctrl + / again, this script will become comment again. 56
And then now let’s write a script to remove interface loopback 0 until 6, 57
so for n in range 0 7, because we want to looping until 6, so we need to write until 7 here. 58
Or actually, we don’t need 0 here, so we can just type 7. This is will be looping from 0 until 6. 59
And then here no interface loopback n. here we need to use f string. 60
Don’t forget \n here for enter. Last, let’s sleep for a half second. 61
Because the configuration is very simple, so a half second is enough. Save this. 62
Let’s back to the terminal, execute the script. Enter enter here, 63
okay here we can see that we are success to remove interface loopback 0 until 6. 64
Let’s check on router 1 again, show ip interface brief exclude unassign. 65
Here we can see that we don’t have loopback 0 until 6 anymore. 66
Okay I think enough for this video, 67
in the next video, we are going to learn how to configure many router at once. 68
Thank you for watching and see you on the next video.