Juniper/py-junos-eznc: Python library for Junos automation

Juniper/py-junos-eznc: Python library for Junos automation

PyPi Version
Documentation Status
Coverage Status
UnitTest Status

The repo is below energetic growth. Should you take a clone, you’re getting the most recent, and maybe not completely secure code.

Official Documentation with examples, right here

API Documentation hosted by readthedocs

Junos PyEZ wiki web page, right here.

PyEZ logo

Junos PyEZ is a Python library to remotely handle/automate Junos gadgets. The consumer is NOT required: (a) to be a “Software program Programmer™”, (b) have refined data of Junos, or (b) have a fancy understanding of the Junos XML API.

This library was constructed for 2 forms of customers:

For “Non-Programmers” – Python as a Energy Shell

Which means that “non-programmers”, for instance the Community Engineer, can use the native Python shell on their administration server (laptop computer, pill, cellphone, and so on.) as their point-of-control for remotely managing Junos gadgets. The Python shell is an interactive surroundings that gives the mandatory means to carry out widespread automation duties, akin to conditional testing, for-loops, macros, and templates. These constructing blocks are comparable sufficient to different “shell” environments, like Bash, to allow the non-programmer to make use of the Python shell as a power-tool, quite than a programming language. From the Python shell a consumer can handle Junos gadgets utilizing native hash tables, arrays, and so on. quite than device-specific Junos XML or resorting to ‘display screen scraping’ the precise Junos CLI.

For “Programmers” – Open and Extensible

There’s a rising curiosity and must automate the community infrastructure into bigger IT methods. To take action, conventional software program programmers, DevOps, “hackers”, and so on. want an abstraction library of code to additional these actions. Junos PyEZ is designed for extensibility in order that the programmer can rapidly and simply add new widgets to the library in help of their particular undertaking necessities. There isn’t any must “wait on the seller” to offer new performance. Junos PyEZ just isn’t particularly tied to any model of Junos or any Junos product household.

For questions and normal help, please go to our Google Group

You can too submit your question on stackoverflow with pyez tag

For documentation and extra utilization examples, please go to the Junos PyEZ undertaking web page, right here.

Points and bugs might be opened within the repository.

Junos PyEZ is designed to offer the identical capabilities as a consumer would have on the Junos CLI, however in an surroundings constructed for automation duties. These capabilities embody, however aren’t restricted to:

  • Distant connectivity and administration of Junos gadgets by way of NETCONF
  • Present “details” in regards to the gadget akin to software-version, serial-number, and so on.
  • Retrieve “operational” or “run-state” data as Tables/Views
  • Retrieve configuration data as Tables/Views
  • Make configuration adjustments in unstructured and structured methods
  • Present widespread utilities for duties akin to safe copy of recordsdata and software program updates
  • As of launch 2.0.0, Junos PyEZ requires ncclient model 0.5.2 or later.
  • When utilizing the ssh_private_key_file argument of the Gadget constructor on MacOS Mojave and better, be sure that the SSH keys are within the RSA format, and never the newer OPENSSH format.
    • New key: ssh-keygen -p -m PEM -f ~/.ssh/id_rsa
    • Convert an present OPENSSH key: “ssh-keygen -p -m PEM -f ~/.ssh/private_key`
    • Examine if a given secret’s RSA or OPENSSH format: head -n1 ~/.ssh/private_key
      • RSA: -----BEGIN RSA PRIVATE KEY-----


Set up requires Python >=3.5 and related pip device

pip set up junos-eznc

Putting in from Git can be supported (OS will need to have git put in).

To put in the most recent MASTER code
pip set up git+
To put in a selected model, department, tag, and so on.
pip set up git+[email protected]


Interactive Docker Utilization

Transfer to the native listing which accommodates your script(s) and run the container. Operating the container on this method will put you into an interactive Bash session.

docker run -it [ --rm ] [ --name pyez ] -v $PWD:/scripts juniper/pyez

Your native scripts will likely be mounted to /scripts within the container.

Microservice Utilization

This picture may also be used as a Python “executable” with the required Python PyEZ libraries pre-installed. To make use of the picture on this approach, mount the quantity which accommodates the Python script and go the script identify as an argument to docker run. Optionally, you may additionally go in a necessities.txt file to put in extra python packages by way of pip. So as to add OS packages (Alpine Linux), present a file with a listing of packages –one per line– and both reference it as an env var ($APK) or mount it to the container /extras/apk.txt. So as to add extra Python packages (by way of pip), present a necessities.txt file and go it in as an env var ($REQ) or mount it to the container at /extras/necessities.txt.

Utilization: docker run -it [ –rm ] -v some/dir:/scripts juniper/pyez [ ]`


