Understanding Junos PyEZ

 

Junos PyEZ Overview

Junos PyEZ is a microframework for Python that enables you to manage and automate devices running the Junos operating system (Junos OS). Junos PyEZ is designed to provide the capabilities that a user would have on the Junos OS command-line interface (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 devices running Junos OS 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 enables you to perform operational tasks on devices running Junos OS. You can use Junos PyEZ to easily retrieve facts and operational information from a device and execute any remote procedure call (RPC) available through the Junos XML API. Junos PyEZ provides software utilities for installing the Junos OS software and rebooting or shutting down managed devices. Junos PyEZ also provides file system utilities to perform common administrative tasks such as copying files and calculating checksums.

Junos PyEZ also enables you to manage the configurations of devices running Junos OS. Junos PyEZ configuration management utilities enable you to retrieve and compare configurations, manage the rescue configuration, roll back a configuration, and upload and commit configuration changes. Junos PyEZ supports standard formats for configuration data including ASCII text, Junos XML elements, Junos OS set commands, and JavaScript Object Notation (JSON), and also supports using 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 devices running Junos OS 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 OS command that has an RPC equivalent 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, starting in Junos PyEZ Release 2.0, 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 devices running Junos OS

  • 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

The Junos OS automation suite of tools includes commit scripts, operation (op) scripts, SNMP scripts, and event policies and event scripts. Certain devices running Junos OS include the Python extensions package and the Junos PyEZ library in the software image. These extensions enable you to write automation scripts in Python and use Junos PyEZ in the scripts to execute RPCs and perform operational and configuration tasks on devices running Junos OS. 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 automation script can leverage features in Junos PyEZ Release 2.1.4 and earlier releases.

Table 1: Junos PyEZ Version on Supported Devices Running Junos OS

Junos OS Release

Junos PyEZ Version

16.1R3 through 17.3

1.3.1

17.4R1 and later

2.1.4

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 Feature 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.

http://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/us/en/training/jnbooks/day-one/automation-series/junos-pyez-cookbook

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 devices running Junos OS.

https://www.juniper.net/documentation/product/en_US/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.

http://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

Techwiki page

Juniper Networks J-Net community forum containing additional how-to articles and usage examples.

https://forums.juniper.net/t5/Automation-Scripting/Junos-PyEZ/ta-p/280496