Automation
Automation

Scripting How-To: Install the Junos PyEZ library

by Cordelia on ‎04-12-2014 08:02 PM - edited on ‎08-23-2017 12:25 PM by Administrator Administrator (22,278 Views)

Install the PyEZ Library

 

Junos PyEZ has been built and tested with Python 2.6 and 2.7.

 

NOTE: Earlier versions of Python are known not to work. Additionally, no testing has been performed with Python 3.3 at this time.

 

System Requirements

 

Some of the project dependencies require OS system libraries. The ncclient package specifically requires libxml2 and libxslt installed on the system.
 
IMPORTANT: Before you begin installing Junos PyEZ, make sure that you have these libraries installed.

 

Ubuntu/Debian

  • python-pip
  • python-dev
  • libxml2-dev
  • libxslt-dev
  • libssl-dev
  • libffi-dev

Fedora

  • python-pip
  • python-devel
  • libxml2-devel
  • libxslt-devel
  • libffi-devel
  • gcc
  • openssl

FreeBSD

  • py27-pip
  • libxml2
  • libxslt

 

PyPI

 

Versions of Junos PyEZ are uploaded to PyPI for ease of installation.

 

NOTE: This process assumes "pip" is for Python 2.7.

 

1 # Install the Junos "EZ" library:
2 pip install junos-eznc

 

Github

 

To get the "latest and greatest" code, you can obtain it directly from github.

 

NOTE: This process assumes "python" is version 2.7 and the git system package has been installed.

 
2  
3 or
4  

 

 

'
Comments
Nov 19, 2014
Cordelia
 
@sdwang, you are right

I checked with another M10 device (with latest build) it has got serial number and hence same code is working for me, older version seems to have missing serial number and leading to exception in PyEZ code. You can raise a request on github, We will try to fix the same.
Item Version Part number Serial number Description
Chassis K1XXX M10I
Midplane REV 09 710-00YYYY AADBYYYY M10i Midplane
Posted 09:38, 19 Nov 2014
Sep 8, 2015
raghavbhargava121

Hey everyone,

 

I am a newbie in automation . I was trying to create a virtual environment on one of our linux boxes and then install jnpr-eznc there. While doing the same i am getting the following error messages and would appreciate if someone can help.

 

Error message:

 

(my_project)raghav@sjd-ra1-8b:~/my_project$ pip install junos-eznc
Collecting junos-eznc
Exception:
Traceback (most recent call last):
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/commands/install.py", line 294, in run
    requirement_set.prepare_files(finder)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/req/req_set.py", line 334, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/req/req_set.py", line 321, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/req/req_set.py", line 461, in _prepare_file
    req_to_install.populate_link(finder, self.upgrade)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/req/req_install.py", line 250, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/index.py", line 486, in find_requirement
    all_versions = self._find_all_versions(req.name)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/index.py", line 404, in _find_all_versions
    index_locations = self._get_index_urls_locations(project_name)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/index.py", line 378, in _get_index_urls_locations
    page = self._get_page(main_index_url)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/index.py", line 818, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/index.py", line 928, in get_page
    "Cache-Control": "max-age=600",
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 477, in get
    return self.request('GET', url, **kwargs)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/download.py", line 373, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 465, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 573, in send
    r = adapter.send(request, **kwargs)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 761, in _validate_conn
    conn.connect()
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/home/raghav/my_project/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/contrib/pyopenssl.py", line 279, in ssl_wrap_socket
    cnx.set_tlsext_host_name(server_hostname)
AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

 

 

Nov 25, 2015
Juniper Employee

@raghavbhargava121

Sorry, didn't realize this was out here.  You probably have this fixed but here is an answer for anyone that sees this error:

AttributeError: '_socketobject' object has no attribute 'set_tlsext_host_name'

 

It is most likely (not always) a case of using python-openssl and it doesn't have a parameter for set_tlsext_host_name

 

Easiest way to fix it is this:

 

apt-get purge python-openssl
apt-get install libffi-dev python-pip
pip2.7 install -U pyopenssl==0.13.1

Assuming you are using Ubuntu.  Use yum/dnf for Fedora/CentOS or whatever package manger you have for your distribution.