GNS3 Talks: Python for Network Engineers with GNS3 (Part 14) - Netmiko, SSH, Python Cisco switches
David Bombal
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: https://www.youtube.com/playlist?list=PLhfrWIlLOoKPn7T9FtvbOWX8GxgsFFNwn
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:
https://github.com/davidbombal/pythonvideos/commit/8a39cd4b16afc8f34564b1201d0d37800dd50c81
Transcription:
This is one of multiple videos teaching you network programmability using Python and GNS3. This is one of the multiple videos showing you how to use Netmiko to configure a GNS3 topology.
In this topology, we have 5 Cisco IOSv switches; Switch 1, Switch 2, 3, 4 and 5. Switch 1 and 2 are acting as core switches in this topology and switches 3, 4, and 5 are acting as access switches. I've got an Ubuntu docker container with Python installed as well as Netmiko.
We will use a Python script to configure this port, this port and of this port as access ports in this campus topology and all the links between the switches will be configured as trunk ports. Switch 1 and Switch 2 have been configured a spanning tree root and backup root but essentially, all that's been configured on these switches is IP addresses and SSH to allow the Python script to SSH to the switches and configure them.
So essentially the switches have been configured with an IP address and SSH to allow the Python client to SSH to them and configure them.
The Python script that we are going to use is fairly simple. We're using Netmiko, so we've got to the statement from Netmiko import connect handler. We are then specifying the details of the switches in the topology. Switch 1 has this IP address, Switch 2 has this IP address, Switch 3, Switch 4 and Switch 5.
I've named the devices iosv_l2_s1, here's s2, s3, s4 and s5. Now we could optimize the code more than we have here.
But notice there's only a few lines to configure the switches. I'm using a with statement to open a file called iosv_l2_ config that file will have these commands in it.
Essentially, what we're going to do in the topology is create a VLAN 2 and configure interfaces gigabit 2/0 - 3 as access ports in VLAN 2.
At the moment only gigabit 2/0 is connected to a PC. But let's assume that there are additional interfaces that need to be configured in VLAN 2,
So these are the access ports on the switch. Other interfaces, so gigabit 0/0 - 3 will be configured as trunk ports.
We’ll explicitly configure the encapsulation as dot1q set the mode to trunk. Turn off DTP and allow VLANs 1 and 2.
In addition, we could configure gigabit 1/0 and 1/1. So we could d ... https://www.youtube.com/watch?v=gEVFRBnjpS4
50181289 Bytes