Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Install Junos PyEZ

Junos PyEZ is a Python library that enables you to manage and automate Junos devices. You can install Junos PyEZ on a UNIX-like operating system or on Windows. You have the option to install and run Junos PyEZ in one of the following ways:

  • Directly on the configuration management server

  • Within a Python virtual environment

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

To install Junos PyEZ on the configuration management server, see the following sections:

To install Junos PyEZ in a Python virtual environment, see the following sections:

To use the Junos PyEZ Docker image, see the following section:

Install 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 3.5 or later

  • All prerequisite software for the given operating system, which is outlined in Table 1

Note:

Python 3.x is supported starting in Junos PyEZ Release 2.0. Python 2.7 support is removed starting in Junos PyEZ Release 2.6.0.

Table 1: Junos PyEZ Prerequisite Software

Operating System

Package or Library

CentOS

  • gcc

  • libffi-devel

  • libxml2-devel

  • libxslt-devel

  • openssl-devel

  • pip

  • python-devel

  • redhat-rpm-config

Debian

  • libxml2-dev

  • libxslt1-dev

  • libssl-dev

  • pip

  • python3-devel (required for Python 3)

Fedora

  • gcc

  • libffi-devel

  • libxml2-devel

  • libxslt-devel

  • openssl-devel

  • pip

  • python3-devel (required for Python 3)

  • redhat-rpm-config

FreeBSD

  • libxml2

  • libxslt

  • py27-pip

OSX

Note:

If Junos PyEZ does not successfully install using pip, try using easy_install to install the lxml library and then Junos PyEZ.

  • pip

  • xcode

Ubuntu

  • libffi-dev

  • libssl-dev

  • libxml2-dev

  • libxslt1-dev

  • python3-dev (required for Python 3)

  • pip

Windows

  • ecdsa

  • pip

Install 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) site. 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 where appropriate):

    Note:

    To upgrade an existing version of Junos PyEZ, include the -U or --upgrade option in the command.

  • To install Junos PyEZ from the GitHub project master branch, execute the following command (use sudo where appropriate):

    Note:

    The latest code in the GitHub source repository is under active development and might not be stable.

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.

Install 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. We recommend that you use Python 3 for your virtual environment.

To create a virtual Python 3 installation with Junos PyEZ on a Linux or macOS server:

  1. Install the prerequisite software on the configuration management server, as outlined in Install Prerequisite Software.
  2. Move into your existing project directory or create a new one, if none exists.
  3. Create a virtual Python installation and specify its name, which in this case is venv.
    Note:

    Ubuntu and Debian systems might require you to install the python3-venv package before you can create the virtual environment.

  4. Activate the virtual environment by executing the script in the virtual environment’s bin directory that is appropriate for your platform and shell.
  5. Install Junos PyEZ.
    • To install the current release of Junos PyEZ from PyPI, execute the following command:

    • To install Junos PyEZ from the GitHub project master branch, execute the following command, which requires that Git is installed:

      Note:

      The latest code in the GitHub source repository is under active development and might not be stable.

  6. Execute your Junos PyEZ commands or scripts within the virtual environment.
  7. When you are finished working in the virtual environment, deactivate it to return to the main shell prompt.

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

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:

      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.

    • To download a specific image, append the appropriate release tag to the image name, for example, 2.1.2.

  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.