- 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
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.
1 <?xml version="1.0"?> 2 <xsl:stylesheet version="1.0" 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 4 xmlns:junos="http://xml.juniper.net/junos/*/junos" 5 xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" 6 xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> 7 <xsl:import href="../import/junos.xsl"/> 8 <xsl:template match="configuration"> 9 <xsl:for-each select="interfaces/interface[starts-with(name, 'so-') \ and unit/family/inet]"> 10 <transient-change> 11 <interfaces> 12 <interface> 13 <name><xsl:value-of select="name"/></name> 14 <encapsulation>ppp</encapsulation> 15 </interface> 16 </interfaces> 17 </transient-change> 18 </xsl:for-each> 19 </xsl:template> 20 </xsl:stylesheet>
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.)
9 <xsl:for-each select="interfaces/interface[starts-with(name, 'so-') \ and unit/family/inet]">
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>
.
10 <transient-change>
Lines 11 through 16 represent the content of the transient change.
The encapsulation is set to ppp
.
11 <interfaces> 12 <interface> 13 <name><xsl:value-of select="name"/></name> 14 <encapsulation>ppp</encapsulation> 15 </interface> 16 </interfaces>
Lines 17 through 19 close all open tags in this template.
17 </transient-change> 18 </xsl:for-each> 19 </xsl:template>
Line 20 closes the style sheet and the commit script.
20 </xsl:stylesheet>
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: Control IS-IS and MPLS Interfaces.
1 <?xml version="1.0"?> 2 <xsl:stylesheet version="1.0" 3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 4 xmlns:junos="http://xml.juniper.net/junos/*/junos" 5 xmlns:xnm="http://xml.juniper.net/xnm/1.1/xnm" 6 xmlns:jcs="http://xml.juniper.net/junos/commit-scripts/1.0"> 7 <xsl:import href="../import/junos.xsl"/> 8 <xsl:template match="configuration"> 9 <xsl:variable name="mpls" select="protocols/mpls"/> 10 <xsl:for-each select="interfaces/interface/unit[family/iso]"> 11 <xsl:variable name="ifname" select="concat(../name, '.', name)"/> 12 <xsl:if test="not(family/mpls)"> 13 <xsl:call-template name="jcs:emit-change"> 14 <xsl:with-param name="message"> 15 <xsl:text> 16 Adding 'family mpls' to ISO-enabled interface 17 </xsl:text> 18 </xsl:with-param> 19 <xsl:with-param name="content"> 20 <family> 21 <mpls/> 22 </family> 23 </xsl:with-param> 24 </xsl:call-template> 25 </xsl:if> 26 <xsl:if test="$mpls and not($mpls/interface[name = $ifname])"> 27 <xsl:call-template name="jcs:emit-change"> 28 <xsl:with-param name="message"> 29 <xsl:text>Adding ISO-enabled interface </xsl:text> 30 <xsl:value-of select="$ifname"/> 31 <xsl:text> to [protocols mpls]</xsl:text> 32 </xsl:with-param> 33 <xsl:with-param name="dot" select="$mpls"/> 34 <xsl:with-param name="content"> 35 <interface> 36 <name> 37 <xsl:value-of select="$ifname"/> 38 </name> 39 </interface> 40 </xsl:with-param> 41 </xsl:call-template> 42 </xsl:if> 43 </xsl:for-each> 44 </xsl:template> 45 </xsl:stylesheet>
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.
9 <xsl:variable name="mpls" select="protocols/mpls"/>
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.
10 <xsl:for-each select="interfaces/interface/unit[family/iso]">
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.
11 <xsl:variable name="ifname" select="concat(../name, '.', name)"/>
Line 12 evaluates as true for each ISO-enabled interface that does not have MPLS enabled.
12 <xsl:if test="not(family/mpls)">
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).
13 <xsl:call-template name="jcs:emit-change">
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.
14 <xsl:with-param name="message"> 15 <xsl:text> 16 Adding 'family mpls' to ISO-enabled interface 17 </xsl:text> 18 </xsl:with-param>
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.
19 <xsl:with-param name="content"> 20 <family> 21 <mpls/> 22 </family> 23 </xsl:with-param>
Lines 24 and 25 close the tags opened in Lines 13 and 12, respectively.
24 </xsl:call-template> 25 </xsl:if>
Line 26 tests whether MPLS is already enabled and if this interface
is not configured at the [edit protocols mpls interface]
hierarchy level.
26 <xsl:if test="$mpls and not($mpls/interface[name = $ifname])">
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.
27 <xsl:call-template name="jcs:emit-change"> 28 <xsl:with-param name="message"> 29 <xsl:text>Adding ISO-enabled interface </xsl:text> 30 <xsl:value-of select="$ifname"/> 31 <xsl:text> to [edit protocols mpls]</xsl:text> 32 </xsl:with-param> 33 <xsl:with-param name="dot" select="$mpls"/> 34 <xsl:with-param name="content"> 35 <interface> 36 <name> 37 <xsl:value-of select="$ifname"/> 38 </name> 39 </interface> 40 </xsl:with-param> 41 </xsl:call-template>
Lines 42 through 45 close all open elements.
42 </xsl:if> 43 </xsl:for-each> 44 </xsl:template> 45 </xsl:stylesheet>