Examples: Generating Persistent and Transient Changes

This section is organized as follows:

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.

The persistent change is generated by the <jcs:emit-change> template, which is a helper template contained in the junos.xsl import file. 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 at the CLI, notifying you that the configuration has been changed.

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>;
                    }
                }
            }
        }
    }
}

Verifying the Persistent Change Generated by the Commit Script

To test that a commit script generates a persistent change correctly, make sure that the candidate configuration contains the condition that elicits the change. For this example, ensure that the family mpls statement is not included at the [edit interfaces so-fpc/pic/port unit logical-unit-number] hierarchy level.

The sample script produces a message announcing the change it is making. To display the XML-formatted version of the message, issue the commit check | display xml command:

[edit]

user@host# commit check | display xml
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.0R1/junos">
    <commit-results>
        <routing-engine junos:style="normal">
            <name>re0</name>
            <xnm:warning>
                <edit-path>
                    [edit interfaces interface so-2/3/4 unit 0]
                </edit-path>
                <message>
                    Adding 'family mpls' to SONET 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:

[edit]

user@host# commit check | display detail
2009-06-17 14:17:35 PDT: reading commit script configuration
2009-06-17 14:17:35 PDT: testing commit script configuration
2009-06-17 14:17:35 PDT: opening commit script '/var/db/scripts/commit/mpls.xsl'
2009-06-17 14:17:35 PDT: reading commit script 'mpls.xsl'
2009-06-17 14:17:35 PDT: running commit script 'mpls.xsl'
2009-06-17 14:17:35 PDT: processing commit script 'mpls.xsl'
2009-06-17 14:17:35 PDT: no errors from mpls.xsl
2009-06-17 14:17:35 PDT: saving commit script changes
2009-06-17 14:17:35 PDT: summary: changes 0, transients 0 (allowed), syslog 0
2009-06-17 14:17:35 PDT: no commit script changes
2009-06-17 14:17:35 PDT: finished loading commit script changes
2009-06-17 14:17:35 PDT: exporting juniper.conf
2009-06-17 14:17:35 PDT: expanding groups
2009-06-17 14:17:35 PDT: finished expanding groups
2009-06-17 14:17:35 PDT: setup foreign files
2009-06-17 14:17:35 PDT: propagating foreign files
2009-06-17 14:17:35 PDT: complete foreign files
2009-06-17 14:17:36 PDT: daemons checking new configuration
configuration check succeeds

To view the configuration with the persistent change, issue 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, something similar to the following appears after the commit script runs:

[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 ...

Example: Generating a Transient Change

Using a commit script, make a transient configuration change that sets PPP encapsulation on all SONET/SDH interfaces with the IPv4 protocol family enabled:

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-')
                          and unit/family/inet]">
            <xsl:call-template name="jcs:emit-change">
                <xsl:with-param name="tag" select="'transient-change'"/>
                <xsl:with-param name="content">
                    <encapsulation>ppp</encapsulation>
                </xsl:with-param>
            </xsl:call-template>
        </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-') and unit/family/inet]) {
        call jcs:emit-change($tag = 'transient-change') {
            with $content = {
                <encapsulation> "ppp";
            }
        }
    }
}

Verifying the Transient Change Generated by the Commit Script

To display a detailed trace of commit script processing, issue the commit check | display detail command:

[edit]

user@host# commit check | display detail
2009-06-15 12:07:30 PDT: reading commit script configuration
2009-06-15 12:07:30 PDT: testing commit script configuration
2009-06-15 12:07:30 PDT: opening commit script '/var/db/scripts/commit/transient.xsl'
2009-06-15 12:07:30 PDT: reading commit script 'transient.xsl'
2009-06-15 12:07:30 PDT: running commit script 'transient.xsl'
2009-06-15 12:07:30 PDT: processing commit script 'transient.xsl'
2009-06-15 12:07:30 PDT: no errors from transient.xsl
2009-06-15 12:07:30 PDT: saving commit script changes
2009-06-15 12:07:30 PDT: summary: changes 0, transients 2 (allowed), syslog 0
2009-06-15 12:07:30 PDT: no commit script changes
2009-06-15 12:07:30 PDT: exporting juniper.conf
2009-06-15 12:07:30 PDT: loading transient changes
2009-06-15 12:07:30 PDT: loading commit script changes(transient)
2009-06-15 12:07:30 PDT: finished loading commit script changes
2009-06-15 12:07:30 PDT: expanding groups
2009-06-15 12:07:30 PDT: finished expanding groups
2009-06-15 12:07:30 PDT: setup foreign files
2009-06-15 12:07:30 PDT: propagating foreign files
2009-06-15 12:07:31 PDT: complete foreign files
2009-06-15 12:07:31 PDT: daemons checking new configuration
configuration check succeeds

To display the configuration with the transient change, issue the show interfaces | display commit-scripts configuration mode command. If there are one or more SONET/SDH interfaces with the IPv4 protocol family enabled, the output is similar to this:

[edit]

user@host# show interfaces | display commit-scripts
... other configured interface types ...
so-1/2/3 {
    mtu 576;
    encapsulation ppp; /* Added by transient change. */
    unit 0 {
        family inet {
            address 10.0.0.3/32;
        }
    }
}
so-1/2/4 {
    encapsulation ppp; /* Added by transient change. */
    unit 0 {
        family inet {
            address 10.0.0.4/32;
        }
    }
}
so-2/3/4 {
    encapsulation cisco-hdlc; # Not affected by this script, because IPv4 protocol
                              # family is not configured on this interface.
    unit 0 {
        family mpls;
    }
}
... other configured interface types ...