Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Design Considerations for Commit Scripts

 

After you have some experience looking at Junos OS configuration data in XML, creating commit scripts is fairly straightforward. This section provides some advice and common patterns for developing commit scripts using XSLT.

XSLT is an interpreted language, making performance an important consideration. For best performance, minimize node traversals and testing performed on each node. When possible, use the select attribute on a recursive <xsl:apply-templates> invocation to limit the portion of the document hierarchy being visited.

For example, the following select attribute limits the nodes to be evaluated by specifying SONET/SDH interfaces that have the inet (IPv4) protocol family enabled:

The following example contains two <xsl:apply-templates> instructions that limit the scope of the script to the import statements configured at the [edit protocols ospf] and [edit protocols isis] hierarchy levels:

In an interpreted language, doing anything more than once can affect performance. If the script needs to reference a node or node set repeatedly, make a variable that holds the node set, and then make multiple references to the variable. For example, the following variable declaration creates a variable called mpls that resolves to the [edit protocols mpls] hierarchy level. This allows the script to traverse the /protocols/ hierarchy searching for the mpls/ node only once.

Variables are also important when using <xsl:for-each> instructions, because the current context node examines each node selected by the <xsl:for-each> instruction. For example, the following script uses multiple variables to store and refer to values as the <xsl:for-each> instruction evaluates the E1 interfaces that are configured on all channelized STM1 (cstm1-) interfaces:

If you channelize a cstm1-0/1/0 interface into 17 E1 interfaces, the script causes the following error message to appear when you issue the commit command. (For more information about this example, see Example: Limiting the Number of E1 Interfaces.)

user@host# commit