Category: Python

What did you Expect? Part 5, Basic Error Handling.

In the first four parts of What did you Expect, we covered the basics of getting started with automating interactions for network equipment.  In the first few posts it was important have a networking environment that  was 100% stable.  The last thing I needed when I was trying to learn to use python to automate network devices that were randomly unresponsive and would crash my code.  In order to accomplish that I built a test network you can read about here in GNS3, created a basic configuration to enable a IOS device to be remotely managed.  I also wrote a quick multi-device ping tool to verify that all the devices are responsive before we run remote code against them.  I made my life easy.  But as all operators know our lives are not that cut and dry.  So I started to break things…and my code did not like me. Read more

Get Coding!

So lets start off with I am an old dog and I am learning new tricks.  My entire career I have avoided the dreaded programing.  In college I slid by my degree requirement for a coding class by taking Visual Basic for Industrial applications.  I hated it.  Debugging drove me nuts and there is still a hole in my bedroom wall at my parents where that brick of a VB found itself one night around 2am.  From there I was just gun shy and honestly had plenty of other things going on that could afford to ignore learning anything outside of the basics of HTML and CSS.

Cut to today,  I am in my late 30’s and going through a career transition of sorts.  My timing for the transition is decent because the network industry is also going through a bit of a transition.  For awhile now all the cool kids have been doing automation and Dev/Ops in the Server, OS and application space.  But networks are trickier.  I will leave out all the discussion of why because that horse has been beat dead a few times online.  In this transition over the past six months or so I have found myself doing things I would never have guessed even a year ago.

So what types of things you ask.  Ok for one I am now doing dev work.  Mind you it is not great dev work and I will never be a professional developer but I have been writing code.  In one case even some minor code for a library that is now in production with clients…scary huh.  But mostly I am coding to learn and help move other people along the Path to Automated Networking including myself.

automated networking

Read more

What did you Expect? Part 4, Working with Flat Files.

So far so good.  In Part 1 we connected to a Cisco switch and and performed basic Authentication with Expect.  Part 2 we expanded on that and added configuration to our code that added a VLAN and configured an interface.  But as I have already stated we are writing quite a bit of code just to configure a single switch.  So the next step is to add multiple devices and flat files.  I mean yeah we could setup a static list in our code and add our devices to that but why?  Our real goal here is to create functional code that we can use to do real things in real networks.  So that means pulling a list of devices from NMS, IPAM or even our nasty old excel files.  Plus this helps us address  the idea of adding authentication files and other flat file resource pools.  Eventually we will transition the use of flat files into databases so we can do even more cool stuff but we will hold off on that for now.

Read more

What did you Expect? Part 3, Fixing Stuff and Scaling Out.

When you setup to learn new things you are bound to get a bit sideways once and awhile.  With writing code I think that is even more the case.  You start out with an idea and if your lucky like I have been so far it starts to flow and things just work.  But in the spirit of learning in manageable chunks and sharing the experience with you I started targeting a single host.  When I tried to make the leap to multiple hosts things got interesting.  Along with that it became clear that these posts were going to get messy quick.  So lets clean all that up and move on to the cool stuff. Read more

Setup GNS3 Automation Network in OSX

I have been working to learn how to use Python to automate interactions with network devices.  Due to what I have in my lab and the fact that we have GNS to model Cisco Networks I started with IOS.  In order to really test out the automation scripts I have been building, I felt it was necessary to run them against at least ten devices to make sure they would scale out and recover well from errors.  In order to do that I had to build out a 10 device lab.  This is how I did it. Read more

NAT Store: The books you read and the stuff you use.

One of the lines that I have taken to heart in Life is  “your only difference between now and ten years from now will be the books you read and the people you meet”.  I read it years ago and since then I have doubled down on my reading.  Prior to this I was reading lots of fiction and technical documents around doing my jobs as a network engineer.  Since then I have expanded into Finance, Marketing, Strategy and more.  I can’t begin to tell you the difference in my life it made.  While I won’t go into details actions I took as a direct result of what I was reading helped me go from a mid five figure salary to a solid six figure salary and on a pace that made me part of the businesses I was with not just an employee. Read more

What did you Expect? Part 2: Working with VLANS

So we started off in Part 1 breaking down what a basic SSH connection and authentication looks like using Python and Expect.  To add some context to this I am using the pexpect library for Python.  This library falls back on system level tools like the the SSH client inside OSX or Linux.  I can’t speak to how this works with Windows so just be aware of that as we move forward.  In the long term I will start adding more complexity such as the ParaMiko and NetMiko libraries that use integrated SSH clients but for now I want to keep this as simple as possible so both you and I can get the most value out of these posts. Read more

What did you Expect? Part 1: Connecting to Cisco IOS

Most of my career I have been an network operator.  In that time there have been many repetitive tasks that I wish I could have automated but I simply did not not have the skill or knowledge to do anything about it.  So when Big Matt Stone sat down and showed me what writing code in Expect inside of Python was all about I was BLOWN AWAY!  This is part one of who knows how many in my series of starting to use Expect to automate network tasks. Read more

Setting up Python on OSX: UPDATED

I have spent quite a bit of time over the past few weeks trying to see how development will fit into the course of my career moving forward.  With the help of some great people like Matt Stone and Matt Oswalt I am charging ahead with Python.  This post is about setting up my Mac to be ready to start coding.  Sure I have the default install of Python installed but I have seen that I need more of an IDE than what is provided by default.  Watching Matt Stone code in VIM I was impressed but I have just never spent enough time in VIM to be comfortable.  So I am going to go with Atom and extend it to meet my requirements.  What follows will be that process.

Brew:

OSX is a bit of a hassle when it comes to application management.  A solid package manager solves that. Now I can’t say how good Brew is I can say it has lots of fans and it seems to work for what I need.

So start by installing Brew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

With Brew installed now we can use it to setup Python.  I had a few issues but its because I had tried some other install steps that broke the Brew Process.  Once I fixed those it was easy.

So Just do the following to install Python 2.7.x

brew install python

Sublime Text:

As you can see I have updated this post to show Sublime Text as my IDE.  I really wanted to love Atom but it just had a bunch of random issues that I could not work around.  Since moving to Sublime Text all those issues have vanished.

So start with Download Sublime Text from here.

After you install and run Sublime Text you should check out this superb writeup at RealPython.com on how to turn Sublime into a full featured IDE for Python.  This is what I use and while it is has things I don’t need right now, it is so close to perfect there is no reason for me to mess it up by trying to edit it down.  Just follow it and then your good to go.

Thats about it. From there open up any .py file and you should see any of the PEP8 markers no the left side and all the python syntax broken out.

start.py — pythonCisco 2015-10-18 22-52-21

 

 

 

 

 

 

 

 

With that done you have a base of what you need for for development for Python in OSX.  I have had help from the following sites pulling all this together.

https://realpython.com/blog/python/setting-up-sublime-text-3-for-full-stack-python-development/

http://hackercodex.com/guide/python-development-environment-on-mac-osx/