1 00:00:00,382 --> 00:00:07,573 In the previous video, we already learn about the differences between send_command and send_config set. 2 00:00:08,086 --> 00:00:16,031 Next, in this video, we are going to learn how to automate multiple router at once using netmiko. 3 00:00:17,075 --> 00:00:21,320 In this case, we will show the interface on all router. 4 00:00:22,198 --> 00:00:23,463 Let’s just start. 5 00:00:24,148 --> 00:00:30,163 Create new file, let’s say the name is netmiko_looping.py. 6 00:00:35,147 --> 00:00:40,990 And then let’s copy and paste the script from netmiko_basic.py. 7 00:00:42,139 --> 00:00:49,750 Here we can see that we define a dictionary for router 1, if you remember the ip address 8 00:00:49,750 --> 00:01:02,607 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 00:01:03,624 --> 00:01:05,654 Let’s check on on gns3. 10 00:01:06,206 --> 00:01:08,773 Here we can see that we have a pattern. 11 00:01:09,403 --> 00:01:17,032 Router 1 is 10.10.10.1, router 2 is 10.10.10.2 and others. 12 00:01:17,750 --> 00:01:23,949 The differences is only in the last number, the first 3 number is same, 13 00:01:24,899 --> 00:01:32,473 So here, we can do looping like this, for n in range 1,6, 14 00:01:32,937 --> 00:01:37,634 This is means that we do looping on number 1 until 5. 15 00:01:38,562 --> 00:01:42,097 And then let’s add an indentation to this script. 16 00:01:42,904 --> 00:01:46,309 So this script will become part of looping. 17 00:01:47,668 --> 00:01:56,172 Next, we can change this number become n, so we need to use f string here, and then 18 00:01:56,172 --> 00:01:58,203 change this become n. 19 00:02:01,618 --> 00:02:06,898 And then for the router variable, let’s just change this become r, 20 00:02:08,467 --> 00:02:12,000 and then here we also need to change it to r. 21 00:02:13,210 --> 00:02:15,067 Okay we have done here, 22 00:02:15,620 --> 00:02:21,633 the device type of all router will be same, the ip address will be different, the username 23 00:02:21,998 --> 00:02:29,919 and password also will be same on all router, and then connect to the router, this is will 24 00:02:29,919 --> 00:02:38,382 be based on the looping, when the n is 1, so we connect to router 1, when the n is 2, 25 00:02:38,603 --> 00:02:41,702 so we connect to router 2, and others. 26 00:02:42,674 --> 00:02:48,484 And then here, let’s say we just want to send command to show the interface, 27 00:02:49,379 --> 00:02:55,944 so we can comment this script, and then uncomment this script, 28 00:02:56,949 --> 00:03:00,322 Let’s also add exclude unassign here. 29 00:03:06,775 --> 00:03:11,360 And then here, we also need to change this variable to r. 30 00:03:12,620 --> 00:03:15,064 Last, we print the output. 31 00:03:15,749 --> 00:03:18,000 Let’s move this script to the end, 32 00:03:19,437 --> 00:03:23,787 Okay so now we just need 16 lines of code. 33 00:03:24,870 --> 00:03:28,580 This is very simple compared to paramiko. 34 00:03:29,221 --> 00:03:30,367 Save this, 35 00:03:30,809 --> 00:03:39,943 Back to the terminal, ls, here we can see that we have netmiko_looping.py, let’s execute 36 00:03:39,943 --> 00:03:41,071 this script. 37 00:03:43,281 --> 00:03:52,586 Okay here we can see that router 1 is success, router 2 success, router 3 success, router 4 38 00:03:52,586 --> 00:03:56,547 success and router 5 also success. 39 00:03:57,542 --> 00:04:05,608 But here we can see that we don’t have divider between router, so the output is not too good. 40 00:04:06,293 --> 00:04:10,806 Back to sublime, and let’s add a divider. 41 00:04:15,778 --> 00:04:21,000 Save, let’s execute the script again, 42 00:04:21,705 --> 00:04:29,012 okay router 1 success, router 2, router 3, router 4, and router 5. 43 00:04:30,095 --> 00:04:36,000 Okay so now we are success to remote multiple router at once using netmiko. 44 00:04:36,778 --> 00:04:39,208 I think enough for this video 45 00:04:39,540 --> 00:04:42,900 Thank you for watching and see you on the next video.