JUNOS PyEz is easy as pie...
Ok, may be not that easy. But it is doable.
I was randomly browsing the net while waiting to upgrade my MX480 to the latest and greatest JUNOS 12.3R5.whatever.... I remember that I still try to learn my rope around Python and one thing leads to another...
"PyEZ" on Juniper's techwiki...
I was hoping to just download the module and run off from techwiki, but unfortunately, I need to go to git to get it. Fortunately, the instruction is easy enough to do. Only two commands to install the required modules on my Ubuntu system:
sudo pip install git+https://github.com/Juniper/ncclient.git
sudo pip install junos-eznc
My first try was unsuccessful and I got the following messages:
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.
ERROR: /bin/sh: 1: xslt-config: not found
** make sure the development packages of libxml2 and libxslt are installed **
Not included in the instruction is that I also need to install two additional packages:
Which on my Ubuntu system, it is easy enough to do:
% sudo apt-get install python-dev
% sudo apt-get install libxslt1-dev
After I install the two packages, the installation of the
pyez was very smooth.
Jeremy's example in the installation page was pretty easy enough for testing. I highly recommend you to just try it in interactive mode like I did...
reia@ubuntu:~$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pprint import pprint
>>> from jnpr.junos import Device
>>> dev = Device(host='mysun.example.net', user='me', password='more0fme')
>>> dev.open()
Device(mysun.example.net)
>>> pprint( dev.facts )
{'2RE': True,
'HOME': '/var/home/lab',
'RE0': {'last_reboot_reason': 'Router rebooted after a normal shutdown.',
'mastership_state': 'master',
'model': 'RE-S-1800x4',
'status': 'OK',
'up_time': '17 hours, 51 minutes, 36 seconds'},
'RE1': {'last_reboot_reason': 'Router rebooted after a normal shutdown.',
'mastership_state': 'backup',
'model': 'RE-S-1800x4',
'status': 'OK',
'up_time': '16 hours, 22 minutes, 55 seconds'},
'domain': None,
'fqdn': 'Sun-re0',
'hostname': 'Sun-re0',
'ifd_style': 'CLASSIC',
'master': 'RE0',
'model': 'MX480',
'personality': 'MX',
'serialnumber': 'JN1XXXXXXXXXX',
'switch_style': 'BRIDGE_DOMAIN',
'version': '12.3R5.7',
'version_RE0': '12.3R5.7',
'version_RE1': '12.3R5.7',
'version_info': junos.version_info(major=(12, 3), type=R, minor=5, build=7)}
>>>
And I notice that my router has been upgraded. That's it for now.
Tata my friend.