Python3 Network Programming – Demonstrating Python script execution, link to this GNS3 Topology shown, and other useful links for GNS3 setup! (Part 2/2)

HugeAutoTopLiftOff

I honestly hope this is a really boring post as its been a long day / weekend for me!

I do hope this is a very boring demonstration of my work just working this blog, as I spent Friday into Saturday AM making most of it, and have mostly been taking advantage of the beautiful weather outside to get some fresh are in.

I created this google share URL (for everyone) to download the above Topology:

https://drive.google.com/file/d/10BWGc5-o-1r9pihErfMZHh7PqeUHbxPN/view?usp=sharing

Please note – You must have setup a Router and Switch Appliance using the following VIRL image files however you get them (please don’t ask me):

  • VIRL Switch – vios_l2-adventerprisek9-m.vmdk.SSA.152-4.0.55.E
  • VIRL Router – vios-adventerprisek9-m.vmdk.SPA.156-2.T

The Generic L2 Switch / Virtual PC’s / NetworkAutomation Host is all pre-canned in the GNS3 download, though you will need to ho to the “Host” devices and at the bottom click new Template to download or import the into GNS3 to be available.

Below is David Bombals YouTube Channel to browse for the setup of GNS3 for your particular setup, I didn’t want to post links in case your situation is different from mine as I have Windows 10 / VMware Workstation 10 Pro / VIRL Images available:

https://www.youtube.com/davidbombal

****I have posted this as he shows how to create the VIRL and Host appliances using the “new template” under the device types, and you need to have every one of the devices in this topology shown available in your “All devices” menu!****

Again I really encourage you to also grab his course I am taking for Python on Udemy for $40 if you are looking at DevNet, he is a great instructor and got me fired up to learn automation, and he will get you fired up as well!

Also note all 4 entire configs pulled from Visual Studio Code are located in my previous post but can be found here if you’d rather click that link! 🙂

^^^ I have ran the script, gotten errors returned several times, and have updated this post to have the most updated and correct scripts to not kick out configs, as demonstrated below!

With that, lets get this Automation started and hopefully completed in one swoop!

I’ve verified that the Host Addresses in the Python scripts are now pingable from the NetworkAuatomation-1 Host so no more connection issues:

NetAutoPings

That is my Microsoft Screen Snip skills at work there, all mgmt IP’s are now reachable, I have “debug telnet” running on all devices, and will paste the the NetworkAutomation host then Network Device debug output per device as it hopefully executes properly:

Automation of SW1 from NetworkAutomation-1 Host:

AutoSuccessSW1

Automation of SW1 from CLI (debug telnet):

AutoSuccessSW11

Note that the VLAN’s not existing / being created are the logical VLAN’s themselves, as I only created the Switched Virtual Interface (SVI) for each VLAN, and assigned it an IP Address – Then adding the Host Interface to it creates the logical VLAN on the switch!

Automation of SW2 from NetworkAutomation-1 Host:

AutoSuccessSW2

Automation of SW1 from CLI (debug telnet):

AutoSuccessSW22

Automation of both  R1 AND R2 from NetworkAutomation-1 Host:

AutoSuccesssR1

I could squeeze both output in one screen snip, so I figured why not 🙂

The “debug telnet” CLI output from R1 and R2 (did some verification on R2) :

AutoSuccesssR11

AutoSuccesssR12

And now that I am approaching Midnight after a long weekend, that will do it!

These all show successful deployment, but it did take a lot of running a python script and seeing it return errors, then go into the script via “nano AutoSW1.py” and change / ctrl+o / ctrl+x to update the script the do a “wr er” and “delete vlan.dat” with a reload on the switch and at some point I just made a baseline config I was correcting so many goof ups.

However that is how you learn, but putting your nose to the grind stone 🙂

Below is one brain fart screen shot I will share, where I forgot to remove “vlan” from the command “int gix/x” so it was “int vlan gix/x” throwing errors:

AutoDerp1

Its nice because you can run the script and see exactly what needs to be adjusted, however I suggest making a quick baseline config, like for me it was the following:

en
conf t
host SW1
no ip domain lookup
username looped password back
enable secret loopedback
line con 0
no exec-t
logg sync
line vty 0 15
no exec-t
logg sync
login local
transport input all
exit
int vlan 1
ip add 192.168.238.150 255.255.255.0
no shut
end
wr

So when I had to a wr er / delete.vlan / reload over and over it was just a bit less painful 🙂

Here at the tail end is a little bit of verification that things are working in the lab

PC1 Can reach its remote PC on VLAN 10 but not other PC’s:

Verify1

SW1 verification of HSRP / OSPF / IP Routes:

Verify2

VRRP / OSPF / IP Routes from R1:

Verify3

This just demonstrates essentially that everything is up correctly, R2 is the BDR, R1 is the VRRP Backup, and it shows the VLAN SVI Subnets being learned via OSPF.

This will conclude the simple straight forward automation with Python

Next I will get into using Python Loops and Concatenation methods to add multiple VLANs and see how else we can leverage pythons “malleability” to configure more of this network however I will leave the existing network as is and just add to it here!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s