: I've been spending a significant amount of time looking at the latest buzz around SDN (software defined networking). Along this path I've run into scores of utilities and guides I figured I would share with the community that explain the details of where networking is going along with advice on the different tools to use in order to get a leg up on SDN and network automation. I really didn't see any posts on this so I thought this thread could be a starting point for learning Network Automation in GNS3. I personally come from the "non-programmer" background and have put all my time into learning howto configure Cisco equipment. I haven't put much time into the automation of administration on these devices via scripting language like python, perl, bash, etc. At my current Job as a Network Engineer I have had the opportunity to see from my colleague; who is the Senior Linux Admin; the strong automation tools like chef and puppet which provide very granular administration of servers. The networking realm is still in it's infancy in this area and this is what has started to create this buzz around SDN.
Since I'm new to this myself I thought I would provide a good baseline guide for getting setup using Python for Network Automation within GNS3. Since we just have emulated routers/switches I chose to focus on using python with a "screen scraping" tool called pexpect to get the job done. This will allow us to send cisco IOS commands via ssh to the routers and run powerful scripts against any gns3 network we setup.
Our tools of use will be: gns3, vmware workstation (debian linux), python, python-pexpect moduleUseful SDN Tools
: For real equipment I recommend Ansible. it seems to be the fastest to learn and most scalable of all the SDN. Some of these do require some form of a API to work effectively. google them to find out more.Ansible
(agentless) - won't work in GNS3 due to how python requires the ability to write a .tmp file to the device via an API) - devops automation framework. easy to work with. this seems to be the preferred method for template based configuration. in 2 hours you can get going on this.
very quick to get started
ansible uses playbook concepts for hosts. Run
will fork 5 processes simultaneously to a web server
transfers python file to remote box and executes this
very good configuration templating system
uses yaml to structure config files. very human readible
- templating language ansible ties into. does search and replace on files to repeat informationyaml
- the templating language for the order of operations Ansible uses, is done in this markup languageParamiko
- ssh2 python modulesublimetext
- good editor for code writingvagrant
- vmware automation configurationopenstack
- code respositoryTailIfNCG (Netomata Config Generator)
kiwi cat tools
GNS3 Using Cisco vIOShttp://brezular.com/2014/07/16/cisco-vi ... s-on-gns3/https://readthedocs.org/projects/trigger/https://pynet.twb-tech.com/http://packetpushers.net/show-176-intro ... engineers/http://www.network-janitor.net/2013/11/ ... c-library/http://www.netomata.com/tools/ncghttp://pexpect.readthedocs.org/en/latest/#http://blog.pythonicneteng.com/2012/11/ ... odule.htmlhttps://code.google.com/p/cisco-ios-cli-automation/http://puppetlabs.com/blog/puppet-labs- ... networkinghttps://github.com/knipknap/exscripthttp://trigger.readthedocs.org/en/latest/index.htmlhttps://devopsu.com/http://www.jedelman.com/home/ansible-for-networkinghttp://comeroutewithme.com/2014/05/08/f ... h-ansible/http://classcblock.com/2014/06/23/show- ... utomation/http://keepingitclassless.net/2014/06/n ... on-or-sdn/https://github.com/search?l=Python&p=2& ... =%E2%9C%93http://learnpythonthehardway.org/book/index.htmlhttp://stackoverflow.com/questions/1502 ... -in-pythonhttp://www.codecademy.com/en/tracks/pythonhttp://bioportal.weizmann.ac.il/course/ ... index.htmlhttp://www.slideshare.net/JeremySchulma ... automationhttp://www.greenteapress.com/thinkpytho ... on002.htmlhttp://pexpect.readthedocs.org/en/latest/#Tools Required
: gns3, vmware workstation (debian linux), python, python-pexpect moduleGoal
: To show how gns3 can be used as a network automation test bed using python. I'm providing a baseline to work from. I'm in the process of learning python which seems to be the preferred networking language to pickup for automation at the moment.Guide
: This guide assumes some general knowledge of Linux and configuration of a virtual machine, along with general gns3 configuration.
1. Create a new Linux(Debian) virtual machine using either Microsoft VirtualPC or VMware workstation. I prefer debian since I love the apt-get package manager.
2. place the NIC into bridged mode so it will grab DHCP from your "Internet" network and receive internet access.
3. Get this virtual machine installed and upto the login point. make sure it's got an SSH server installed since we will remote into it later using putty
4. After it's installed we need to make sure python is loaded. to check this simply type in python at the CLI and you should see this:
Python 2.7.3 (default, Mar 14 2014, 11:57:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
5. At this point type quit() to exit out
6. Now lets get our dependencies loaded.
7. from the CLI type in: apt-get install python-pexpect python-paramiko python-getpass python-pip
8. from the CLI type in: pip install getpass
9. That should get our python environment setup
10. Lets move our virtual machine over to the vmnet1 host NIC adaptor so it's in a private network shared with the host and the GNS3 network.
11. Lets move onto the GNS3/SSH configuration. For this step we basically need to hook in the virtual machine's networking to the gns3 lab. follow this guide here for placing the virtual machine into the same network as your GNS3 lab along with configuring SSH access on the router you create in GNS3: https://www.youtube.com/watch?v=R0_7_JD5QLQ
. This guy has a good guide on getting the right NIC attached to the cloud object in GNS3. For that step I chose the NIC in vmnet1 which has a default subnet of 192.168.245.0/24. Whatever network you choose make note of this.
12. configure your gns3 router to be on 192.168.245.2/24. So your Host would be 192.168.245.1/24, your router is 192.168.245.2/24 and your virtual machine would grab dhcp from the Hosts vmnet1 network. by default vmware workstation gives out DHCP on this network.
13. At this point SSH into the virtual machine and ping the router. this should test successfully. Also try to SSH into the GNS3 router. this should also work
14. We are now onto the python part. I've attached a script and written below it's contents (ciscoconnect.py). This will login via ssh to multiple devices, print the running-config, and store this in a file based on the devices IP.
15. To run this simply type it in at the command line ./ciscoconnect.py and it will do it's magic.
16. This script utilizes pexpect which is the python port of expect, the screen scraping utility that allows you to interact with terminal devices.
17. There's a ton more I want to do with experimentation but this gives you a rough framework for running python code against GNS3 routers and seeing how python can be leveraged in network automation.
I updated this with the final code which will perform a backup of the running config, parse the changes.txt file and read those lines into the device and than take a final backup of the running config. This allows for easy change management.
With this said I wanted to create a dialogue with the community and hope this thread creates some productive discussion. I feel that we are in the early stages of DevOps SDN and the earlier we all start collaborating on this stuff, the faster the industry will adapt and create tools to make automation easier.