filmov
tv
GNS3 Talks: Python for Network Engineers with GNS3 (Part 13) - Netmiko, SSH, Python Cisco switches
Показать описание
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.
================================
Script on GitHub:
================================
Transcription:
This is one of the multiple videos teaching you network programmability using Python and GNS3.
In the previous video I showed you how to use Netmiko to configure a single IOSv switch in GNS3.
Now we'll extend to the topology and configure three switches. So I've got three switches booted and configured for SSH in GNS3 and I can now configure them through Netmiko. Netmiko makes it easy. This is the configuration for switch 1 here's the configuration for switch 2
Here's the configuration for switch 3. If I have additional switches I would simply configure those additional switches in the Python script and now what I can do is create a variable that contains IOS v layer 2 switch 1 switch 2 and switch 3 and then I can run a loop. So I can say four devices in all devices, in other words these three switches we're going to connect to those devices and then I'm going to run a sub loop where I create 20 VLANs on each of those switches. So it's quite a simple script which I'll now copy.
Here's my Ubuntu host I've got a script called a Netmiko1. So let's create another one called Netmiko 2 and I'll paste that script in.
The script is once again available on github and I've referenced it below this video. So there's the script. Now before I run the script I'll reduce the number of VLANs to 5 so that you don't have to watch me wait for the VLANs to run.
So now python netmiko2 before I run the script, let's have a look at the VLANs on Switch 2 as an example.
show vlan brief switch 2 only has the default VLANs configured
switch 3 sh vlan brief only has the default VLANs configured switch 1 was previously configured.
So it has more VLANs, so sh vlan brief notice it has 30 VLANs configured but what we should notice is when the script SSH is into the switches that it will configure VLANs on switch 1 which is currently doing and then it will connect to switch 2 and switch 3 and configure the 5 VLANs.
So it's now configured the VLANs on switch 1. We’re told that it's creating VLAN to which will be on switch 2. We can see that it's connected to switch 2, so sh vlan brief, we can see that 4 VLANs have been configured on switch 2 and now 5 VLANs have been configured.
sh vlan brief there was a problem accessing switch 3. Notice there's a trace back saying that there's a problem on switch 3.
So let's look at the code and make sure that everything looks good so that all looks the same. Can we ping 192.168.122.73 yes we can but perhaps SSH hasn't been enabled properly on this switch.
So let's 192.168.122.73 notice the connection is refused. So let's ensure that the keys are created.
So crypto key generate RSA.
Let's try and SSH again. Notice we are asked whether we want to login and we can access the switch. So let's run the script again and make sure that the VLANs are configured on the 3 switches. So it's currently configuring switch 1, I’ll speed the video up so said that you don't have to watch it cycle through the VLANs again.
It’s configuring switch 2 at the moment and now its configuring switch 3.
So show vlan brief you can see 4 VLANs configured 5 VLANs have been configured.
So the script has successfully configured 5 VLANs on the three switches. So it was as simple as that to configure 3 switches with the VLANs using a very basic Python script.
Now again these scripts can be optimized but at this point I simply want you to see that it's
possible for you to configure network devices using Python. It may sound really complicated and very difficult but actually it's not.
I hope you enjoyed this video. If you did, please like it and please subscribe to my YouTube channel. I wish you all the very best!
Комментарии