GNS3 Talks: Python for Network Engineers with GNS3 (Part 3) - Remove Passwords and improve scripts
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. In this video we program a Cisco IOSvL2 switch with VLANs by using Python on an Ubuntu Docker container.
Script used in this video is available on GitHub here: https://github.com/davidbombal/pythonvideos/commit/da3045beca3c1b8766b2c9c92d2cdf55b3b8f7f1
Transcription:
This is one of multiple videos teaching you network programmability using Python and GNS3. So currently we have two scripts: Python1script1 and Pythons1script1. What I'll do is copy the s1 script to a file called s1script2.py notice we've changed the extension to the py
If I try and run at that script notice we’re told that the command is not found.
We could still use Pythons1 and run the script this way and notice the changes have been made to the switch we can see here that the switch was configured. But we may want to improve things by simply running the script as follows.
So let's use nano to edit the script.
Notice the difference it's now showing the text in colors so that's a lot nicer but what I'm also going to do is a reference Python in the script.
Now in Unix and executable file that's meant to be interpreted can indicate which interpreter to use by having hash exclamation mark or pound-bang if you prefer at the start of the first line followed by the interpreter.
So as an example, how does the operating system know if this is a bash script or a Python script?
This allows us to indicate that information so I'm going to save the script. Now when I run it, it's still not running. A good Linux command is clear to clear the screen so at the moment we have our script but it's not executable. I'm going to change the permissions on the script to make it executable.
So I'm going to specify that the script is now executable by adding the executable permission using change mod +x. Notice it's a lowercase x.
ls now shows us that the script color has changed so I can now run the script simply by entering its name. And notice the script run.
Now the best way to find files within this directory is to use ./ and then search for the name. Notice when I press tab it autocompletes but if I do this it's not going to autocomplete. So get into the habit of using ./ for files in the local directory , I’ll break that script.
So to prove that this works, nano and specify the script. So let's edit the script and what I'll do is simply add another VLAN to our switch.
So I'm going to specify VLAN_7 and giv ... https://www.youtube.com/watch?v=ViGoIl0-g7s
57953569 Bytes