GNS3 Talks: Python for Network Engineers with GNS3 (Part 5) - Multiple switches, multiple VLANs
51 هزار بار بازدید -
7 سال پیش
-
Udemy: Get the course for
Udemy: Get the course for $10 here: https://goo.gl/QYC988
GNS3 Academy: Get the course for $10 here: https://goo.gl/vnZJhg
More free Python videos here: Python Programming for Network Engineers
Learn Python programming with GNS3. In this series of videos I will show you how you can quickly and easily program Cisco networks using Python. In this video we program a Cisco IOSvL2 switch with VLANs by using Python on an Ubuntu Docker container.
Script on GitHub:
https://github.com/davidbombal/python...
Transcription:
This is one of multiple videos teaching you network programmability using Python and GNS3.
Now that we've been able to automate the configuration of both a Cisco IOSv router and an IOSv Layer 2 switch, we'll now configure multiple switches at the same time.
So I'll drag 4 additional switches to the topology and we'll connect them to the first IOSv switch.
So this is acting as a management network for let's say a core and access layer. So these core switches will be connected to one another and they will be connected to the access switches.
So perhaps something like this. Now what you're going to remember is, these links between switch1 and the rest of the switches in the topology is an out-of-band management network,
these links between the switches would be the network used for user traffic.
Now we could delete these links to the access layer, for now I'm going to leave them there but in a subsequent video we'll use an in-band management VLAN rather than a dedicated link…….
So I'll start up these switches. One of the parts that's going to take the longest is configuring the IP addresses and other information on the switches. I'll open up a console to the devices in the topology.
So the switches are currently booting up. While we're waiting for all the switches
to boot up, let's have a look at our Python script. The first thing I'm going to do is copy script2.py to scripty3.py and then we'll use nano to edit script3.
So this is what the script currently looks like.
In the previous video I showed you how to use a range to configure VLANs on a single switch.Now what's great about using Python directly is you can test things. So if I say range 10 notice it gives me a range from 0 to 9 there are 10 values in the range.
If I say range 74 notice it gives me a range from 0 to 73.
So if I say range 10 again it's in the range 0 to 9. But if I specify 2, 10 that's in the range from 2 to 9. So if I specify 5, 10 that's 5 to 9. If I actually want to use numbers like 5, 6, 7, 8, 9, 10, then I need to specify 11.
So that's something to remember when you create a loops using the range.
In the previous video we wanted to create a VLANs 2 to 100. So I had to specify 101 in the range. Now that's too many VLANs for what we're going to do so let's configure VLANs 2 to 10 on all switches in our topology. The great thing about building networks like this GNS3 is you can try things without being worried that you'll break a live network.
So we can sort of take chances and learn and iterate our scripts as we going along without the fear of breaking a production Network. So what we're going to do now is create a loop to automate the configuration of all the switches in one go.
So what we'll do is we'll configure the VLANs 2 to 10 on all the switches.
Now the first thing we need to do is specify the IP address that we're going to use for the
devices. So currently we only have one IP address but what I want to do is loop through all the IP addresses of the switches.
So we'll change the IP address to 192. 168.122.72 which is the IP address of the first switch. Which we can confirm by logging into the switch and by using the command show ip interface brief.
So there's the IP address of the first switch. We've got 72. We'll configure this switch as 73 74 75 and 76.
So we've got 5 switches. So we'll use 77 here so that it goes in the range 72, 73, 74, 75, 76 to cover our five switches.
Now to tell python that this host line belongs under the loop we need to add some whitespace. So I'll just press tab there. We don't, however, want to enter the username and password five times. So we'll move that above the loop and then we'll remove them here.
So the way the script will work is, it'll ask us to enter the telnet username and password.
In this case because we're going to use the same username and password on all the switches, we only want to be prompted for that once. If the credentials were different on every switch we could add it as part of the loop. So we prompted for the credentials of the individual switches.
So we need to move all this code to the right, so that it's under the loop.
GNS3 Academy: Get the course for $10 here: https://goo.gl/vnZJhg
More free Python videos here: Python Programming for Network Engineers
Learn Python programming with GNS3. In this series of videos I will show you how you can quickly and easily program Cisco networks using Python. In this video we program a Cisco IOSvL2 switch with VLANs by using Python on an Ubuntu Docker container.
Script on GitHub:
https://github.com/davidbombal/python...
Transcription:
This is one of multiple videos teaching you network programmability using Python and GNS3.
Now that we've been able to automate the configuration of both a Cisco IOSv router and an IOSv Layer 2 switch, we'll now configure multiple switches at the same time.
So I'll drag 4 additional switches to the topology and we'll connect them to the first IOSv switch.
So this is acting as a management network for let's say a core and access layer. So these core switches will be connected to one another and they will be connected to the access switches.
So perhaps something like this. Now what you're going to remember is, these links between switch1 and the rest of the switches in the topology is an out-of-band management network,
these links between the switches would be the network used for user traffic.
Now we could delete these links to the access layer, for now I'm going to leave them there but in a subsequent video we'll use an in-band management VLAN rather than a dedicated link…….
So I'll start up these switches. One of the parts that's going to take the longest is configuring the IP addresses and other information on the switches. I'll open up a console to the devices in the topology.
So the switches are currently booting up. While we're waiting for all the switches
to boot up, let's have a look at our Python script. The first thing I'm going to do is copy script2.py to scripty3.py and then we'll use nano to edit script3.
So this is what the script currently looks like.
In the previous video I showed you how to use a range to configure VLANs on a single switch.Now what's great about using Python directly is you can test things. So if I say range 10 notice it gives me a range from 0 to 9 there are 10 values in the range.
If I say range 74 notice it gives me a range from 0 to 73.
So if I say range 10 again it's in the range 0 to 9. But if I specify 2, 10 that's in the range from 2 to 9. So if I specify 5, 10 that's 5 to 9. If I actually want to use numbers like 5, 6, 7, 8, 9, 10, then I need to specify 11.
So that's something to remember when you create a loops using the range.
In the previous video we wanted to create a VLANs 2 to 100. So I had to specify 101 in the range. Now that's too many VLANs for what we're going to do so let's configure VLANs 2 to 10 on all switches in our topology. The great thing about building networks like this GNS3 is you can try things without being worried that you'll break a live network.
So we can sort of take chances and learn and iterate our scripts as we going along without the fear of breaking a production Network. So what we're going to do now is create a loop to automate the configuration of all the switches in one go.
So what we'll do is we'll configure the VLANs 2 to 10 on all the switches.
Now the first thing we need to do is specify the IP address that we're going to use for the
devices. So currently we only have one IP address but what I want to do is loop through all the IP addresses of the switches.
So we'll change the IP address to 192. 168.122.72 which is the IP address of the first switch. Which we can confirm by logging into the switch and by using the command show ip interface brief.
So there's the IP address of the first switch. We've got 72. We'll configure this switch as 73 74 75 and 76.
So we've got 5 switches. So we'll use 77 here so that it goes in the range 72, 73, 74, 75, 76 to cover our five switches.
Now to tell python that this host line belongs under the loop we need to add some whitespace. So I'll just press tab there. We don't, however, want to enter the username and password five times. So we'll move that above the loop and then we'll remove them here.
So the way the script will work is, it'll ask us to enter the telnet username and password.
In this case because we're going to use the same username and password on all the switches, we only want to be prompted for that once. If the credentials were different on every switch we could add it as part of the loop. So we prompted for the credentials of the individual switches.
So we need to move all this code to the right, so that it's under the loop.
7 سال پیش
در تاریخ 1396/01/20 منتشر شده
است.
51,033
بـار بازدید شده