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 connect to devices running Junos OS using a serial console connection, telnet, or a NETCONF session over SSH. 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 through a console server that is directly connected to the device.

Junos PyEZ enables you to perform operational tasks on devices running Junos OS. Using Junos PyEZ, you can 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, create a rescue configuration, roll back a configuration, and upload 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 provides Tables and Views to enable you to both configure devices running Junos OS and extract specific operational information or configuration data from the devices. Tables and Views are defined using simple YAML files that contain key:value pair mappings, so no complex coding is required to use them. Using Tables and Views, you can 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.

Junos PyEZ Resources

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

Table 1: Junos PyEZ Resources

Resource

Description

URL

API Reference

Detailed documentation for the Junos PyEZ modules.

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

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/en_US/release-independent/junos-pyez/information-products/pathway-pages/index.html

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

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

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. Starting in Junos OS Release 16.1, Junos OS automation scripts can be written in Python on certain supported devices that include the Python extensions package in the software image, and the Python automation scripts can leverage features in Junos PyEZ Release 1.3.1 and earlier releases to execute RPCs and perform operational and configuration tasks on devices running Junos OS. Starting in Junos OS Release 17.4, Python automation scripts can leverage features in Junos PyEZ Release 2.1.4 and earlier releases.

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