Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Overview of Using Junos PyEZ Configuration Tables to Define and Configure Structured Resources

Junos PyEZ enables you to use Tables and Views to configure Junos devices. Tables and Views are defined using simple YAML files that contain key and value pair mappings, so no complex coding is required to create them. You can create Tables and Views that define structured configuration resources. When you add the Table to the Junos PyEZ framework, Junos PyEZ dynamically creates a configuration class for the resource, which you can use to programmatically configure the resource on a device.

To configure Junos devices using configuration Tables and Views, you must identify the resource to model, create the Table and View definitions for that resource, and then use those definitions to configure the resource in your Junos PyEZ application. The general steps are outlined in this topic.

Create the Structured Resource

To create the structured resource:

  1. Identify the Junos OS configuration for which you want to define a structured resource; for example, a user object at the [edit system login] hierarchy level.
  2. Create the Table and View definitions for the structured resource.

    For detailed information about creating configuration Tables and Views, see Define Junos PyEZ Configuration Tables and Define Views for Junos PyEZ Configuration Tables.

  3. Add the structured resource to the Junos PyEZ framework either as an inline string or as an external file, as discussed in Load Inline or External Tables and Views in Junos PyEZ Applications.

Use the Resource in a Junos PyEZ Application

To configure the resource in your Junos PyEZ application:

  1. Create a Device instance and connect to the device. For example:
  2. Create a Table object and associate it with the device.
  3. Configure the resource by defining values for the necessary fields, including all key fields that are defined in the Table’s key-field property.

    For detailed information about configuring the resource, see Use Junos PyEZ Configuration Tables to Configure Structured Resources on Junos Devices.

  4. Call the append() method to build the Junos XML configuration that contains the configuration changes.
    Note:

    After you call append(), the value for each field is reset to its default value or to None, if the View does not define a default. If you configure another resource, the initial values for that resource are the reset values rather than the values that were configured for the previous resource.

  5. Repeat Step 3 and Step 4 for each additional resource to configure.
  6. Load and commit the configuration changes to the shared configuration database on the device by using one of the following approaches:
    • Call the set() method, which automatically calls the lock(), load(), commit(), and unlock() methods.

    • Call the individual lock(), load(), commit(), and unlock() methods.

  7. Close the device connection.

For more information about the using the different methods to load and commit the configuration data, see Use Junos PyEZ to Configure Junos Devices and Use Junos PyEZ to Commit the Configuration.