1 00:00:00,911 --> 00:00:07,596 In the previous video, we already learn how to doing network automation using paramiko. 2 00:00:08,297 --> 00:00:16,817 But the case is still very simple, which is to create only 1 loopback interface. 3 00:00:17,435 --> 00:00:23,540 Now in this video, we are going to do more complex network automation. 4 00:00:24,042 --> 00:00:30,918 Let’s say we want to create some interface loopback at once. Let’s just start. 5 00:00:31,464 --> 00:00:33,313 Create a new file, 6 00:00:37,657 --> 00:00:41,816 let’s say the name is paramiko_looping.py. 7 00:00:48,408 --> 00:00:53,344 I will copy paste the script from the paramiko_basic.py, 8 00:00:53,657 --> 00:00:56,612 and then later we will edit this. 9 00:00:57,755 --> 00:01:02,949 Okay now let’s edit this script to create some interface at once. 10 00:01:03,528 --> 00:01:08,647 Let’s say we will create interface loopback 4 until 6. 11 00:01:09,177 --> 00:01:21,045 To do that, we will use looping, for n, this n is just a variable, you can use anything you want, 12 00:01:21,495 --> 00:01:33,029 in range 4 until 7, if we looping between 4 until 7 like this, the result will be 4 until 6. 13 00:01:33,435 --> 00:01:47,984 Let’s try it on python interpreter first. Here let’s type the script, for n in range 4 7, 14 00:01:50,000 --> 00:01:51,901 let’s print the n, 15 00:01:52,537 --> 00:02:00,866 Here we can see that the result is 4 until 6. So here 7 minus by 1. 16 00:02:01,626 --> 00:02:09,122 If we type the looping between 4 until 6, the result will be only until 5. 17 00:02:09,546 --> 00:02:14,642 Let’s try it, for n in range 4 6 18 00:02:18,793 --> 00:02:22,903 Here we can see that the result is only until 5, 19 00:02:23,546 --> 00:02:31,272 so if we want to create loopback 4 until 6, we need to looping on 4 until 7. 20 00:02:32,535 --> 00:02:40,000 Here we need to have indentation we can block the script and then tab in the keyboard. 21 00:02:40,522 --> 00:02:50,181 For the interface name, let’s change it using n, because we want the name of interface is loopback4 22 00:02:50,181 --> 00:02:57,537 loopback5 and loopback 6, so we need to change this 3 become n. 23 00:02:58,070 --> 00:03:05,217 We can use f string, f here, and then here let’s change become n. 24 00:03:05,817 --> 00:03:10,990 So this n will be 4 5 and 6. 25 00:03:11,482 --> 00:03:18,581 Next, for the ip address, we can see that the ip address is increment by 1 from the 26 00:03:18,581 --> 00:03:29,909 loopback number. Loopback0, the ip address is 10.1.1.1, loopback1 the ip address is 10.1.1.2. 27 00:03:30,279 --> 00:03:40,642 loopback2 the ip address is 10.1.1.3, and loopback3 the ip address is 10.1.1.4. 28 00:03:41,159 --> 00:03:46,165 So the last number Is the loopback number increment by 1, 29 00:03:46,746 --> 00:03:52,337 Now we can change this become n plus by 1. 30 00:03:55,817 --> 00:04:03,677 And then here we need to use f string. So when we create interface loopback4, 31 00:04:03,677 --> 00:04:15,304 the ip address will be 4 plus by 1, which is 5. When we create loopback5, the ip address will be 5 plus 32 00:04:15,304 --> 00:04:27,096 by 1, which is 6. And when we create loopback6, the ip address will be 6 plus by 1, which is 7. 33 00:04:27,931 --> 00:04:33,150 Okay we have done here, we using indentation here, 34 00:04:33,322 --> 00:04:40,433 so this script will be looping, but the output script is outside looping. 35 00:04:41,193 --> 00:04:47,759 Because we want to execute print output when all configuration is done. 36 00:04:48,442 --> 00:04:54,180 And then here, configure terminal is also outside the looping, 37 00:04:54,553 --> 00:04:58,525 because we only need to use configure terminal command 38 00:04:58,525 --> 00:05:06,549 one time. We don’t need to type configure terminal every time create interface loopback. 39 00:05:07,288 --> 00:05:12,487 save, let’s execute this script. 40 00:05:16,442 --> 00:05:23,479 Ls, here we can see that we have paramiko_looping_interface.py, 41 00:05:23,977 --> 00:05:30,658 let’s execute this, python paramiko_looping_interface.py. 42 00:05:33,624 --> 00:05:44,675 just enter enter here, okay this is success to login to router 1, configure terminal, 43 00:05:44,790 --> 00:05:54,480 and here we are success to configure loopback 4, the ip address is 10.1.1.5, configure loopback5, 44 00:05:54,480 --> 00:06:04,353 the ip address is 10.1.1.6, and configure loopback6, the ip address is 10.1.1.7. 45 00:06:04,840 --> 00:06:15,617 okay this is success. Let’s check on router 1, do show ip interface brief exclude unassign, 46 00:06:19,531 --> 00:06:24,284 here we can see that we have interface loopback 4 until 6. 47 00:06:25,097 --> 00:06:30,177 Okay so now we are success to create many interface at once. 48 00:06:31,311 --> 00:06:33,946 Before moving to next video, 49 00:06:33,946 --> 00:06:41,989 let’s remove all interface loopback on router 1, so here we have loopback 0 until 6, 50 00:06:42,104 --> 00:06:48,946 let’s try to remove all of this loopback interface, we can use looping. 51 00:06:49,497 --> 00:06:51,648 Let’s just comment this, 52 00:06:51,944 --> 00:06:59,835 to comment multiple line of code, we can block the script, and then ctrl + /, 53 00:07:03,546 --> 00:07:07,759 Here we can see that all script is become comment. 54 00:07:08,155 --> 00:07:16,334 If we block the script again, and type ctrl + / again, the comment will be gone like this. 55 00:07:16,986 --> 00:07:23,310 If I type ctrl + / again, this script will become comment again. 56 00:07:24,282 --> 00:07:30,934 And then now let’s write a script to remove interface loopback 0 until 6, 57 00:07:31,466 --> 00:07:42,675 so for n in range 0 7, because we want to looping until 6, so we need to write until 7 here. 58 00:07:43,193 --> 00:07:54,420 Or actually, we don’t need 0 here, so we can just type 7. This is will be looping from 0 until 6. 59 00:07:54,906 --> 00:08:03,906 And then here no interface loopback n. here we need to use f string. 60 00:08:05,722 --> 00:08:13,891 Don’t forget \n here for enter. Last, let’s sleep for a half second. 61 00:08:14,405 --> 00:08:22,177 Because the configuration is very simple, so a half second is enough. Save this. 62 00:08:23,288 --> 00:08:31,488 Let’s back to the terminal, execute the script. Enter enter here, 63 00:08:35,660 --> 00:08:42,260 okay here we can see that we are success to remove interface loopback 0 until 6. 64 00:08:43,949 --> 00:08:51,104 Let’s check on router 1 again, show ip interface brief exclude unassign. 65 00:08:51,688 --> 00:08:56,820 Here we can see that we don’t have loopback 0 until 6 anymore. 66 00:08:57,466 --> 00:09:00,755 Okay I think enough for this video, 67 00:09:00,755 --> 00:09:06,722 in the next video, we are going to learn how to configure many router at once. 68 00:09:07,110 --> 00:09:10,747 Thank you for watching and see you on the next video.