Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Create a Complex Configuration Based on a Simple Interface Configuration

This commit script example uses a macro to automatically expand a simple interface configuration.

Requirements

This example uses a device running Junos OS.

Overview and Commit Script

This example uses a commit script and macro to automatically expand a simple interface configuration by generating a transient change that assigns a default encapsulation type, configures multiple routing protocols on the interface, and applies multiple configuration groups. The Junos OS management (mgd) process inspects the configuration, looking for apply-macro params statements included at the [edit interfaces interface-name] hierarchy level.

When the script finds an apply-macro params statement, it performs the following actions:

  • Applies the interface-details configuration group to the interface.

  • Includes the value of the description parameter at the [edit interfaces interface-name description] hierarchy level.

  • Includes the value of the encapsulation parameter at the [edit interfaces interface-name encapsulation] hierarchy level. If the encapsulation parameter is not included in the apply-macro params statement, the script sets the encapsulation to cisco-hdlc as the default.

  • Sets the logical unit number to 0 and tests whether the inet-address parameter is included in the apply-macro params statement. If it is, the script includes the value of the inet-address parameter at the [edit interfaces interface-name unit 0 family inet address] hierarchy level.

  • Includes the interface name at the [edit protocols rsvp interface] hierarchy level.

  • Includes the level 1 enable and metric statements at the [edit protocols isis interface interface-name] hierarchy level.

  • Includes the level 2 enable and metric statements at the [edit protocols isis interface interface-name] hierarchy level.

  • Tests whether the isis-level-1 or isis-level-1-metric parameter is included in the apply-macro params statement. If one or both of these parameters are included, the script includes the level 1 statement at the [edit protocols isis interface interface-name] hierarchy level. If the isis-level-1 parameter is included, the script also includes the value of the isis-level-1 parameter (enable or disable) at the [edit protocols isis interface interface-name level 1] hierarchy level. If the isis-level-1-metric parameter is included, the script also includes the value of the isis-level-1-metric parameter at the [edit protocols isis interface interface-name level 1 metric] hierarchy level.

  • Tests whether the isis-level-2 or isis-level-2-metric parameter is included in the apply-macro params statement. If one or both of these parameters are included, the script includes the level 2 statement at the [edit protocols isis interface interface-name] hierarchy level. If the isis-level-2 parameter is included, the script also includes the value of the isis-level-2 parameter (enable or disable) at the [edit protocols isis interface interface-name level 2] hierarchy level. If the isis-level-2-metric parameter is included, the script also includes the value of the isis-level-2-metric parameter at the [edit protocols isis interface interface-name level 2 metric] hierarchy level.

  • Includes the interface name at the [edit protocols ldp interface] hierarchy level.

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

XSLT Syntax

SLAX Syntax

Topology

Configuration

Procedure

Step-by-Step Procedure

To download, enable, and test the script:

  1. Copy the script into a text file, name the file if-params.xsl or if-params.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 if-params.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

Issue the show interfaces | display commit-scripts | display inheritance configuration mode command. The | display commit-scripts option displays all the statements that are in the configuration, including statements that are generated by transient changes. The | display inheritance option displays inherited configuration data and information about the source group from which the configuration has been inherited. This option also shows interface ranges configuration data in expanded format and information about the source interface-range from which the configuration has been expanded. You should see the following output:

Issue the show protocols | display commit-scripts configuration mode command. You should see the following output: