Automation & Programmability
, Super Contributor
Automation & Programmability
Python for Non-Programmers (Part 1)
11.25.13

PYTHON AS A POWER TOOL

 

When I talk with Network Engineers and Operations teams about automation, often times the response is: "I am not a programmer, so I can't do this".  Worse yet are folks in the blog-o-sphere saying that if networking folks don't become a programmers, they will become obsolete.  This is all rubbish. 

 

Have you ever used Linux, and hacked out a shell "for" or "while" loop to do a quick repetitive task?  I'm sure you have, but would you call that programming?  No, of course not.  I have friends that are in different fields, like science and finance.  They use programming languages, like Python, to do numerical analysis, as a power-tool for their job.  If you ask my friend the scientist if they are a "Programmer", they would say "NO!  I am a Scientist!" 

 

So there seems to be a (self inflicted) distinction between using a programming language as a power-tool and being a programmer as a profession.  And yes, I do believe there is a distinct difference, and no, it does not mean you have a Computer Science degree.

 

So perhaps we can all agree that using a programming language does not make you a programmer.  It's just a power-tool to help you do you job. So now you can get over it, and start to have some fun and be more productive.

 

AUTOMATION IS ABOUT CONSUMPTION

 

My basic thesis is that automation is defined by the nature of the consumer, that is, the person using the automation technology.  The technology could be a purpose built tool/product, an IT framework, a set of language libraries, SDKs, or a combination of the above.  I've even tried to make this concept consumable by creating an analogy to "ice cream" - as described in this blog

 

If we treat automation as consumption, then we must consider the "digestion factor", or "how easy" can we make automation consumable by the user, you, the non-programmer.  If you are presented with an automation task that is "too hard" then it is not consumable, and thus creates "indigestion".   For example, let's say that in order to do some automation task you had to develop in Java and write over 500 lines of code. #fail.

 

My rule of thumb:  Do something useful in less than 50 lines of code, or just do it interactively.

 

THE "JUNOS EZ" LIBRARY FOR PYTHON

 

The "Junos EZ" library is a way for non-programmers to start benefiting from using automation without requiring them to be hardcore programmers.  It is not a set of APIs - APIs are for application programmers - which we've already agreed we are not.  Can Junos EZ be used by "programmers" to build tools? -- of course.  This library could also be the basis of integration with other higher-order IT frameworks (like Ansible or Salt).

 

This series of blogs "Python for Non-Programmers" will introduce the major concepts of Junos EZ.  These include:

 

  • Remote Connectivity and "Fact" Gathering
  • Configuration Management - Structured abstractions
  • Configuration Management - Unstructured snippets and templating
  • Gathering Operational (Run-State) information
  • Multipurpose Utilities (like filesystem, software-upgrade, file-copy)

 

SETUP PYTHON FOR JUNOS AUTOMATION

 

(updated: 2014-Mar-27)

 

The updated installation steps are now posted on the Juniper TechWiki here:

https://techwiki.juniper.net/Automation_Scripting/Junos_OS_PyEZ/Installation

 

TESTING "HELLO, WORLD"

 

Once everything is installed, you can do a quick check by connecting to a Junos device, and displaying the "facts" like software-version and serial-number.  I've documented this example, and others, on a previous blog here.

 

AUTOMATION IS A JOURNEY, AND SO IT BEGINS ...

 

You now have an environment and the consumable tools to begin automation efforts.  I would suggest by starting with "read-only" automation, like gathering statistical information or correlating information like the SRX example.

 

 

FURTHER READING

 

 

04.15.14

@kalsoup,

 

Thank you for your inquiry.  I haven't personally tested the install process on Ubuntu 13.10, but there are install instructions for on the github repo, here. Please review those instructions and let us know if you have any issues.


Thank you!

04.15.14
Juniper Employee

@kalsoup, This appears to be a system related issue.

 

Please update your system packages and setuptools

 

sudo apt-get update
sudo apt-get upgrade
sudo pip install --upgrade setuptools

 

 

http://stackoverflow.com/questions/11425106/python-pip-install-fails-invalid-command-egg-info

04.15.14
kalsoup

Hello @Jeremy, @rsherman,

 

Thank you both for your quick response!

Looks like I was missing setuptools and Paramiko 1.7+. I installed both of them and junoz-eznc is intalled (I think), but it doesn't look "clean":

 

"Cleaning up...
Command /usr/bin/python -c "import setuptools;__file__='/tmp/pip_build_root/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-OTKKcB-record/install-record.txt --single-version-externally-managed failed with error code 1 in /tmp/pip_build_root/lxml
Storing complete log in /home/.pip/pip.log"

Junos-eznc however does show up as installed

 

$ pip list
junos-eznc (0.0.5)
ncclient (0.4.1)

 

When I try to run a test script from Jeremy's examples (inventory.py), I get :

 

Traceback (most recent call last):
  File "inventory.py", line 4, in <module>
    jdev.open()
  File "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py", line 242, in open
    hostkey_verify=False, device_params={'name':'junos'} )
  File "build/bdist.linux-x86_64/egg/ncclient/manager.py", line 96, in connect_ssh
  File "build/bdist.linux-x86_64/egg/ncclient/transport/ssh.py", line 188, in connect
ncclient.transport.errors.SSHError: Could not open socket to 172.27.12.1:830


Netconf has been enabled on the Junos device.

 

root@wt-ubuntu:/home/projects/Juniper/Scripts# ssh -s 172.27.12.1 netconf
root@172.27.12.1's password:
<!-- No zombies were killed during the creation of this user interface -->
<!-- user root, class super-user -->
<hello>
  <capabilities>
    <capability>urn:ietf params:xml:ns:netconf:base:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:candidate:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:confirmed-commit:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:validate:1.0</capability>
    <capability>urn:ietf params:xml:ns:netconf:capability:url:1.0?protocol=http,ftp,file</capability>
    <capability>http://xml.juniper.net/netconf/junos/1.0</capability>
    <capability>http://xml.juniper.net/dmi/system/1.0</capability>
  </capabilities>
  <session-id>99021</session-id>
</hello>
]]>]]>

 

I will do some more testing and make sure I have all the dependencies and maybe even try a fresh install of Ubuntu.

 

Do you see anything else that might be amiss?

I downloaded ncclient from https://pypi.python.org/pypi/ncclient/0.4.1 and installed it in my "home" projectc directory. Can this directory path be an issue?

 

Thanks again and much appreciate your help!

 

 Edit:

 

It worked!!!

 

root@wt-ubuntu:/home/projects/Juniper/Scripts# python inventory.py
model: SRX210HE2
serial-number: CD3813AK0157

 

To summarize:

1. I was missing Setuptools and Paramiko

2. Netconf has to be opened under the 'edit system services' heierarchy AND 'edit security zones security-zone <your-zone>' heirarchy.

 

I'm super excited to get started with JunOS_PyEZ.

 

Thanks a lot @Jermey and @rsherman for you help!!

 

 

 

Top Kudoed Authors
User Kudos Count
1