Installing the Junos EZ Library – Easy SDN Part 1

This post follows on from my last post about the Junos EZ Library, Jeremy Schulman’s work to make Junos devices easily manageable via Python, even for those of us who are not hard core programmers by trade.

In order to run the Junos EZ library I had to prepare my Ubuntu system with a few pre-requisites. Jeremy’s first post talks about what’s required on his CentOS Developer Workstation; this post does the same for Ubuntu server.

My System

I’m running Ubuntu Server 12.04.3 LTS. I say that because if you are running something different, or chose slightly different options at install time, your experience may be different. In principal though, these commands should not, I would think, hurt your system – if something’s already installed, it should just say so and move on.

Disclaimer

This software is in an early development stage (v0.0.2) and if you trust my commands in a production system, you’re as silly as you’ll look when it goes wrong. Follow my crazy guide at your own risk in a safe environment; it’s your fault if you take down something in production, ok?

Pre-Requisites

Jeremy states that the following commands need to be run:

# Install the NETCONF 'ncclient' library:
pip-2.7 install git+https://github.com/Juniper/ncclient.git

# Install the Junos "EZ" library:
pip-2.7 install git+https://github.com/jeremyschulman/py-junos-eznc.git

But hold on, because those commands need other things to be in place in order to succeed. At the very least, along with the above, you will need Python 2.7 and the “pip–2.7” tool. On my Ubuntu server, I had Python 2.7 installed, but the rest took a few more steps.

Steps

Check Python Version

First, check that you are running a version of Python 2.7. If not, you’ll need to upgrade accordingly (I’ll leave that to a Google search for you):

john@dns2:~$ python --version
Python 2.7.3

LibXML

One of the Junos library requirements is libxml. This can be installed with the following command if not already present:

sudo apt-get install libxml2-dev libxslt-dev

Pip–2.7

Jeremy’s guide is very insistent that pip–2.7 is the required command, but by default that isn’t available on my Ubuntu build. Sadly, neither is ‘easy_install’, which is how I would install it, so let’s fix that too:

sudo apt-get install python-setuptools
sudo easy_install-2.7 -U pip

Git

One of my systems had git installed, and one did not. Check if git is installed:

root@dns2:/home/john# git --version
git version 1.7.9.5

If not, install it:

sudo apt-get install git

Python-Dev

It’s endless, isn’t it? You also need Python-Dev installed in order to supply the header files needed by the Junos EZ installation:

sudo apt-get install python-dev

Install Junos EZ Libraries

Yes, at last we are here! Give it a shot:

sudo pip-2.7 install git+https://github.com/Juniper/ncclient.git

The installation may take a few minutes and pauses concerningly at some points. When complete, check for errors; the installation on my system generated many warnings, but ultimately claimed success at the end:

Successfully installed lxml ncclient ecdsa
Cleaning up...

With one success under our belts, let’s try the second EZ installation:

sudo pip-2.7 install git+https://github.com/jeremyschulman/py-junos-eznc.git

Hopefully you’ll get a success message at the end:

Successfully installed netaddr jinja2 scp junos-eznc markupsafe
Cleaning up...

If so, it’s time to test it out! Well, almost…

Prepare Your Junos Device

There’s no point having all this running if you don’t prepare your Junos device to be probed by the library. It takes one command:

set system services netconf ssh port 830

Once committed, this enables netconf over ssh, which is used by the Junos EZ library in the background.

Testing Junos EZ

Here’s a short test script brutally ripped from Jeremy’s web site. Put in the hostname or IP of the Junos device that you configured to run Netconf, and fill in the username and password in the appropriate places:

from pprint import pprint
from jnpr.junos import Device
dev = Device(host='<hostname>', user='<username>', password='<password>' )
dev.open()
pprint( dev.facts )
dev.close()

You should get a result something like this when you run it (in my case the script was saved in a file called “eztest”):

john@dns1:~/jnpr$ python eztest
{'2RE': False,
 'RE0': {'last_reboot_reason': '0x2:watchdog ',
     'mastership_state': 'master',
     'model': 'EX3200-24T, 8 POE',
     'status': 'OK',
     'up_time': '47 days, 13 hours, 57 minutes, 54 seconds'},
 'fqdn': 'noisy',
 'hostname': 'noisy',
 'ifd_style': 'SWITCH',
 'master': 'RE0',
 'model': 'EX3200-24T',
 'personality': 'SWITCH',
 'serialnumber': '1234567890',
 'switch_style': 'VLAN',
 'vc_capable': False,
 'version': '12.3R3.4',
 'version_info': junos.versino_info(major=(12, 3), type=R, minor=3, build=4)}

