1 00:00:00,150 --> 00:00:06,720 Now that we've been able to telnet from the network automation container to the router and make changes 2 00:00:06,720 --> 00:00:10,860 to it, let's do something similar with the switch. 3 00:00:11,940 --> 00:00:17,520 So on the network automation container, we currently have a script Python three one API. 4 00:00:17,760 --> 00:00:23,810 I'm going to copy that script to another script called Python 32. p y. 5 00:00:24,480 --> 00:00:31,560 So we've now got two scripts and what I'll do now is edit python 32. p y. 6 00:00:33,070 --> 00:00:37,030 In this example, we want to configure a different device. 7 00:00:37,150 --> 00:00:40,030 So let's configure the switch with IP address. 8 00:00:40,030 --> 00:00:43,330 1921681 2272. 9 00:00:44,080 --> 00:00:45,850 He has the console of the switch. 10 00:00:47,590 --> 00:00:49,010 So I'll give it a name. 11 00:00:49,030 --> 00:00:50,020 Switch one. 12 00:00:50,350 --> 00:00:53,680 Do show IP interface brief. 13 00:00:54,160 --> 00:00:56,620 Shows us interfaces on the switch. 14 00:00:58,390 --> 00:01:00,220 What I'll do here is configure. 15 00:01:01,960 --> 00:01:04,269 The IP address on VLAN one 16 00:01:07,060 --> 00:01:16,090 slash 24 mosque and I'll no shut interface VLAN one so show IP interface brief again. 17 00:01:17,230 --> 00:01:24,490 We've now got vlan one configured with this IP address and the interface is up, up. 18 00:01:26,690 --> 00:01:32,040 What I now need to do is configure a username to be consistent. 19 00:01:32,060 --> 00:01:35,930 I'll keep it the same configure and enable password. 20 00:01:36,290 --> 00:01:43,670 In the real world you may want to use a secret password, but this is fine for our examples and allows 21 00:01:43,670 --> 00:01:51,320 us to verify our scripts as we can see the usernames and passwords used log in. 22 00:01:51,320 --> 00:02:01,190 A local is going to be used on the v lines and we're going to allow all protocols to access the v t 23 00:02:01,190 --> 00:02:01,940 lines. 24 00:02:02,740 --> 00:02:04,840 So back on the network automation container. 25 00:02:04,870 --> 00:02:06,460 I'll save that script. 26 00:02:07,090 --> 00:02:10,870 Let's confirm that we can ping the switch. 27 00:02:10,900 --> 00:02:12,010 Yes, we can. 28 00:02:12,310 --> 00:02:15,730 Can we telnet to the switch? 29 00:02:16,300 --> 00:02:17,320 Username is david. 30 00:02:17,320 --> 00:02:20,140 Password is cisco type enable. 31 00:02:21,000 --> 00:02:28,230 And the answer is yes, we can telnet and access enable mode onto the switch from the network automation 32 00:02:28,230 --> 00:02:28,980 container. 33 00:02:31,010 --> 00:02:39,590 So on a script are we going to telnet to the switch IP address one on 21681 2272 we're going to prompt 34 00:02:39,680 --> 00:02:46,790 the user for the username and password and at this point the script is going to telnet to the switch. 35 00:02:47,690 --> 00:02:49,370 It's going to look for username. 36 00:02:50,270 --> 00:02:58,190 So again, we can confirm that the same process is used on the switch by telnet to the switch. 37 00:03:00,940 --> 00:03:03,160 So telnet to the switch. 38 00:03:03,370 --> 00:03:08,200 Your username is what's prompted for and then password. 39 00:03:08,530 --> 00:03:14,170 So this code can be reused for the telnet connections to the switch. 40 00:03:14,680 --> 00:03:18,970 All I've done at this point is change the IP address. 41 00:03:20,010 --> 00:03:20,700 On the switch. 42 00:03:20,700 --> 00:03:26,370 We need to tap, enable and the password of Cisco so that stays the same. 43 00:03:26,580 --> 00:03:35,220 We then go to global config mode and rather than creating loopback, let's configure VLANs on the switch. 44 00:03:35,790 --> 00:03:40,200 So I'll configure VLAN two and give it a name. 45 00:03:41,400 --> 00:03:43,410 Of Python. 46 00:03:43,560 --> 00:03:44,850 VLAN two. 47 00:03:47,130 --> 00:03:54,090 So basically on the switch, we're going to go to global config mode type VLAN two and then configure 48 00:03:54,090 --> 00:03:58,830 a name of Python VLAN two. 49 00:03:59,010 --> 00:04:01,020 So let's do it like this. 50 00:04:03,130 --> 00:04:10,180 So hopefully when we run the script, we should see a result like this. 51 00:04:10,810 --> 00:04:17,230 So what I'll do is remove vlan two from the switch show vlan 52 00:04:19,240 --> 00:04:20,019 brief. 53 00:04:20,800 --> 00:04:24,250 We only have the default vlans on the switch. 54 00:04:24,970 --> 00:04:34,810 What I'll do here is delete a lines by using control k and then I'll copy these lines into the script. 55 00:04:36,250 --> 00:04:44,470 Now programmers with lots of experience will tell you that you should use loops and not duplicate code 56 00:04:44,770 --> 00:04:46,060 like we're doing here. 57 00:04:47,020 --> 00:04:48,580 Again, that is true. 58 00:04:49,270 --> 00:04:51,460 We'll get to that later. 59 00:04:52,760 --> 00:04:57,410 For now, let's configure VLANs two, three, four and five on the switch. 60 00:04:57,860 --> 00:05:04,040 Later on, we'll use a loop to configure 100 VLANs on the switch. 61 00:05:04,580 --> 00:05:10,010 After the moment we only have VLAN one as the ethernet VLAN. 62 00:05:10,460 --> 00:05:12,800 We're not going to worry about these vlans. 63 00:05:12,830 --> 00:05:16,070 They are not supported on the switch anyway. 64 00:05:17,420 --> 00:05:18,680 I'll save the script. 65 00:05:19,160 --> 00:05:20,570 Python three. 66 00:05:20,570 --> 00:05:24,140 Python 32. p y. 67 00:05:25,280 --> 00:05:26,270 Username is David. 68 00:05:26,270 --> 00:05:27,560 Password is cisco. 69 00:05:27,590 --> 00:05:32,690 Before I press enter debug telnet on the switch. 70 00:05:33,200 --> 00:05:34,310 Press enter now. 71 00:05:35,030 --> 00:05:38,300 We can see that the script is telling to the switch. 72 00:05:39,150 --> 00:05:44,100 We can see on the network automation container that vlans were created on the switch. 73 00:05:44,520 --> 00:05:47,040 So show VLAN brief. 74 00:05:48,130 --> 00:05:52,030 We can see that those VLANs were created on the switch. 75 00:05:53,660 --> 00:05:55,370 So it was as simple as that. 76 00:05:55,880 --> 00:06:08,690 To configure VLANs on a Cisco switch using Python, I could copy those lines of code and edit those 77 00:06:08,690 --> 00:06:11,690 lines to create more VLANs. 78 00:06:12,950 --> 00:06:14,390 So let's create. 79 00:06:17,150 --> 00:06:18,590 Eight VLANs on the switch. 80 00:06:18,620 --> 00:06:28,340 For example, so VLAN six, seven and eight will now be created on the switch back on the switch once 81 00:06:28,340 --> 00:06:30,860 again we only have VLANs. 82 00:06:30,860 --> 00:06:32,900 One, two, three, four and five. 83 00:06:33,590 --> 00:06:35,390 But if I run the script again. 84 00:06:37,900 --> 00:06:43,360 Script telnet to the switch and has created these additional vlans. 85 00:06:43,690 --> 00:06:46,000 So show vlan brief. 86 00:06:47,520 --> 00:06:50,160 They are the vlans on the switch. 87 00:06:52,810 --> 00:06:55,510 So we've now got two scripts. 88 00:06:56,830 --> 00:06:57,580 Python three. 89 00:06:57,580 --> 00:06:58,720 Python three, one. 90 00:06:58,900 --> 00:07:01,780 P y makes changes to the router. 91 00:07:03,460 --> 00:07:07,450 Three two makes changes to the switch. 92 00:07:10,450 --> 00:07:13,270 These are, again, very simple scripts. 93 00:07:16,610 --> 00:07:25,070 But hopefully it shows you how you can configure network devices using Python with just a few lines 94 00:07:25,070 --> 00:07:25,850 of code. 95 00:07:26,480 --> 00:07:33,260 This is not a very large script, but we've been able to use the script to make changes to the network 96 00:07:33,260 --> 00:07:34,250 devices. 97 00:07:34,880 --> 00:07:38,300 Now again, you may want to use a more powerful. 98 00:07:39,370 --> 00:07:47,260 I.D. to make your changes so you could use something like sublime text, pie, charm or something else 99 00:07:47,260 --> 00:07:53,410 to do your actual editing, and then you can simply paste those scripts into the network automation 100 00:07:53,410 --> 00:07:54,130 container. 101 00:07:54,700 --> 00:08:01,570 I'm going to do that later in the course as our scripts become more powerful and more complicated. 102 00:08:02,020 --> 00:08:08,080 I just want to get you started automating once you get started and see what's possible. 103 00:08:08,200 --> 00:08:15,070 Hopefully you can think of other scenarios and other things that you can do using Python to automate 104 00:08:15,070 --> 00:08:15,910 your network.