Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Retrieve the Pre-Inheritance Candidate Configuration in a Commit Script

This example shows how to construct a commit script to retrieve the pre-inheritance candidate configuration for either a normal or private configuration session.

Requirements

  • Routing, switching, or security device running Junos OS Release 12.2 or later.

Overview

In Junos OS, when a candidate configuration is committed, it is inspected by each active commit script. The normal input for a commit script is the post-inheritance candidate configuration, in which all configuration group values have been inherited by their targets and the inactive portions of the configuration have been removed.

At times, a commit script requires access to the pre-inheritance candidate configuration rather than the post-inheritance configuration it receives by default. Since normal configuration sessions use the regular candidate database, and private configuration sessions use a dedicated, private candidate database, the candidate database location depends on the session type.

Within a commit script, invoking the <get-configuration> remote procedure call (RPC) with the database="candidate" attribute retrieves the normal pre-inheritance candidate configuration. The <get-configuration> RPC also has a database-path attribute, which is used to specify the location of the pre-inheritance configuration database for either a normal or private configuration session. This attribute is an alternative to the database attribute and indicates which database file to load. Commit scripts can invoke the <get-configuration> RPC with the database-path attribute to retrieve the pre-inheritance candidate configuration specific to that session.

The global variable, $junos-context contains the commit-context/database-path element, which stores the location of the session’s pre-inheritance candidate configuration. In a normal configuration session, the <database-path> element contains the location of the normal candidate database:

In a private configuration session, the <database-path> element contains the location of the session-specific, private candidate database. For example:

To construct a commit script that retrieves the pre-inheritance candidate configuration specific to that session, include the <get-configuration> RPC in the commit script, and set the <database-path> attribute to $junos-context/commit-context/database-path. For normal configuration sessions, the commit-script retrieves the normal pre-inheritance candidate configuration, and for private configuration sessions, the commit-script retrieves the private, pre-inheritance candidate configuration.

Note:

If a commit script includes both the database and the database-path attributes in the <get-configuration> tag, the database attribute takes precedence.

Configuration

Configuring the Commit Script

Step-by-Step Procedure

To construct a commit script that retrieves the pre-inheritance candidate configuration specific to that session:

  1. In a text editor, add the commit script boilerplate to a file.

  2. Create a variable that stores the <get-configuration> RPC with the database-path attribute set to $junos-context/commit-context/database-path.

  3. Add a statement that invokes the <get-configuration> RPC and stores the resulting configuration in a variable.

  4. Refer to the desired hierarchy levels and statements in the pre-inheritance candidate configuration using normal XPath constructs, for example:

  5. Include any statements required to enforce your custom configuration rules during the commit process.

  6. Copy the script to the /var/run/scripts/commit directory on the device.

  7. In configuration mode, configure the file statement to enable the commit script.

  8. Issue the commit command to commit the configuration.

    The commit script is executed during the commit operation.

Results