Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Generate a Persistent or Transient Configuration Change in Python Commit Scripts

Junos OS commit scripts enforce custom configuration rules and can automatically change the configuration when it does not comply with your rules. When a commit script changes the configuration, it can generate a persistent change or a transient change.

To generate a persistent or transient change using Python commit scripts:

  1. Include the Python commit script boilerplate from Required Boilerplate for Commit Scripts, which is reproduced here for convenience:
  2. Include one or more programming instructions that test for your custom configuration rules.

    For example, the following code selects each ge-0/0/* interface that does not have the MPLS protocol family enabled:

  3. Create an XML string that instructs Junos OS how to modify the configuration.

    This example enables the MPLS protocol family for the selected interfaces.

  4. To generate the persistent or transient change, call the jcs.emit_change method. Specify the type of change as 'change' or 'transient-change' in the argument list.
  5. Include any additional required or optional code. This example generates a warning message in the CLI when the commit script updates an interface.
  6. Save the script with a meaningful name.
  7. Copy the script to the /var/db/scripts/commit directory on the hard disk or the /config/scripts/commit directory on the flash drive as appropriate.
    Note:

    Unsigned Python scripts must be owned by either root or a user in the Junos OS super-user login class, and only the file owner can have write permission for the file.

  8. Enable the script by configuring the file filename statement at the [edit system scripts commit] hierarchy level.
  9. If the script generates transient changes, configure the allow-transients statement.

    Configure the statement at the [edit system scripts commit] hierarchy level to enable all commit scripts to make transient changes.

    Alternatively, on supported devices and releases, configure the statement at the [edit system scripts commit file filename] hierarchy level to enable only the individual script to make transient changes.

  10. Enable the execution of unsigned Python scripts on the device.
  11. Commit the configuration.

The resulting script searches for ge-0/0/* interfaces that do not have the MPLS protocol family enabled. The script adds the family mpls statement at the [edit interfaces ge-0/0/port unit logical-unit-number] hierarchy level as a persistent change. For each updated interface, the script emits a warning message stating that it changed the interface configuration.

If all enabled commit scripts run without errors, the device loads any persistent changes into the candidate configuration. The device loads any transient changes into the checkout configuration, but not to the candidate configuration. The commit process then continues by validating the configuration and propagating changes to the affected processes on the device.

To display the configuration with both persistent and transient changes applied, issue the show | display commit-scripts configuration mode command.

To display the configuration with only persistent changes applied, issue the show | display commit-scripts no-transients configuration mode command.

The device loads persistent and transient changes into the configuration in the same manner that the load replace configuration mode command loads an incoming configuration. When generating a persistent or transient change, adding the replace="replace" attribute to a configuration element produces the same behavior as a replace: tag in a load replace operation. Both persistent and transient changes are loaded into the configuration with the load replace behavior. However, persistent changes are loaded into the candidate configuration, and transient changes are loaded into the checkout configuration.