- play_arrow Overview
- play_arrow Junos Automation Scripts Overview
- play_arrow Junos XML Management Protocol and Junos XML API Overview
-
- play_arrow Automation Scripting Using XSLT
- play_arrow XSLT Overview
- play_arrow Standard XPath and XSLT Functions Used in Automation Scripts
- play_arrow Standard XSLT Elements and Attributes Used in Automation Scripts
-
- play_arrow Automation Scripting Using SLAX
- play_arrow SLAX Overview
- SLAX Overview
- SLAX Syntax Rules Overview
- SLAX Elements and Element Attributes Overview
- SLAX Elements as Function Arguments
- Understanding SLAX Default Namespaces
- XPath Expressions Overview for SLAX
- SLAX Templates Overview
- SLAX Functions Overview
- SLAX Parameters Overview
- SLAX Variables Overview
- SLAX Statements Overview
- XSLT Elements Without SLAX Equivalents
- SLAX Operators
- play_arrow SLAX Statements
- append
- apply-imports
- apply-templates
- attribute
- attribute-set
- call
- copy-node
- copy-of
- decimal-format
- element
- else
- else if
- expr
- fallback
- for
- for-each
- function
- if
- import
- key
- match
- message
- mode
- mvar
- number
- output-method
- param
- preserve-space
- priority
- processing-instruction
- result
- set
- sort
- strip-space
- template
- terminate
- trace
- uexpr
- use-attribute-sets
- var
- version
- while
- with
- play_arrow The libslax Distribution for Automation Scripting
- libslax Distribution Overview
- libslax Library and Extension Libraries Overview
- Download and Install the libslax Distribution
- libslax Default Extension Libraries: bit, curl, db, os, and xutil
- Understanding the SLAX Processor (slaxproc)
- How to Use the SLAX Processor (slaxproc)
- SLAX Debugger, Profiler, and callflow
-
- play_arrow Automation Scripting Using Python
- play_arrow Python Overview
- Understanding Python Automation Scripts for Junos Devices
- Requirements for Executing Python Automation Scripts on Junos Devices
- Overview of Python Modules on Junos Devices
- How to Use Python Interactive Mode on Devices Running Junos OS
- How to Use the psutil Module to Retrieve Process and System Information on Devices Running Junos OS
- How to Use the Requests Library for Python on Devices Running Junos OS
- IPv6 Support in Python Automation Scripts
- How to Specify the Routing Instance in Python 3 Applications on Devices Running Junos OS Evolved
-
- play_arrow Automation Script Input
- play_arrow Global Parameters in Automation Scripts
-
- play_arrow Extension Functions and Named Templates for Automation Scripts
- play_arrow Extension Functions for Automation Scripting
- play_arrow Extension Functions in the jcs and slax Namespaces
- base64-decode() Function (SLAX)
- base64-encode() Function (SLAX)
- break-lines() Function (SLAX and XSLT)
- close() Function (SLAX and XSLT)
- dampen() Function (Python, SLAX, and XSLT)
- document() Function (SLAX)
- emit_error() Function (Python)
- emit_snmp_attributes Function (Python)
- emit_warning() Function (Python)
- empty() Function (SLAX and XSLT)
- evaluate() Function (SLAX)
- execute() Function (SLAX and XSLT)
- first-of() Function (SLAX and XSLT)
- get-command() Function (SLAX)
- get-hello() Function (SLAX and XSLT)
- get-input() Function (SLAX and XSLT) and get_input() (Python)
- get-protocol() Function (SLAX and XSLT)
- get-secret() Function (SLAX and XSLT) and get_secret() (Python)
- get_snmp_action() Function (Python)
- get_snmp_oid() Function (Python)
- hostname() Function (Python, SLAX, and XSLT)
- invoke() Function (SLAX and XSLT)
- open() Function (SLAX and XSLT)
- output() Function (Python, SLAX, and XSLT)
- parse-ip() Function (SLAX and XSLT) and parse_ip() (Python)
- printf() Function (Python, SLAX, and XSLT)
- progress() Function (Python, SLAX, and XSLT)
- regex() Function (SLAX and XSLT)
- set_routing_instance() Function (Python)
- sleep() Function (SLAX and XSLT)
- split() Function (SLAX and XSLT)
- sysctl() Function (Python, SLAX, and XSLT)
- syslog() Function (Python, SLAX, and XSLT)
- trace() Function (Python, SLAX, and XSLT)
- play_arrow Named Templates for Automation Scripting
- play_arrow Named Templates in the jcs Namespace
-
- play_arrow Manage Automation Scripts
- play_arrow Store and Enable Scripts
- play_arrow Configure a Remote Source for Scripts
- play_arrow Configure the Session Protocol for Scripts
- play_arrow Control Execution of Scripts
- play_arrow Synchronize Scripts Between Routing Engines
- play_arrow Convert Scripts Between SLAX and XSLT
-
- play_arrow Op Scripts
- play_arrow Op Scripts Overview
- play_arrow Create and Execute Op Scripts
- Required Boilerplate for Op Scripts
- Map Operational Mode Commands and Output Fields to Junos XML Notation
- How to Use RPCs and Operational Mode Commands in Op Scripts
- Declare and Use Command-Line Arguments in Op Scripts
- Configure Help Text for Op Scripts
- Define Operational Mode Commands to Allow in an Op Script
- Enable an Op Script and Define a Script Alias
- Configure Checksum Hashes for an Op Script
- Execute an Op Script on the Local Device
- Execute an Op Script from a Remote Site
- Disable an Op Script
- play_arrow Op Script Examples
- Change the Configuration Using SLAX and XSLT Scripts
- Example: Change the Configuration Using SLAX and XSLT Op Scripts
- Example: Change the Configuration Using Python Op Scripts
- Example: Customize Output of the show interfaces terse Command Using an Op Script
- Example: Display DNS Hostname Information Using an Op Script
- Example: Find LSPs to Multiple Destinations Using an Op Script
- Example: Restart an FPC Using an Op Script
- Example: Export Files Using an Op Script
- Example: Import Files Using an Op Script
- Example: Search Files Using an Op Script
- play_arrow Provision Services Using Service Template Automation
- play_arrow Troubleshoot Op Scripts
-
- play_arrow Event Policies and Event Scripts
- play_arrow Event Policy Overview
- play_arrow Event Policy Triggers
- Use Correlated Events to Trigger an Event Policy
- Trigger an Event Policy Based on Event Count
- Example: Trigger an Event Policy Based on Event Count
- Use Regular Expressions to Refine the Set of Events That Trigger a Policy
- Example: Controlling Event Policy Using a Regular Expression
- Generate Internal Events to Trigger Event Policies
- Use Nonstandard System Log Messages to Trigger Event Policies
- Junos Logger Utility
- play_arrow Event Policy Actions
- Configure an Event Policy to Execute Operational Mode Commands
- Configure an Event Policy to Change the Configuration
- Example: Changing the Configuration Using an Event Policy
- Example: Changing the Interface Configuration in Response to an Event
- Execute Event Scripts in an Event Policy
- Change the Configuration Using an Event Script
- Configuring an Event Policy to Pass Arguments to an Event Script
- Configure Event Policies to Ignore an Event
- Example: Ignore Events Based on Receipt of Other Events
- Overview of Using Event Policies to Raise SNMP Traps
- Example: Raise an SNMP Trap in Response to an Event
- Understanding the Event System Log Priority in an Event Policy
- Example: Configuring the Event System Log Priority in an Event Policy
- Example: Limit Event Script Output Based on a Specific Event Type
- play_arrow Configure Event Policy File Archiving
- play_arrow Configure Event Policy Privileges
- play_arrow Event Scripts Overview
- play_arrow Create and Execute Event Scripts
- play_arrow Troubleshoot Event Policies and Event Scripts
-
- play_arrow SNMP Scripts
- play_arrow SNMP Scripts Overview
- play_arrow Create and Execute SNMP Scripts
- play_arrow SNMP Script Example
- play_arrow Troubleshoot SNMP Scripts
-
- play_arrow Configuration Statements and Operational Commands
Generate a Persistent or Transient Configuration Change in SLAX and XSLT Commit Scripts
Junos OS commit scripts enforce custom configuration rules and can automatically change the configuration when it does not comply with your custom configuration rules. To generate a persistent change or transient change in Extensible Stylesheet Language Transformations (XSLT) or Stylesheet Language Alternative syntaX (SLAX) commit scripts:
At the start of the script, include the XSLT or SLAX commit script boilerplate from Required Boilerplate for Commit Scripts.
XSLT BoilerplateSLAX Boilerplatecontent_copy zoom_out_map<?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"> <!-- ... insert your code here ... --> </xsl:template> </xsl:stylesheet>
content_copy zoom_out_mapversion 1.2; 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 { /* * insert your code here */ }
At the position indicated by the comment “insert your code here,” include one or more XSLT programming instructions or their SLAX equivalents. Commonly used XSLT constructs include the following:
<xsl:choose> <xsl:when> <xsl:otherwise>
—Conditional construct that causes different instructions to be processed in different circumstances. The<xsl:choose>
instruction contains one or more<xsl:when>
elements, each of which tests an XPath expression. If the test evaluates as true, the XSLT processor executes the instructions in the<xsl:when>
element. The XSLT processor processes only the instructions contained in the first<xsl:when>
element whosetest
attribute evaluates as true. If none of the<xsl:when>
elements’test
attributes evaluate as true, the content of the<xsl:otherwise>
element, if present, is processed.<xsl:for-each select="xpath-expression">
—Programming instruction that tells the XSLT processor to gather together a set of nodes and process them one by one. The nodes are selected by the XPath expression in theselect
attribute. Each of the nodes is then processed according to the instructions contained in the<xsl:for-each>
instruction. Code inside an<xsl:for-each>
instruction is evaluated recursively for each node that matches the XPath expression. The context is moved to the node during each pass.<xsl:if test="xpath-expression">
—Conditional construct that causes instructions to be processed if the XPath expression in thetest
attribute evaluates totrue
.
For example, the following XSLT programming instructions select each SONET/SDH interface that does not have the MPLS protocol family enabled:
content_copy zoom_out_map<xsl:for-each select="interfaces/interface[starts-with(name, 'so-')]/unit"> <xsl:if test="not(family/mpls)">
In SLAX, the equivalent
for-each
andif
constructs are:content_copy zoom_out_mapfor-each (interfaces/interface[starts-with(name, 'so-')]/unit) { if (not(family/mpls)) {
For more information about how to use programming instructions, including examples and pseudocode, see XSLT Programming Instructions Overview. For information about writing scripts in SLAX instead of XSLT, see SLAX Overview.
Include instructions for changing the configuration.
There are two ways to generate a persistent change and two ways to generate a transient change:
To generate a persistent change, you can either reference the
jcs:emit-change
template or include a<change>
element.To generate a transient change, you can either reference the
jcs:emit-change
template and pass in thetag
parameter with'transient-change'
selected or include a<transient-change>
element.
The
jcs:emit-change
template allows for more efficient, less error-prone scripting because you can define the content of the change without specifying the complete XML hierarchy for the affected statement. Instead, the XML hierarchy is defined in the XPath expression contained in the script’s programming instruction.Consider the following examples. Both of the persistent change examples have the same result, even though they place the
Persistent Change Generated with the jcs:emit-change Templateunit
statement in different locations in the<xsl:for-each>
and<xsl:if>
programming instructions. In both cases, the script searches for SONET/SDH interfaces that do not have the MPLS protocol family enabled, adds thefamily mpls
statement at the[edit interfaces so-fpc/pic/port unit logical-unit-number]
hierarchy level, and emits a warning message stating that the configuration has been changed. Likewise, both of the transient change examples have the same result. They both set Point-to-Point Protocol (PPP) encapsulation on all SONET/SDH interface that have IP version 4 (IPv4) enabled.In this example, the content of the persistent change (contained in the
content
parameter) is specified without including the complete XML hierarchy. Instead, the XPath expression in the<xsl:for-each>
programming instruction sets the context for the change.The message parameter is also included. This parameter causes the
jcs:emit-change
template to call the<xnm:warning>
template, which sends a warning notification to the CLI. The message parameter automatically includes the current hierarchy information in the warning message.Persistent Change Generated with the <change> Elementcontent_copy zoom_out_map<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="content"> <family> <mpls/> </family> </xsl:with-param> <xsl:with-param name="message"> <xsl:text>Adding 'family mpls' to SONET interface.</xsl:text> </xsl:with-param> </xsl:call-template> </xsl:if> </xsl:for-each>
In this example, the complete XML hierarchy leading to the affected statement must be included as child elements of the
<change>
element.This example includes the current hierarchy information in the warning message by referencing the
jcs:edit-path
andjcs:statement
templates.Transient Change Generated with the jcs:emit-change Templatecontent_copy zoom_out_map<xsl:for-each select="interfaces/interface[starts-with(name, 'so-')]"> <xsl:if test="not(unit/family/mpls)"> <change> <interfaces> <interface> <name><xsl:value-of select="name"/></name> <unit> <name><xsl:value-of select="unit/name"/></name> <family> <mpls/> </family> </unit> </interface> </interfaces> </change> <xnm:warning> <xsl:call-template name="jcs:edit-path"/> <xsl:call-template name="jcs:statement"> <xsl:with-param name="dot" select="unit/name"/> </xsl:call-template> <message>Adding 'family mpls' to SONET interface.</message> </xnm:warning> </xsl:if> </xsl:for-each>
In this example, the content of the transient change (contained in the
content
parameter) is specified without including the complete XML hierarchy. Instead, the XPath expression in the<xsl:for-each>
programming instruction sets the context of the change. Theand
operator in the XPath expression means both operands must betrue
when converted to Booleans; the second operand is not evaluated if the first operand isfalse
.The tag parameter is included with '
transient-change
' selected. Without thetag
parameter, thejcs:emit-change
template generates a persistent change by default.Transient Change Generated with the <transient-change> Elementcontent_copy zoom_out_map<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>
In this example, the complete XML hierarchy leading to the affected statement must be included as child elements of the
<transient-change>
element.content_copy zoom_out_map<xsl:for-each select="interfaces/interface[starts-with(name, 'so-')\ and unit/family/inet]"> <transient-change> <interfaces> <interface> <name><xsl:value-of select="name"/></name> <encapsulation>ppp</encapsulation> </interface> </interfaces> </transient-change> </xsl:for-each>
Save the script with a meaningful name.
Copy the script to either the /var/db/scripts/commit directory on the device hard disk or the /config/scripts/commit directory on the flash drive. For information about setting the storage location for commit scripts, see Store Scripts in Flash Memory.
If the device has dual Routing Engines and you want the script to take effect on both of them, you must copy the script to both Routing Engines. The
commit synchronize
command does not copy scripts between Routing Engines.Enable the script by including the
file filename
statement at the[edit system scripts commit]
hierarchy level.content_copy zoom_out_map[edit system scripts commit] user@host# set file filename
If the script generates transient changes, configure the
allow-transients
statement.Configure the statement at the
[edit system scripts commit]
hierarchy level to enable all commit scripts to make transient changes.content_copy zoom_out_map[edit system scripts commit] user@host# set allow-transients
Alternatively, on supported devices and releases, configure the statement at the
[edit system scripts commit file filename]
hierarchy level to enable only the individual script to make transient changes.content_copy zoom_out_map[edit system scripts commit] user@host# set file filename allow-transients
Commit the configuration.
content_copy zoom_out_map[edit system scripts commit] user@host# commit
If all the commit scripts run without errors, any persistent changes are loaded into the candidate configuration. Any transient changes are loaded into the checkout configuration, but not to the candidate configuration. The commit process then continues by validating the configuration and propagating changes to the affected processes on the device.
To display the configuration with both persistent and
transient changes applied, issue the show | display commit-scripts
configuration mode command.
[edit] user@host# show | display commit-scripts
To display the configuration with only persistent changes
applied, issue the show | display commit-scripts no-transients
configuration mode command.
[edit] user@host# show | display commit-scripts no-transients
Persistent and transient changes are loaded into the configuration
in the same manner that the load replace
configuration
mode command loads an incoming configuration. When generating a persistent
or transient change, adding the replace="replace"
attribute to a configuration element produces the same behavior
as a replace:
tag in a load replace
operation. Both persistent and transient changes are loaded into
the configuration with the load replace
behavior. However,
persistent changes are loaded into the candidate configuration, and
transient changes are loaded into the checkout configuration.