Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Using Salt with Junos PyEZ Tables to Retrieve Operational and Configuration Data from Devices Running Junos OS

Juniper Networks provides support for using Salt to manage devices running Junos OS, and the Junos execution and state modules (for Salt) define functions that enable you to perform operational and configuration tasks on the managed devices. The salt.modules.junos.get_table execution function and the salt.states.junos.get_table state function can reference predefined or custom Junos PyEZ Tables to extract operational information or configuration data from a device running Junos OS.

Understanding Junos PyEZ Tables

Junos PyEZ is a microframework for Python that enables you to manage and automate devices running Junos OS. The Junos proxy minion (for Salt) connects to the Salt master using the ZeroMQ event bus and uses the Junos PyEZ library to connect to the device running Junos OS. As a result, Salt can leverage Junos PyEZ features when managing the devices.

Junos PyEZ supports using simple YAML definitions, which are referred to as Tables and Views, to retrieve and filter operational command output and configuration data from devices running Junos OS. Junos PyEZ operational (op) Tables extract information from the output of operational commands or RPCs, and configuration Tables retrieve specific configuration data. The Junos PyEZ jnpr.junos.op modules contain predefined Table and View definitions for some common RPCs. You can also create custom Tables and Views.

When you use Salt to manage devices running Junos OS, the junos.get_table function can use Junos PyEZ Tables to retrieve data from a device. The function can reference the predefined operational Tables and Views that are included with the Junos PyEZ distribution, or it can reference user-defined operational and configuration Tables and Views that reside on either the Salt master or a separate proxy minion server.

For general information about Junos PyEZ Tables and Views, see the following sections and related documentation in the Junos PyEZ Developer Guide:

junos.get_table Function Overview

The junos.get_table function can use Junos PyEZ Tables to retrieve data from a device running Junos OS. The basic syntax for the junos.get_table execution function and state function is presented here. For a complete list of the available function parameters, see the API documentation for the function.

The salt.modules.junos.get_table execution function syntax is:

The salt.states.junos.get_table state function syntax is:


  • id—User-defined identifier for the state declaration.

  • path: path—(Optional) Path to the YAML file that contains the Table and View definitions.

  • table: table—Name of the Junos PyEZ Table.

  • table_file: table_file—Filename of the YAML file that contains the Table and View definitions.

You use the path and table_file parameters to specify the path and filename of the YAML file containing the Table definition. If you import a Table from the jnpr.junos.op module included with the Junos PyEZ distribution, you can omit the path parameter. In this case, the get_table function automatically checks the appropriate directory in the Junos PyEZ install path for the specified Table file. You can also specify a path to a custom Table. If you use a custom Table, the Table can reside on the Salt master or proxy minion server. Table 1 outlines the different Tables you can use, the location of the Tables, and the required value for the path parameter.

Table 1: get_table Table Types



path Value


jnpr.junos.op module Tables

jnpr/junos/op directory under the Junos PyEZ install path on the proxy minion server

  - table: ArpTable
  - table_file: arp.yml

Custom Tables

Salt master

Path (using salt:// notation) to the YAML file containing the custom Table.

  - table: IFTable
  - table_file: IFTable.yml
  - path: salt://tables 

Proxy minion server

Absolute path to the YAML file containing the custom Table.

  - table: IFTable
  - table_file: IFTable.yml
  - path: /srv/salt/tables 

How to Use the junos.get_table Function

You can call the junos.get_table function to use a Junos PyEZ Table to retrieve operational or configuration data from a device running Junos OS. The following command uses the ArpTable Table in the jnpr.junos.op module to retrieve Address Resolution Protocol (ARP) entries for the target device. The Table is defined in the arp.yml file located in the Junos PyEZ jnpr/junos/op directory.

The function’s response includes the device’s hostname, the Table and View, and the out key, which returns True if the operation is successful. If the operation is successful, the response also includes the reply key, which contains the Table items. Each Table item includes the fields defined by the View and the value extracted from the data for each of the corresponding fields.

As another example, the following state file retrieves interface status information using a custom Junos PyEZ Table named IFTable. The Table and View are defined in the /srv/salt/tables/IFTable.yml file on the Salt master.

How to Define Optional Parameters in Tables and Views

Junos PyEZ Tables and Views can include a number of optional parameters depending on the type of Table. The Table and View definitions can define default values for these parameters. You can also specify or override the value for one or more parameters when you use the Table in an application.

The junos.get_table function enables you to define a value or override the default value for many of these same parameters. For example, when you call the junos.get_table function, you can include the key argument for Tables that support the corresponding parameter. You can also include the table_args argument to supply key/value pairs for the args parameter in op Tables. For information about the parameters supported by the different types of Tables and Views, see the Junos PyEZ Developer Guide.

Consider the EthPortTable Table in the jnpr.junos.op module, which executes the get-interface-information RPC. The RPC uses the default arguments media: True and interface_name: '[afgxe][et]-*'.

In this case, when you call the junos.get_table function, you can include optional parameters that are supported by op Tables that execute RPCs and return structured output. For example, you can include the table_args parameter to override the default values for the RPC arguments that are defined in args.

The following command uses EthPortTable to retrieve interface information from the device, and it includes the table_args parameter to only return data for 10-Gigabit Ethernet (GbE) interfaces instead of the default set of interfaces defined in the Table. The Table definition displayed in the output reflects the updated arguments under args.

The equivalent state file is: