GNS3 Talks: Python for Network Engineers with GNS3 (Part 9) - Backup switch configurations.
Udemy: Get the course for $10 here:
https://goo.gl/QYC988GNS3 Academy: Get the course for $10 here:
https://goo.gl/vnZJhgMore free Python videos here:
https://www.youtube.com/playlist?list=PLhfrWIlLOoKPn7T9FtvbOWX8GxgsFFNwnLearn 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 I show you how to open a file and leverage that for configuring Cisco switches. I also demonstrate the importance of spacing in Python.
Code is on GitHub here:
https://github.com/davidbombal/pythonvideos/commit/13574b46f5be90c3316a5a93c1addc5a63e043c8Transcription:
I've had this question asked a number of times: “David can you show us how to backup the conflicts of multiple switches using Python?”
So in this video I'm going to show you a quick demonstration of how you can backup the configuration of multiple devices using Python. This is One of multiple videos teaching you network programmability using Python and GNS3.
So in this topology we have five switches, Switch 1, Switch 2, Switch 3, 4 and 5, which are Cisco IOSv Layer 2 switches. Previously, we created various scripts. One of the files is switchloopfile.py So let's have a look at that file
This script is going to open a file called myswitches and for each align in the file, it's going to telnet to a switch and then it's going to configure various VLANs.
So let's have a look at myswitches, that's a list of IP addresses of switches in the network. What I'll do now is copy switchloopfile.py to getconfigs.py. So nano getconfig.py There's some redundant codes. What I'll do is remove imports.
Let's also add some comments to this code to improve it. So for this first piece of code we'll ask for username and password. This will open a file called myswitches.
Now per Python best practices, you can use either single quotes or double quotes but it's a good idea to be consistent so let me fix that and make it consistent. So what happens here is we are asking the user to enter the username and password then we open a file called myswitches and for each align in the file which consists of an IP address, it's going to print out some information.
So let's say get running config from switch and then it will print out the IP address of the switch. Then what it's going to do is set host equal to the line in the file. Now I'm going to strip redundant information in the line of the file such as hidden spaces in the file.
So when you retrieve an IP address from a file, it's a good idea to strip any whitespace so that you only get the IP address of the device. Then we're going to tell it to the device we're going to enter a username which was previously requested over here so that variable stores the username
...
https://www.youtube.com/watch?v=t-AjBM9P8A8