Juniper Networks, Inc.
1133 Innovation Way
Sunnyvale, California 94089
USA
408-745-2000
www.juniper.net
Juniper Networks, the Juniper Networks logo, Juniper, and Junos are registered trademarks of Juniper Networks, Inc. in
the United States and other countries. All other trademarks, service marks, registered marks, or registered service marks
are the property of their respective owners.
Juniper Networks assumes no responsibility for any inaccuracies in this document. Juniper Networks reserves the right
to change, modify, transfer, or otherwise revise this publication without notice.
The information in this document is current as of the date on the title page.
ii
YEAR 2000 NOTICE
Juniper Networks hardware and software products are Year 2000 compliant. Junos OS has no known time-related
limitations through the year 2038. However, the NTP application is known to have some difficulty in the year 2036.
END USER LICENSE AGREEMENT
The Juniper Networks product that is the subject of this technical documentation consists of (or is intended for use with)
Juniper Networks software. Use of such software is subject to the terms and conditions of the End User License Agreement
(“EULA”) posted at https://support.juniper.net/support/eula/. By downloading, installing or using such software, you
agree to the terms and conditions of that EULA.
Table of Contents
1
2
3
About the Documentation | x
Documentation and Release Notes | x
Documentation Conventions | x
Documentation Feedback | xiii
Requesting Technical Support | xiii
Self-Help Online Tools and Resources | xiv
Creating a Service Request with JTAC | xiv
Disclaimer
Junos PyEZ Disclaimer | 16
iii
Junos PyEZ Overview
Understanding Junos PyEZ | 18
Junos PyEZ Overview | 18
Benefits of Junos PyEZ | 19
Using Junos PyEZ in Automation Scripts | 19
Junos PyEZ Resources | 20
Junos PyEZ Modules Overview | 21
Installing Junos PyEZ
Installing Junos PyEZ | 25
Installing Prerequisite Software | 25
Installing Junos PyEZ on the Configuration Management Server | 27
Installing Junos PyEZ in a Python Virtual Environment | 28
Using the Junos PyEZ Docker Image | 29
Setting Up Junos PyEZ Managed Nodes | 31
Enabling NETCONF over SSH on Devices Running Junos OS | 32
Satisfying Requirements for SSHv2 Connections | 32
Configuring Telnet Service on Devices Running Junos OS | 33
Connecting to and Retrieving Facts From a Device Using Junos PyEZ
4
5
Connecting to Devices Running Junos OS Using Junos PyEZ | 36
Troubleshooting Junos PyEZ Authentication Errors When Managing Devices Running
Junos OS | 305
Troubleshooting Junos PyEZ Errors When Configuring Devices Running Junos OS | 306
Troubleshooting Timeout Errors | 306
Troubleshooting Configuration Lock Errors | 307
Troubleshooting Configuration Change Errors | 308
About the Documentation
IN THIS SECTION
Documentation and Release Notes | x
Documentation Conventions | x
Documentation Feedback | xiii
Requesting Technical Support | xiii
Use this guide to develop Python scripts that remotely automate and manage devices running Junos OS
using the Juniper Networks Junos PyEZ Python library.
x
Documentation and Release Notes
To obtain the most current version of all Juniper Networks®technical documentation, see the product
documentation page on the Juniper Networks website at https://www.juniper.net/documentation/.
If the information in the latest release notes differs from the information in the documentation, follow the
product Release Notes.
Juniper Networks Books publishes books by Juniper Networks engineers and subject matter experts.
These books go beyond the technical documentation to explore the nuances of network architecture,
deployment, and administration. The current list can be viewed at https://www.juniper.net/books.
Documentation Conventions
Table 1 on page xi defines notice icons used in this guide.
Table 1: Notice Icons
xi
DescriptionMeaningIcon
Indicates important features or instructions.Informational note
Caution
Indicates a situation that might result in loss of data or hardware
damage.
Alerts you to the risk of personal injury or death.Warning
Alerts you to the risk of personal injury from a laser.Laser warning
Indicates helpful information.Tip
Alerts you to a recommended use or implementation.Best practice
Table 2 on page xi defines the text and syntax conventions used in this guide.
Table 2: Text and Syntax Conventions
ExamplesDescriptionConvention
Fixed-width text like this
Italic text like this
Represents text that you type.Bold text like this
Represents output that appears on
the terminal screen.
Introduces or emphasizes important
•
new terms.
Identifies guide names.
•
Identifies RFC and Internet draft
•
titles.
To enter configuration mode, type
the configure command:
user@host> configure
user@host> show chassis alarms
No alarms currently active
A policy term is a named structure
•
that defines match conditions and
actions.
Junos OS CLI User Guide
•
RFC 1997, BGP Communities
•
Attribute
Table 2: Text and Syntax Conventions (continued)
xii
ExamplesDescriptionConvention
Italic text like this
Text like this
< > (angle brackets)
| (pipe symbol)
Represents variables (options for
which you substitute a value) in
commands or configuration
statements.
Represents names of configuration
statements, commands, files, and
directories; configuration hierarchy
levels; or labels on routing platform
components.
variables.
Indicates a choice between the
mutually exclusive keywords or
variables on either side of the symbol.
The set of choices is often enclosed
in parentheses for clarity.
Configure the machine’s domain
name:
[edit]
root@# set system domain-name
domain-name
To configure a stub area, include
•
the stub statement at the [edit
protocols ospf area area-id]
hierarchy level.
The console port is labeled
•
CONSOLE.
stub <default-metric metric>;Encloses optional keywords or
broadcast | multicast
(string1 | string2 | string3)
# (pound sign)
[ ] (square brackets)
Indention and braces ( { } )
; (semicolon)
GUI Conventions
Indicates a comment specified on the
same line as the configuration
statement to which it applies.
Encloses a variable for which you can
substitute one or more values.
Identifies a level in the configuration
hierarchy.
Identifies a leaf statement at a
configuration hierarchy level.
rsvp { # Required for dynamic MPLS
only
community name members [
community-ids ]
[edit]
routing-options {
static {
route default {
nexthop address;
retain;
}
}
}
Table 2: Text and Syntax Conventions (continued)
xiii
ExamplesDescriptionConvention
Bold text like this
> (bold right angle bracket)
Represents graphical user interface
(GUI) items you click or select.
Separates levels in a hierarchy of
menu selections.
In the Logical Interfaces box, select
•
All Interfaces.
To cancel the configuration, click
•
Cancel.
In the configuration editor hierarchy,
select Protocols>Ospf.
Documentation Feedback
We encourage you to provide feedback so that we can improve our documentation. You can use either
of the following methods:
Online feedback system—Click TechLibrary Feedback, on the lower right of any page on the Juniper
•
Networks TechLibrary site, and do one of the following:
Click the thumbs-up icon if the information on the page was helpful to you.
•
Click the thumbs-down icon if the information on the page was not helpful to you or if you have
•
suggestions for improvement, and use the pop-up form to provide feedback.
E-mail—Send your comments to techpubs-comments@juniper.net. Include the document or topic name,
•
URL or page number, and software version (if applicable).
Requesting Technical Support
Technical product support is available through the Juniper Networks Technical Assistance Center (JTAC).
If you are a customer with an active Juniper Care or Partner Support Services support contract, or are
covered under warranty, and need post-sales technical support, you can access our tools and resources
online or open a case with JTAC.
JTAC policies—For a complete understanding of our JTAC procedures and policies, review the JTAC User
•
Guide located at https://www.juniper.net/us/en/local/pdf/resource-guides/7100059-en.pdf.
JTAC hours of operation—The JTAC centers have resources available 24 hours a day, 7 days a week,
•
365 days a year.
Self-Help Online Tools and Resources
For quick and easy problem resolution, Juniper Networks has designed an online self-service portal called
the Customer Support Center (CSC) that provides you with the following features:
Use of the Junos PyEZ software implies acceptance of the terms of this disclaimer, in addition to any other
licenses and terms required by Juniper Networks.
Juniper Networks is willing to make the Junos PyEZ software available to you only on the condition that
you accept all of the terms contained in this disclaimer. Please read the terms and conditions of this
disclaimer carefully.
The Junos PyEZ software is provided as is. Juniper Networks makes no warranties of any kind whatsoever
with respect to this software. All express or implied conditions, representations and warranties, including
any warranty of non-infringement or warranty of merchantability or fitness for a particular purpose, are
hereby disclaimed and excluded to the extent allowed by applicable law.
In no event will Juniper Networks be liable for any direct or indirect damages, including but not limited to
lost revenue, profit or data, or for direct, special, indirect, consequential, incidental or punitive damages
however caused and regardless of the theory of liability arising out of the use of or inability to use the
software, even if Juniper Networks has been advised of the possibility of such damages.
16
2
CHAPTER
Junos PyEZ Overview
Understanding Junos PyEZ | 18
Junos PyEZ Modules Overview | 21
Understanding Junos PyEZ
IN THIS SECTION
Junos PyEZ Overview | 18
Benefits of Junos PyEZ | 19
Using Junos PyEZ in Automation Scripts | 19
Junos PyEZ Resources | 20
Junos PyEZ Overview
18
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 provides device, software, and file system utilities that enable you to perform common
operational tasks on devices running Junos OS. 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 the configurations of devices running Junos OS. 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), 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 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, 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.
19
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
Junos OS includes the Python extensions package and the Junos PyEZ library in the software image for
certain 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 devices running Junos OS.
Junos PyEZ is supported in commit, event, op, and SNMP scripts; Juniper Extension Toolkit (JET) scripts;
and YANG action and translation scripts.
Table 3 on page 20 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 3: Junos PyEZ Version on Supported Devices Running Junos OS
Junos PyEZ VersionJunos OS Release
1.3.116.1R3 through 17.3
2.1.417.4R1 through 19.3
2.2.019.4R1 and later
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.
20
Junos PyEZ Resources
Juniper Networks provides a number of Junos PyEZ resources, which are described in Table 4 on page 20.
Table 4: Junos PyEZ Resources
URLDescriptionResource
API Reference
Day One: Junos PyEZ
Cookbook and script
repository
Documentation
modules.
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.
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.
http://junos-pyez.readthedocs.org/Detailed documentation for the Junos PyEZ
Public repository for the Junos PyEZ project. This
repository includes the most current source code,
installation instructions, and release note
summaries for all releases.
Forum that addresses questions and provides
general support for Junos PyEZ.
Junos PyEZ sample scripts to get you started.Sample scripts
Forum that addresses questions and provides
general support for Junos PyEZ.
Juniper Networks J-Net community forum
containing additional how-to articles and usage
examples.
Connecting to Devices Running Junos OS Using Junos PyEZ | 36
Using Junos PyEZ to Configure Devices Running Junos OS | 126
Junos PyEZ Modules Overview
Junos PyEZ is a microframework for Python that enables you to manage and automate devices running
Junos OS. Junos PyEZ consists of the jnpr.junos package, which contains modules that handle device
connectivity and provide operational and configuration utilities.
Table 5 on page 22 outlines the primary Junos PyEZ modules that are used to manage devices running
Junos OS. For detailed information about each module, see the Junos PyEZ API Reference at
http://junos-pyez.readthedocs.org/.
Table 5: Junos PyEZ Modules
Descriptionjnpr.junos Modules
22
device
command
exception
factory
facts
op
resources
Defines the Device class, which represents the device running Junos OS and enables you
to connect to and retrieve facts from the device.
Includes predefined operational Tables and Views that can be used to filter unstructured
output returned from CLI and vty commands and convert it to JSON.
Defines exceptions encountered when accessing, configuring, and managing devices
running Junos OS.
Contains code pertaining to Tables and Views, including the loadyaml() function, which is
used to load custom Tables and Views.
A dictionary-like object of read-only facts about the device. These facts are accessed using
the facts attribute of a Device object instance.
Includes predefined operational Tables and Views that can be used to filter structured
output returned from RPCs.
Includes predefined configuration Tables and Views representing specific configuration
resources, which can be used to programmatically configure devices running Junos OS.
Contains code used by the Device class to support the different connection types.transport
utils
Includes configuration utilities, file system utilities, shell utilities, software installation
utilities, and secure copy utilities.
In Junos PyEZ, each device is modeled as an instance of the jnpr.junos.device.Device class. The device
module provides access to devices running Junos OS through a serial console connection, telnet, or SSH
and 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. All connection methods support retrieving device facts,
performing operations, and executing RPCs on demand. Support for serial console connections and for
telnet and SSH connections through a console server enables you to connect to and initially configure
new or zeroized devices that are not yet configured for remote access. Facts about the device are accessed
using the facts attribute of the Device object instance.
The utils module defines submodules and classes that handle software installation, file system and copy
operations, and configuration management. The exception module defines exceptions encountered when
managing devices running Junos OS.
The command, op, resources, and factory modules pertain to Tables and Views. The command and op
modules contain predefined operational Tables and Views that can be used to extract specific information
from the output of common operational commands and RPCs on devices running Junos OS. The resources
module contains predefined configuration Tables and Views that can be used to configure specific resources
on devices running Junos OS. The factory module contains methods that enable you to load your own
custom Tables and Views in Junos PyEZ applications.
RELATED DOCUMENTATION
Understanding Junos PyEZ | 18
Understanding Junos PyEZ Tables and Views | 185
Using Junos PyEZ to Retrieve Facts from Devices Running Junos OS | 60
23
3
CHAPTER
Installing Junos PyEZ
Installing Junos PyEZ | 25
Setting Up Junos PyEZ Managed Nodes | 31
Installing Junos PyEZ
Junos PyEZ is a Python library that enables you to manage and automate devices running Junos OS. You
can install Junos PyEZ on a UNIX-like operating system or on Windows. You have the option to install and
run Junos PyEZ directly on the configuration management server, within a Python virtual environment, or
as a Docker container.
As an alternative to installing Junos PyEZ directly on the server, you can install it in a virtual environment.
A Python virtual environment isolates a project’s Python installation and packages from those installed on
the system or in other virtual environments, which prevents breaking the dependencies of other projects.
You can create virtual environments when you have projects that require different versions of Python or
Python packages or as an alternative to installing packages globally on the system.
Juniper Networks also provides a Junos PyEZ Docker image that enables you to run Junos PyEZ as a
Docker container. The Docker container is a lightweight, self-contained system that bundles Junos PyEZ,
its dependencies, and Python into a single portable container. The Docker image enables you to quickly
run Junos PyEZ in interactive mode, as an executable package, or as a terminal on any platform that
supports Docker.
25
To install Junos PyEZ on the configuration management server, see the following sections:
Installing Prerequisite Software on page 25
•
Installing Junos PyEZ on the Configuration Management Server on page 27
•
To install Junos PyEZ in a Python virtual environment, see the following sections:
Installing Prerequisite Software on page 25
•
Installing Junos PyEZ in a Python Virtual Environment on page 28
•
To use the Junos PyEZ Docker image, see the following section:
Using the Junos PyEZ Docker Image on page 29
•
Installing Prerequisite Software
Before you install the Junos PyEZ library on the configuration management server or in a virtual
environment, ensure that the configuration management server has the following software installed:
Python 2.7, or Python 3.5 or later
•
All prerequisite software for the given operating system, which is outlined in Table 6 on page 26
•
NOTE: Python 3.x is only supported in Junos PyEZ Release 2.0 and later releases.
successfully install using pip, try using
easy_install to install the lxml library and
then Junos PyEZ.
Ubuntu
Windows
pip
•
xcode
•
libffi-dev
•
libssl-dev
•
libxml2-dev
•
libxslt1-dev
•
python-dev (required for Python 2)
•
python3-dev (required for Python 3)
•
pip
•
ecdsa
•
pip
•
pycrypto
•
Installing Junos PyEZ on the Configuration Management Server
After you install the prerequisite software on the configuration management server, you can install the
latest release of Junos PyEZ from the Python Package Index (PyPI). You can also download the latest
version of the code from the Junos PyEZ GitHub repository. To install Junos PyEZ from GitHub, you must
have Git installed on the configuration management server.
To install the current release of Junos PyEZ from PyPI, execute the following command (use sudo pip
•
where appropriate):
user@server:~$ sudo pip install junos-eznc
NOTE: To upgrade an existing version of Junos PyEZ, include the -U or --upgrade option when
executing the pip install command.
To install Junos PyEZ from the GitHub project master branch, execute the following command (use sudo
NOTE: The latest code in the GitHub source repository is under active development and might
not be stable.
NOTE: The pip command name might vary depending on your operating system and version of
Python. Before installing Junos PyEZ using pip, use the pip -V command to display the version,
and verify that the pip command corresponds to the version of Python that you are using for
Junos PyEZ on your system. If the version is not the same as the Python version used for Junos
PyEZ, then try using the pip2 or pip3 commands instead of pip.
For additional information about installing Junos PyEZ, including additional installation options, see the
INSTALL file for your specific operating system in the Junos PyEZ GitHub repository at
https://github.com/Juniper/py-junos-eznc.
28
Installing Junos PyEZ in a Python Virtual Environment
As an alternative to installing Python packages globally on a system, you can install the required packages
and dependencies for a specific project in an isolated Python virtual environment. After you install the
prerequisite software on the configuration management server, you can create a Python virtual environment
for your Junos PyEZ project.
For example, to create a virtual Python 3 installation with Junos PyEZ on a Linux or macOS server:
1. Move into your existing project directory or create a new one, if none exists.
user@host:~$ mkdir junos-pyez
user@host:~$ cd junos-pyez
2. Create a virtual Python installation and specify its name, which in this case is venv.
user@host:~/junos-pyez$ python3 -m venv venv
NOTE: Ubuntu and Debian systems might require you to install the python3-venv package
before you can create the virtual environment.
3. Activate the virtual environment by executing the script in the virtual environment’s bin directory that
is appropriate for your platform and shell.
user@host:~/junos-pyez$ source venv/bin/activate
(venv) user@host:~/junos-pyez$
4. Install Junos PyEZ.
To install the current release of Junos PyEZ from PyPI, execute the following command:
NOTE: For Python 2 virtual environments, use the virtualenv tool.
Using the Junos PyEZ Docker Image
Docker is a software container platform that is used to package and run an application and its dependencies
in an isolated container. Juniper Networks provides a Junos PyEZ Dockerfile as well as Junos PyEZ Docker
images, which are automatically built for every Junos PyEZ release. Starting in Junos PyEZ Release 2.1.8,
the Docker images include Python 3.6. In earlier release, the images include Python 2.7.x.
You can customize and use the Dockerfile to build your own Junos PyEZ Docker image, or you can use
one of the prebuilt Docker images, which are stored on Docker Hub, to run Junos PyEZ as a Docker
container. You can run the container in interactive mode, as an executable package, or as a terminal.
To use a prebuilt Junos PyEZ Docker image on your configuration management server:
1. Install Docker.
See the Docker website at https://www.docker.com for instructions on installing and configuring
Docker on your specific operating system.
2. Download the juniper/pyez Docker image from Docker Hub.
To download the latest image, issue the following command:
•
user@server:~$ docker pull juniper/pyez
NOTE: The latest Junos PyEZ Docker image is built using the most recently committed
code in the Junos PyEZ source repository, which is under active development and might
not be stable.
30
To download a specific image, append the appropriate release tag to the image name, for example,
•
2.1.2.
user@server:~$ docker pull juniper/pyez:tag
3. Move to the local directory that contains your scripts.
When you run the Docker container, the local scripts are mounted to /scripts in the container.
4. Run the container.
For instructions on running the container, see the official usage examples at DOCKER-EXAMPLES.md.
RELATED DOCUMENTATION
Setting Up Junos PyEZ Managed Nodes | 31
Understanding Junos PyEZ | 18
Junos PyEZ Modules Overview | 21
Authenticating Junos PyEZ Users | 52
Loading...
+ 278 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.