Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Prepend a Global Policy

This commit script example ensures that a BGP global import policy is applied to all your BGP imports before any other import policies are applied.

Requirements

This example uses a device running Junos OS.

Overview and Commit Script

For most configuration objects, the order in which the object or its children is created is not significant, because the Junos OS configuration management software stores and displays configuration objects in predetermined positions in the configuration hierarchy. However, some configuration objects—such as routing policies and firewall filters—consist of elements that must be processed and analyzed sequentially in order to produce the intended routing behavior.

This example commit script ensures that a BGP global import policy is applied to all your BGP imports before any other import policies are applied.

This example automatically prepends the bgp_global_import policy in front of any other BGP import policies. If the bgp_global_import policy statement is not included in the configuration, an error message is generated, and the commit operation fails.

Otherwise, the commit script uses the insert="before" Junos XML protocol attribute and the position() XSLT function to control the position of the global BGP policy in relation to any other applied policies. The insert="before" attribute inserts the bgp_global_import policy in front of the first preexisting BGP import policy.

If there is no preexisting default BGP import policy, the global policy is included in the configuration.

The example script is shown in both XSLT and SLAX syntax:

XSLT Syntax

SLAX Syntax

Configuration

Procedure

Step-by-Step Procedure

To download, enable, and test the script:

  1. Copy the script into a text file, name the file bgp-global-import.xsl or bgp-global-import.slax as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.

  2. Select the following test configuration stanzas, and press Ctrl+c to copy them to the clipboard.

    If you are using the SLAX version of the script, change the filename at the [edit system scripts commit file] hierarchy level to bgp-global-import.slax.

  3. In configuration mode, issue the load merge terminal command to merge the stanzas into your device configuration.

    1. At the prompt, paste the contents of the clipboard by using the mouse and the paste icon.

    2. Press Enter.

    3. Press Ctrl+d.

  4. Commit the configuration.

Verification

Verifying the Configuration

Purpose

Verify that the script behaves as expected.

Action

When you issue the show protocols configuration mode command, the bgp_global_import import policy is not displayed, because it is added as a transient change.

The commit script adds the import bgp_global_import statement at the [edit protocols bgp] hierarchy level and prepends the bgp_global_import policy to the 192.168.16.4 neighbor policy chain. Issue the show protocols | display commit-scripts to view all configuration statements including transient changes.

After you add a policy to the 192.168.16.6 neighbor, which previously had no policies applied, the bgp_global_import policy is prepended. Issue the show protocols | display commit-scripts command to view all configuration statements including transient changes.