1 00:00:00,210 --> 00:00:04,920 Now, one thing that you shouldn't be doing is reinventing the wheel. 2 00:00:05,689 --> 00:00:07,610 Don't redo code. 3 00:00:07,640 --> 00:00:11,030 Try and leverage what you've created previously. 4 00:00:11,420 --> 00:00:20,900 So as an example, if I look at Python three for p y, we previously created a loop here that created 5 00:00:20,900 --> 00:00:24,770 a bunch of VLANs on a single switch. 6 00:00:25,430 --> 00:00:34,400 In the previous video we opened up a file called My Switches and then created a VLANs. 7 00:00:35,710 --> 00:00:38,980 Owner the switches listed in the file. 8 00:00:40,410 --> 00:00:47,220 So what you'll notice now is this code looks exactly the same as my new script. 9 00:00:47,460 --> 00:00:49,950 Python three six API. 10 00:00:50,520 --> 00:00:54,000 Here's Python 35. y. 11 00:00:54,330 --> 00:00:57,450 Yes, python 36. p y. 12 00:00:59,130 --> 00:01:03,150 The change that we're making here is we're going to use. 13 00:01:04,260 --> 00:01:10,620 Thus a loop that we previously created and use that in our script. 14 00:01:10,920 --> 00:01:14,430 So I've simply copied these lines of code. 15 00:01:15,320 --> 00:01:18,680 And I've changed the number of VLANs to 21. 16 00:01:22,080 --> 00:01:26,340 So I've been able to remove this code, which wasn't ideal. 17 00:01:28,300 --> 00:01:30,400 And I've replaced it with a loop. 18 00:01:30,970 --> 00:01:32,230 Apart from that. 19 00:01:33,190 --> 00:01:36,430 Everything is the same as our previous script. 20 00:01:37,150 --> 00:01:40,270 Previously we opened a file called My Switches. 21 00:01:41,830 --> 00:01:43,330 That's what we're doing here. 22 00:01:43,570 --> 00:01:51,610 We're opening up a file called My Switches, and then for each IP address in the file we are going to 23 00:01:51,610 --> 00:01:53,620 telnet to the switch. 24 00:01:54,540 --> 00:02:03,450 Login, go to global configuration mode and now create a bunch of VLANs on that switch. 25 00:02:04,160 --> 00:02:07,190 So what I'll do is copy this code. 26 00:02:08,449 --> 00:02:15,650 Go to the network automation container and create a file called Python three six. 27 00:02:16,100 --> 00:02:17,030 P y. 28 00:02:17,660 --> 00:02:19,760 And I'll paste that code in. 29 00:02:21,130 --> 00:02:22,420 And save it. 30 00:02:23,050 --> 00:02:24,580 So python three. 31 00:02:24,580 --> 00:02:26,410 Python three six. 32 00:02:26,710 --> 00:02:27,580 P y. 33 00:02:27,850 --> 00:02:37,990 Before I press enter, notice that on switch one as an example, we only have vlans up to vlan eight. 34 00:02:39,050 --> 00:02:42,170 The same is true on switch three. 35 00:02:43,130 --> 00:02:45,040 Show vlan. 36 00:02:45,170 --> 00:02:45,800 Brief. 37 00:02:48,000 --> 00:02:51,540 We only have a vlans up to vlan eight. 38 00:02:52,020 --> 00:02:53,850 Same is true on switch six. 39 00:02:53,850 --> 00:02:55,320 Show VLAN brief. 40 00:02:55,920 --> 00:03:02,730 We only have eight ethernet vlans so run the script username is David. 41 00:03:02,730 --> 00:03:04,020 Password is Cisco. 42 00:03:04,500 --> 00:03:08,580 It's toll needing to switch one at the moment he has switched to. 43 00:03:09,180 --> 00:03:11,460 You can see the telnet debug. 44 00:03:14,990 --> 00:03:17,660 Show we brief. 45 00:03:20,700 --> 00:03:28,170 Notice 20 VLANs have been created on switch to the script is already configuring switch for. 46 00:03:31,180 --> 00:03:35,710 You can see the telnet debug output show vlan brief. 47 00:03:36,920 --> 00:03:41,450 We've got 20 vlans configured on the switch. 48 00:03:42,340 --> 00:03:44,830 And the same is true for the other switches. 49 00:03:44,950 --> 00:03:48,700 So as an example, show vlan brief on switch six. 50 00:03:49,180 --> 00:03:51,250 We've got 20 vlans. 51 00:03:52,190 --> 00:04:03,110 So this simple script can telnet to as many switches as we want and configure as many VLANs as we want 52 00:04:03,680 --> 00:04:06,200 by making that simple change. 53 00:04:07,730 --> 00:04:15,770 The script will now telnet to the switches and configure 30 VLANs. 54 00:04:16,950 --> 00:04:18,839 So there's our original 20. 55 00:04:21,220 --> 00:04:24,790 But now you can see 27 have been configured. 56 00:04:25,120 --> 00:04:26,680 Run the command again. 57 00:04:28,250 --> 00:04:31,010 30 VLANs have now been configured. 58 00:04:32,070 --> 00:04:36,150 The switch has configured switch three to now configured switch for. 59 00:04:37,600 --> 00:04:38,800 So in search for gain. 60 00:04:38,800 --> 00:04:39,460 Shall we land? 61 00:04:39,460 --> 00:04:40,150 Brief. 62 00:04:43,350 --> 00:04:46,470 30 VLANs have been configured. 63 00:04:48,200 --> 00:04:50,420 And on switch six. 64 00:04:52,080 --> 00:04:54,900 30 VLANs have now been configured. 65 00:04:56,460 --> 00:04:58,560 So this is the power of automation. 66 00:04:59,130 --> 00:05:03,090 Just iterate and improve your scripts as you go along. 67 00:05:03,750 --> 00:05:07,860 With just those three lines of code added to the script. 68 00:05:07,860 --> 00:05:14,100 We can get to the script to configure many VLANs on many switches. 69 00:05:15,240 --> 00:05:22,890 If you want to configure additional switches, simply add IP addresses to the my switches file and then 70 00:05:23,340 --> 00:05:31,830 the script will loop through the file and configure those switches with the VLANs. 71 00:05:32,220 --> 00:05:37,050 Now one thing we haven't done is save the configuration of our switches. 72 00:05:37,620 --> 00:05:49,800 So to get the script to do that, I could simply copy and paste a line here for saving the switch configurations. 73 00:05:50,370 --> 00:05:59,400 And then I could say Python three, Python three, six MP y and get to the script to telnet to each 74 00:05:59,400 --> 00:06:00,060 switch. 75 00:06:01,260 --> 00:06:06,150 Configure the switch and then save the switch configuration. 76 00:06:08,220 --> 00:06:09,960 It's now configuring switch to. 77 00:06:12,270 --> 00:06:14,910 You can see the telnet debug output. 78 00:06:15,970 --> 00:06:19,750 And as you can see, the configuration has been saved. 79 00:06:20,850 --> 00:06:21,330 David. 80 00:06:21,330 --> 00:06:25,470 Tony added to the switch and saved the configuration. 81 00:06:26,510 --> 00:06:30,320 You can see something similar in the output of the script. 82 00:06:30,650 --> 00:06:39,410 So the lesson was network automation and network programmability is iterate your scripts, keep on improving 83 00:06:39,410 --> 00:06:44,870 your scripts and enhancing the features available in your scripts. 84 00:06:45,200 --> 00:06:51,230 Start small and then keep on improving your scripts to do more and more.