$ docker run -it --rm -v $PWD:/scripts juniper/pyez
{'2RE': False, 'HOME': '/var/residence/lab', 'RE0': {'mastership_state': 'grasp', 'standing': 'OK', 'mannequin': 'RE-SRX210H-POE', 'last_reboot_reason': '0x1:energy cycle/failure', 'up_time': '36 days, 11 hours, 49 minutes, 59 seconds'}, 'RE1': None, 'RE_hw_mi': False, 'current_re': ['master', 'node', 'fwdd', 'member', 'pfem', 'backup', 're0', 'fpc0.pic0'], 'area': None, 'fqdn': 'fw1.localdomain', 'hostname': 'fw1.localdomain', 'hostname_info': {'re0': 'fw1.localdomain'}, 'ifd_style': 'CLASSIC', 'junos_info': {'re0': {'textual content': '12.1X44-D40.2', 'object': junos.version_info(main=(12, 1), kind=X, minor=(44, 'D', 40), construct=2)}}, 'grasp': 'RE0', 'mannequin': 'SRX210H-POE', 'model_info': {'re0': 'SRX210H-POE'}, 'persona': 'SRX_BRANCH', 're_info': {'default': {'0': {'mastership_state': 'grasp', 'standing': 'OK', 'mannequin': 'RE-SRX210H-POE', 'last_reboot_reason': '0x1:energy cycle/failure'}, 'default': {'mastership_state': 'grasp', 'standing': 'OK', 'mannequin': 'RE-SRX210H-POE', 'last_reboot_reason': '0x1:energy cycle/failure'}}}, 're_master': {'default': '0'}, 'serialnumber': 'AE3009AA0101', 'srx_cluster': False, 'srx_cluster_id': None, 'srx_cluster_redundancy_group': None, 'switch_style': 'VLAN', 'vc_capable': False, 'vc_fabric': None, 'vc_master': None, 'vc_mode': None, 'model': '12.1X44-D40.2', 'version_RE0': '12.1X44-D40.2', 'version_RE1': None, 'version_info': junos.version_info(main=(12, 1), kind=X, minor=(44, 'D', 40), construct=2), 'digital': False}

See for some instance utilization.


Upgrading has the identical necessities as set up and has the identical format with the addition of -UPGRADE

pip set up -U junos-eznc


The next is a fast “good day, world” instance to make sure that the software program was put in appropriately. This code will merely hook up with a tool and show the identified details of the gadget, like serial-number, mannequin, and so on.

from pprint import pprint
from jnpr.junos import Gadget

with Gadget(host='my_host_or_ipaddr', consumer='jeremy', password='jeremy123' ) as dev:
    pprint( dev.details )

Instance output for an SRX-210 gadget:

>>> pprint(dev.details)
{'2RE': False,
 'RE0': {'last_reboot_reason': '0x20:power-button smooth energy off',
         'mannequin': 'RE-SRX210H',
         'standing': 'OK',
         'up_time': '10 minutes, Three seconds'},
 'area': ''         
 'fqdn': '',
 'hostname': 'srx210',
 'ifd_style': 'CLASSIC',
 'mannequin': 'SRX210H',
 'persona': 'SRX_BRANCH',
 'serialnumber': 'AD2909AA0096',
 'switch_style': 'VLAN',
 'model': '12.1X44-D10.4',
 'version_info': junos.versino_info(main=(12, 1), kind=X, minor=(44, 'D', 10), construct=4)}

Apache 2.0

Juniper Networks is actively contributing to and sustaining this repo. Please contact [email protected] for any queries.


Nitin Kumar, Stacy Smith, Stephen Steiner

  • v2.4.1: Nitin Kumar
  • v2.4.0: Nitin Kumar
  • v2.3.0: Nitin Kumar, Raja Shekar Mekala, Dinesh Babu, Chris Jenn, Shigechika
  • v2.2.1: Nitin Kumar, Raja Shekar Mekala, Dinesh Babu, Marcel Wiget, John Tishey, Alex Carp, Cory Councilman
  • v2.2.0: Nitin Kumar, Raja Shekar Mekala, Marek, Marcel Wiget
  • v2.1.9: Dinesh Babu, Nitin Kumar, Jacob Neil Taylor, Raja Shekar Mekala
  • v2.1.8: Dinesh Babu, Stephen Steiner
  • v2.1.7: Stacy Smith
  • v2.0.0: Ganesh Nalawade, Jainpriyal

Former Contributors:

Jeremy Schulman, Rick Sherman, Edward Arcuri

Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *