Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

Line-by-Line Explanation of Sample Commit Scripts

 

Applying a Change to SONET/SDH Interfaces

The following XSLT commit script applies a transient change to each interface whose name begins with so-, setting the encapsulation to ppp. For information about transient changes, see Overview of Generating Persistent or Transient Configuration Changes Using Commit Scripts. For a SLAX version of this example, see Example: Generating a Transient Change.

Lines 1 through 8 are boilerplate as described in Required Boilerplate for Commit Scripts and are omitted here for brevity.

Line 9 is an <xsl:for-each> programming instruction that examines each interface node whose names starts with 'so-' and that has family inet enabled on any logical unit. (It appears here on two lines only for brevity.)

Line 10 is the open tag for a transient change. The possible contents of the <transient-change> element are the same as the contents of the <configuration> tag element in the Junos XML protocol operation <load-configuration>.

Lines 11 through 16 represent the content of the transient change. The encapsulation is set to ppp.

Lines 17 through 19 close all open tags in this template.

Line 20 closes the style sheet and the commit script.

Applying a Change to ISO-Enabled Interfaces

The following sample XSLT script ensures that interfaces that are enabled for an International Organization for Standardization (ISO) protocol also have MPLS enabled and are included at the [edit protocols mpls interface] hierarchy level. For a SLAX version of this example, see Example: Controlling IS-IS and MPLS Interfaces.

Lines 1 through 8 are boilerplate as described in Required Boilerplate for Commit Scripts and are omitted here for brevity.

Line 9 saves a reference to the [edit protocols mpls] hierarchy level so that it can be referenced in the following for-each loop.

Line 10 examines each interface unit (logical interface) on which ISO is enabled. The select stops at the unit, but the predicate limits the selection to only those units that contain an <iso> element nested under a <family> element.

Line 11 builds the interface name in a variable. First, the name attribute of the variable declaration is set to ifname. In Junos OS, an interface name is the concatenation of the device name, a period, and the unit number. At this point in the script, the context node is the unit number, because Line 10 changes the context to interfaces/interface/unit. The ../name refers to the <name> element of the parent node of the context node, which is the device name (type-fpc/pic/port). The "name" token in the XPath expression refers to the <name> element of the context node, which is the unit number (unit-number). After the concatenation is performed, the XPath expression in Line 11 resolves to type-fpc/pic/port.unit-number. As the <xsl:for-each> instruction in Line 10 traverses the hierarchy and locates ISO-enabled interfaces, the interface names are recursively stored in the ifname variable.

Line 12 evaluates as true for each ISO-enabled interface that does not have MPLS enabled.

Line 13 calls the jcs:emit-change template, which is a helper or convenience template in the junos.xsl file. This template is discussed in emit-change Template (SLAX and XSLT) and emit_change (Python) .

Lines 14 through 18 use the message parameter from the jcs:emit-change template. The message parameter is a shortcut you can use instead of explicitly including the <warning>, <edit-path>, and <statement> elements.

Lines 19 through 23 use the content parameter from the jcs:emit-change template. The content parameter specifies the change to make, relative to the current context node.

Lines 24 and 25 close the tags opened in Lines 13 and 12, respectively.

Line 26 tests whether MPLS is already enabled and if this interface is not configured at the [edit protocols mpls interface] hierarchy level.

Lines 27 through 41 contain another invocation of the jcs:emit-change template. In this invocation, the interface is added at the [edit protocols mpls interface] hierarchy level.

Lines 42 through 45 close all open elements.