Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Understanding Junos PyEZ

SUMMARY Use the Junos PyEZ Python library to develop Python scripts that remotely manage Junos devices.

Junos PyEZ Overview

Junos PyEZ is a microframework for Python that enables you to manage and automate Junos devices. Junos PyEZ is designed to provide the capabilities that a user would have on the Junos OS CLI in an environment built for automation tasks. Junos PyEZ does not require extensive knowledge of Junos OS or the Junos XML APIs.

Junos PyEZ enables you to manage Junos devices using the familiarity of Python. However, you do not have to be an experienced programmer to use Junos PyEZ. Non-programmers can quickly execute simple commands in Python interactive mode, and more experienced programmers can opt to create more complex, robust, and reusable programs to perform tasks.

Junos PyEZ enables you to directly connect to a device using a serial console connection, telnet, or a NETCONF session over SSH. In addition, Junos PyEZ also supports connecting to the device through a telnet or SSH connection to a console server that is connected to the device’s CONSOLE port. You can use Junos PyEZ to initially configure a new or zeroized device that is not yet configured for remote access by using either a serial console connection when you are directly connected to the device or by using telnet or SSH through a console server that is directly connected to the device.

Junos PyEZ provides device, software, and file system utilities that enable you to perform common operational tasks on Junos devices. You can use Junos PyEZ to:

  • Retrieve facts or operational information from a device

  • Execute remote procedure calls (RPC) available through the Junos XML API

  • Install or upgrade the Junos OS software

  • Reboot or shut down the device

  • Perform common administrative tasks such as copying files and calculating checksums

Junos PyEZ also enables you to manage Junos device configurations. Junos PyEZ configuration management utilities enable you to:

  • Retrieve configuration data

  • Compare configurations

  • Upload and commit configuration changes

  • Roll back the configuration

  • Manage the rescue configuration

Junos PyEZ supports standard formats for configuration data including ASCII text, Junos XML elements, Junos OS set commands, and JavaScript Object Notation (JSON). You can also use Jinja2 templates and template files for added flexibility and customization. In addition, you can use Tables and Views to define structured resources that you can use to programmatically configure a device.

Junos PyEZ Tables and Views enable you to both configure Junos devices and extract specific operational information or configuration data from the devices. You define Tables and Views using simple YAML files that contain key-value pair mappings, so no complex coding is required to use them. You can use Tables and Views to retrieve the device configuration or the output for any Junos command or RPC and then extract a customized subset of information. This is useful when you need to retrieve information from a few specific fields that are embedded in extensive command output such as for the show route or show interfaces command. In addition, you can use Tables and Views to define structured configuration resources. Junos PyEZ dynamically creates a configuration class for the resource, which enables you to programmatically configure the resource on a device.

Benefits of Junos PyEZ

  • Provides an abstraction layer that enables Python programmers as well as non-programmers to easily manage and automate Junos devices.

  • Increases operational efficiency by enabling operators to automate common tasks thereby reducing the manual configuration and management of devices.

  • Minimizes errors and risks by enabling structured configuration changes of targeted resources.

Using Junos PyEZ in Automation Scripts

Junos OS and Junos OS Evolved include the Python extensions package and the Junos PyEZ library in the software image on supported devices. These extensions enable you to create on-box Python scripts that use Junos PyEZ to execute RPCs and perform operational and configuration tasks on the device. Junos PyEZ is supported in commit, event, op, and SNMP scripts; Juniper Extension Toolkit (JET) scripts; and YANG action and translation scripts.

Table 1 summarizes the Junos PyEZ version that is available on supported devices running the given Junos OS release. For example, starting in Junos OS Release 17.4R1, an on-box Python script can leverage features in Junos PyEZ Release 2.1.4 and earlier releases.

Table 1: Junos PyEZ Version on Supported Junos Devices

Junos OS Release

Junos PyEZ Version

16.1R3 through 17.3

1.3.1

17.4R1 through 19.3

2.1.4

19.4R1 and later

2.2.0

For more information about creating onbox Python automation scripts, see Understanding Python Automation Scripts for Devices Running Junos OS in the Junos OS Automation Scripting User Guide.

Junos PyEZ Resources

Juniper Networks provides a number of Junos PyEZ resources, which are described in Table 2.

Table 2: Junos PyEZ Resources

Resource

Description

URL

API Reference

Detailed documentation for the Junos PyEZ modules.

https://junos-pyez.readthedocs.org/

Day One: Junos PyEZ Cookbook and script repository

Junos PyEZ network automation cookbook with a setup guide, a start-up sandbox, and a complete showcase of automation scripts that are available on GitHub.

https://www.juniper.net/documentation/en_US/day-one-books/DO_PyEZ_Cookbook.pdf

https://github.com/Juniper/junosautomation/tree/master/pyez/PyEZ_Cookbook_2017

Documentation

Junos PyEZ documentation containing detailed information about installing Junos PyEZ and using Junos PyEZ to perform operational and configuration tasks on Junos devices.

https://www.juniper.net/documentation/product/us/en/junos-pyez

GitHub repository

Public repository for the Junos PyEZ project. This repository includes the most current source code, installation instructions, and release note summaries for all releases.

https://github.com/Juniper/py-junos-eznc/

Google Groups forum

Forum that addresses questions and provides general support for Junos PyEZ.

https://groups.google.com/group/junos-python-ez

Sample scripts

Junos PyEZ sample scripts to get you started.

https://github.com/Juniper/junosautomation/tree/master/pyez

Stack Overflow forum

Forum that addresses questions and provides general support for Junos PyEZ.

https://stackoverflow.com/questions/tagged/pyez