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.
Pre-Requisites
# 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.
source: http://movingpackets.net/2013/12/02/installing-junos-ez-library-easy-sdn-part-1/