Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Required Boilerplate for Commit Scripts

Define the boilerplate for commit scripts.

You can write Junos OS commit scripts in Extensible Stylesheet Language Transformations (XSLT), Stylesheet Language Alternative syntaX (SLAX), or Python. Commit scripts must include the necessary boilerplate required for that script language. Include boilerplate for both basic script functionality as well as any optional functionality used within the script such as the Junos OS extension functions and named templates. This topic provides standard boilerplate that you can use in XSLT, SLAX, and Python commit scripts.

XSLT Boilerplate for Commit Scripts

The XSLT commit script boilerplate is as follows:

Line 1 is the Extensible Markup Language (XML) processing instruction (PI). This PI specifies that the code is written in XML using version 1.0. The XML PI, if present, must be the first noncomment token in the script file.

Line 2 opens the style sheet and specifies the XSLT version as 1.0.

Lines 3 through 6 list all the namespace mappings commonly used in commit scripts. Not all of these prefixes are used in this example. Listing all namespace mappings prevents errors if you use the mappings in later versions of the script.

Line 7 is an XSLT import statement. It loads the templates and variables from the ../import/junos.xsl file, which ships as part of the Junos OS. The junos.xsl file contains a set of named templates you can call in your scripts. For more information about the named templates, see Understanding Named Templates in Junos OS Automation Scripts.

Line 8 defines a template that matches the <configuration> element, which is the node selected by the <xsl:template match="/"> template, contained in the junos.xsl import file. The <xsl:template match="configuration"> element allows you to exclude the /configuration/ root element from all XPath expressions in the script and begin XPath expressions with the top Junos OS hierarchy level. For more information, see XPath Overview.

Add your code between Lines 8 and 9.

Line 9 closes the template.

Line 10 closes the style sheet and the commit script.

SLAX Boilerplate for Commit Scripts

The SLAX commit script boilerplate is as follows:

Python Boilerplate for Commit Scripts

Python commit scripts do not have a required boilerplate. However, Python commit scripts must import any objects that the script uses. Python commit scripts can import the following:

  • Junos_Context dictionary—Contains information about the script execution environment.

  • Junos_Configuration object—Contains the post-inheritance candidate configuration.

  • jcs library—Enables the script to use Junos OS extension functions and named templates in the script.

  • jnpr.junos module and classes—Enable the script to use Junos PyEZ.

For example:

Python automation scripts do not need to include an interpreter directive line (#!/usr/bin/env python) at the start of the script. However, the program still executes correctly if one is present.