Supported Platforms
Related Documentation
- ACX, EX, M, MX, SRX, T Series
- Example: Generating a Transient Change
- ACX, EX, M, MX, PTX, SRX, T Series
- Generating a Persistent or Transient Change
- Removing a Persistent or Transient Change
- jcs:emit-change Template
- ACX, EX, J, M, MX, PTX, QFX, SRX, T Series
- Overview of Generating Persistent or Transient Configuration Changes
Example: Generating a Persistent Change
If you do not explicitly configure the MPLS protocol family on an interface, the interface is not enabled for MPLS applications. This example generates a persistent change that adds the family mpls statement in the configuration of SONET/SDH interfaces when the statement is not already included in the configuration.
Requirements
This example uses a device running Junos OS with one or more SONET/SDH interfaces.
Overview and Commit Script
The commit script in this example finds all SONET/SDH interfaces that have a logical interface configured but that do not have the family mpls statement configured. For these interfaces, the script adds the family mpls statement to the interface configuration as a persistent change at the [edit interfaces interface-name unit logical-unit-number hierarchy level.
The persistent change is generated by the jcs:emit-change template, which is a helper template contained in the junos.xsl
import file. The tag parameter of the jcs:emit-change template
is omitted, which directs the script to emit the change as a persistent
change. The content parameter of the jcs:emit-change template includes the configuration
statements to be added as a persistent change. The message parameter of the jcs:emit-change template
includes the warning message to be displayed in the CLI, notifying
you that the configuration has been changed.
The script is shown in both XSLT and SLAX syntax.
XSLT Syntax
<?xml version="1.0" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:junos="http://xml.juniper.net/junos/*/junos"
xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm"
xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0">
<xsl:import href="../import/junos.xsl"/>
<xsl:template match="configuration">
<xsl:for-each select="interfaces/interface[starts-with(name, 'so-')]/unit">
<xsl:if test="not(family/mpls)">
<xsl:call-template name="jcs:emit-change">
<xsl:with-param name="message">
<xsl:text>Adding 'family mpls' to SONET/SDH interface.</xsl:text>
</xsl:with-param>
<xsl:with-param name="content">
<family>
<mpls/>
</family>
</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
SLAX Syntax
version 1.0;
ns junos = "http://xml.juniper.net/junos/*/junos";
ns xnm = "http://xml.juniper.net/xnm/1.1/xnm";
ns jcs = "http://xml.juniper.net/junos/commit-scripts/1.0";
import "../import/junos.xsl";
match configuration {
for-each (interfaces/interface[starts-with(name, 'so-')]/unit) {
if (not(family/mpls)) {
call jcs:emit-change() {
with $message = {
expr "Adding 'family mpls' to SONET/SDH interface.";
}
with $content = {
<family> {
<mpls>;
}
}
}
}
}
}
Configuration
Step-by-Step Procedure
Download, enable, and test the script.
- Copy the XSLT or SLAX script into a text file, name the
file
mpls.xsl
ormpls.slax
as appropriate, and copy it to the/var/db/scripts/commit/
directory on the device. In configuration mode, include the file statement at the [edit system scripts commit] hierarchy level and
mpls.xsl
ormpls.slax
as appropriate.[edit]user@host# set system scripts commit file mpls.xslTo test that the commit script generates the persistent change correctly, make sure that the configuration contains the condition that elicits the change. To test this script, ensure that the family mpls statement is not included at the [edit interfaces so-fpc/pic/port unit logical-unit-number] hierarchy level for at least one SONET/SDH interface.
If the family mpls statement is included at the [edit interfaces so-fpc/pic/port unit logical-unit-number] hierarchy level, issue the following configuration mode command to delete the statement:
[edit]user@host# delete interfaces so-fpc/pic/port unit logical-unit-number family mpls- The commit check command verifies the syntax
of the configuration prior to a commit, but it does not commit the
changes. The commit script in this example produces a message for
each change it makes. Use the commit check command to preview
these messages to determine whether the script will update the configuration
with the family mpls statement for the appropriate interfaces.
Issue the commit check | display xml command to display the XML-formatted version of the message. The sample output indicates that the script will add the family mpls statement to the so-2/3/4 interface configuration during the commit operation.
[edit]
user@host# commit check | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/11.2R1/junos">
<commit-results>
<routing-engine junos:style="normal">
<name>re0</name>
<xnm:warning xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm">
<edit-path>
[edit interfaces interface so-2/3/4 unit 0]
</edit-path>
<message>
Adding 'family mpls' to SONET/SDH interface.
</message>
</xnm:warning>
<commit-check-success/>
</routing-engine>
</commit-results>
</rpc-reply> - To display a detailed trace of commit script processing,
issue the commit check | display detail command. In the
sample output, there is one persistent change that will be loaded
into the configuration during the commit operation.
[edit]
user@host# commit check | display detail
2011-06-17 14:17:35 PDT: reading commit script configuration
2011-06-17 14:17:35 PDT: testing commit script configuration
2011-06-17 14:17:35 PDT: opening commit script '/var/db/scripts/commit/mpls.xsl'
2011-06-17 14:17:35 PDT: reading commit script 'mpls.xsl'
2011-06-17 14:17:35 PDT: running commit script 'mpls.xsl'
2011-06-17 14:17:35 PDT: processing commit script 'mpls.xsl'
2011-06-17 14:17:35 PDT: no errors from mpls.xsl
2011-06-17 14:17:35 PDT: saving commit script changes for script mpls.xsl
2011-06-17 14:17:35 PDT: summary of script mpls.xsl: changes 1, transients 0, syslog 0
2011-06-17 14:17:35 PDT: start loading commit script changes
2011-06-17 14:17:35 PDT: loading commit script changes into real db
2011-06-17 14:17:35 PDT: finished commit script changes into real db
2011-06-17 14:17:35 PDT: no transient commit script changes
2011-06-17 14:17:35 PDT: finished loading commit script changes
2011-06-17 14:17:35 PDT: copying juniper.db to juniper.data+
2011-06-17 14:17:35 PDT: finished copying juniper.db to juniper.data+
... configuration check succeeds After verifying that the script produces the correct changes, issue the commit command to start the commit operation and execute the script.
user@host# commit
Verification
Verifying the Configuration
Purpose
Verify that the correct changes are integrated into the configuration.
Action
After executing the commit operation, view the configuration by issuing the show interfaces configuration mode command. If the MPLS protocol family is not enabled on one or more SONET/SDH interfaces before the script runs, the output is similar to the following:
[edit]
user@host# show interfaces
... other configured interface types ...
so-2/3/4 {
unit 0 {
family mpls; # Added by persistent change
}
}
... other configured interface types ...
Related Documentation
- ACX, EX, M, MX, SRX, T Series
- Example: Generating a Transient Change
- ACX, EX, M, MX, PTX, SRX, T Series
- Generating a Persistent or Transient Change
- Removing a Persistent or Transient Change
- jcs:emit-change Template
- ACX, EX, J, M, MX, PTX, QFX, SRX, T Series
- Overview of Generating Persistent or Transient Configuration Changes
Published: 2013-07-26
Supported Platforms
Related Documentation
- ACX, EX, M, MX, SRX, T Series
- Example: Generating a Transient Change
- ACX, EX, M, MX, PTX, SRX, T Series
- Generating a Persistent or Transient Change
- Removing a Persistent or Transient Change
- jcs:emit-change Template
- ACX, EX, J, M, MX, PTX, QFX, SRX, T Series
- Overview of Generating Persistent or Transient Configuration Changes