Cool, right? Ignore the typo in “version” – Jeremy will fix the typo in facts/swver.py soon I’m sure (right? ;-)). Folks, this is what early release means – it comes with free typos! Still, for a 6 line script – 5 of which are probably the same for every script you right, and one of which generated the output above – that’s pretty sweet in my opinion.

What Next?

If you’ve got this far and successfully run the test script, wait for my next post about Junos EZ, which will look a little deeper at grabbing interface information, and talk to how I expanded the included functionality to create a web page for my home switch that summarized the status of all the interfaces with the information I wanted on it.

13 Comments on Installing the Junos EZ Library – Easy SDN Part 1

  1. Hi John,

    Thank you for the post. I should have done a better job with the “dependency” thing. The “pip-2.7” is not the dependency, it is Python 2.7. So if your system (Ubuntu) comes stock with Python 2.7, you should be able to use the standard “pip” tool. In my case I was using CentOS 6.4, and Python 2.6 was stock. I will clarify/update my blog to fix this.

    I will also fix the “version” type, thank you!

  2. Thanks..instructions were useful.

    Just in case someone else have the same problem –

    I didn’t have gcc installed so had to install buildtools first.. “sudo apt-get install build-essential”

  3. Hi — Thanks for this set of instructions! Huge help!

    I have the exact same set up as you have, xubuntu 12.04 3, python 2.7

    But, something has recently changed, and I had to do the following just

    before doing the git+https:// install step:

    sudo pip install setuptools –no-use-wheel –upgrade

    Otherwise pip complains about “Wheel installs require setuptools >= 0.8 for dist-info support.” and then exits.

    Thanks again for posting this step by step guide. Saves the rest of us hours!

    Dave

  4. Interesting…I get the wheel error regardless 🙁

    chris@ubuntu:~$ sudo pip install setuptools –no-use-wheel –upgrade
    Wheel installs require setuptools >= 0.8 for dist-info support.
    pip’s wheel support requires setuptools >= 0.8 for dist-info support.
    Storing debug log for failure in /home/chris/.pip/pip.log

    chris@ubuntu:~$ sudo pip install git+https://github.com/Juniper/ncclient.git
    Wheel installs require setuptools >= 0.8 for dist-info support.
    pip’s wheel support requires setuptools >= 0.8 for dist-info support.
    Storing debug log for failure in /home/chris/.pip/pip.log

    Any ideas? I’m running Python 2.7.3 on Ubuntu 12.04 LTS.

  5. Thanks I should have read your blog before I attempted by myself… 🙂

    On my MX running JUNOS 12.3R5.7, I have just:

    set system servies netconf ssh

    And it seems to be working without specify any port number. I have a SRX and an EX somewhere. Will try that out next.

    Thanks again for such a useful blog.

  6. Chris,

    I see some people having problem with pip version 1.5.

    I’m using pip version 1.0 and I have no problem with it.

    reia@ubuntu:~$ pip –version

    pip 1.0 from /usr/lib/python2.7/dist-packages (python 2.7)

    reia@ubuntu:~$

  7. I’m running into an installation problem, specifically, a complaint about xmlstring.h being missing, though I have all the dependencies installed.

    The environment:

    OS: Debian 7.3

    Python: 2.7.3

    pip: 1.1

    git: 1.7.10.4

    apt-get install python-dev libxml2-dev libxslt-dev

    Note, selecting ‘libxslt1-dev’ instead of ‘libxslt-dev’

    libxml2-dev is already the newest version.

    libxslt1-dev is already the newest version.

    python-dev is already the newest version.

    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    ——————————————–

    Things go south when trying to build lxml.etree:

    src/lxml/lxml.etree.c:344:30: fatal error: libxml/xmlstring.h: No such file or directory

    The full output from the git command:

    sudo pip-2.7 install git+https://github.com/Juniper/ncclient.git

    [sudo] password for agallo:

    Sorry, try again.

    [sudo] password for agallo:

    Downloading/unpacking git+https://github.com/Juniper/ncclient.git

    Cloning https://github.com/Juniper/ncclient.git to /tmp/pip-wpll60-build

    Running setup.py egg_info for package from git+https://github.com/Juniper/ncclient.git

    Requirement already satisfied (use –upgrade to upgrade): Paramiko>1.7 in /usr/local/lib/python2.7/dist-packages (from ncclient==0.1a)

    Downloading/unpacking lxml>3.0 (from ncclient==0.1a)

    Running setup.py egg_info for package lxml

    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘bugtrack_url’

    warnings.warn(msg)

    Building lxml version 3.3.0.

    Building without Cython.

    Using build configuration of libxslt 1.0.23

    Building against libxml2/libxslt in the following directory: /usr/local/lib

    Requirement already satisfied (use –upgrade to upgrade): pycrypto>=2.1,!=2.4 in /usr/local/lib/python2.7/dist-packages (from Paramiko>1.7->ncclient==0.1a)

    Requirement already satisfied (use –upgrade to upgrade): ecdsa in /usr/local/lib/python2.7/dist-packages (from Paramiko>1.7->ncclient==0.1a)

    Installing collected packages: lxml

    Running setup.py install for lxml

    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘bugtrack_url’

    warnings.warn(msg)

    Building lxml version 3.3.0.

    Building without Cython.

    Using build configuration of libxslt 1.0.23

    Building against libxml2/libxslt in the following directory: /usr/local/lib

    building ‘lxml.etree’ extension

    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/local/include/libxml2 -I/home/agallo/junosnetconf/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w

    src/lxml/lxml.etree.c:344:30: fatal error: libxml/xmlstring.h: No such file or directory

    compilation terminated.

    error: command ‘gcc’ failed with exit status 1

    Complete output from command /usr/bin/python -c “import setuptools;__file__=’/home/agallo/junosnetconf/build/lxml/setup.py’;exec(compile(open(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))” install –single-version-externally-managed –record /tmp/pip-J30I5A-record/install-record.txt:

    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘bugtrack_url’

    warnings.warn(msg)

    Building lxml version 3.3.0.

    Building without Cython.

    Using build configuration of libxslt 1.0.23

    Building against libxml2/libxslt in the following directory: /usr/local/lib

    running install

    running build

    running build_py

    copying src/lxml/includes/lxml-version.h -> build/lib.linux-i686-2.7/lxml/includes

    running build_ext

    building ‘lxml.etree’ extension

    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/local/include/libxml2 -I/home/agallo/junosnetconf/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w

    src/lxml/lxml.etree.c:344:30: fatal error: libxml/xmlstring.h: No such file or directory

    compilation terminated.

    error: command ‘gcc’ failed with exit status 1

    —————————————-

    Command /usr/bin/python -c “import setuptools;__file__=’/home/agallo/junosnetconf/build/lxml/setup.py’;exec(compile(open(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))” install –single-version-externally-managed –record /tmp/pip-J30I5A-record/install-record.txt failed with error code 1 in /home/agallo/junosnetconf/build/lxml

    Storing complete log in /root/.pip/pip.log

    • Ok, I’m not a Debian guy, but reading through, the obvious question is “So is the file really missing?” This output:

      gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/local/include/libxml2 -I/home/agallo/junosnetconf/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w

      src/lxml/lxml.etree.c:344:30: fatal error: libxml/xmlstring.h: No such file or directory

      If I read that right, it’s going to look for the libxml files within /usr/local/include/, but when I did a quick search of the interwebs I found a file thingy suggesting that Debian may install those files in /usr/include/ instead? I’m totally guessing. Is that something you could check? It may be that a symlink could fix all ills.

      Or maybe somebody with more of a clue than me can pitch in!

      • Thanks for the quick reply. I

        I had initially looked for that file and found nothing, so I

        removed all the libxml and python-dev stuff, reinstalled, found the errant file. You are exactly right, it was in the wrong location.

        Complication and installation are successful.

        Thanks again!

  8. Not sure if anyone else had this caveat, but when I ran the following pip command, it wasn’t recognizing the command…

    sudo pip-2.7 install git+https://github.com/Juniper/ncclient.git

    Just had to remove the “-“, so it runs fine with…

    sudo pip2.7 install git+https://github.com/Juniper/ncclient.git

    This was on ubuntu 12.04.3

  9. Just a quick question:

    We are using IBM server running rhel-5.5-server OS. So will it use the same commands to install python 2.7 and other files or will it differ ?

    And I am trying to understand the program when you say pprint (dev.facts), how it is gonna understand what and all called facts from the device ?

  10. I had a couple of issues. First, the git for ncclient doesn’t exist, so I used this sudo pip2.7 install git+https://github.com/ncclient/ncclient.git

    next, I had issues installing lxml, which was resolved by this

    sudo apt-get install -y libxml2-dev libxslt1-dev zlib1g-dev python3-pip

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.