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

 

Starting in Junos PyEZ Release 2.0, Junos PyEZ enables you to use Tables and Views to configure devices running Junos OS. 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 devices running Junos OS 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.

Creating 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.
    user@host> show configuration system login | display xml
  2. Create the Table and View definitions for the structured resource.

    For detailed information about creating configuration Tables and Views, see Defining Junos PyEZ Configuration Tables and Defining Junos PyEZ Views for 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 Loading Inline or External Tables and Views in Junos PyEZ Applications.

Using 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 Using Junos PyEZ Configuration Tables to Configure Structured Resources on Devices Running Junos OS.

  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 Using Junos PyEZ to Configure Devices Running Junos OS and Using Junos PyEZ to Commit the Configuration.