- 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
Example: Create a Complex Configuration Based on a Simple Interface Configuration
This commit script example uses a macro to automatically expand a simple interface configuration.
Overview and Commit Script
This example uses a commit script and macro to automatically
expand a simple interface configuration by generating a transient change that assigns a default encapsulation
type, configures multiple routing protocols on the interface, and
applies multiple configuration groups. The Junos OS management (mgd)
process inspects the configuration, looking for apply-macro params
statements included at the [edit interfaces interface-name]
hierarchy level.
When the script finds an apply-macro params
statement, it performs the following actions:
Applies the
interface-details
configuration group to the interface.Includes the value of the
description
parameter at the[edit interfaces interface-name description]
hierarchy level.Includes the value of the
encapsulation
parameter at the[edit interfaces interface-name encapsulation]
hierarchy level. If theencapsulation
parameter is not included in theapply-macro params
statement, the script sets the encapsulation tocisco-hdlc
as the default.Sets the logical unit number to
0
and tests whether theinet-address
parameter is included in theapply-macro params
statement. If it is, the script includes the value of theinet-address
parameter at the[edit interfaces interface-name unit 0 family inet address]
hierarchy level.Includes the interface name at the
[edit protocols rsvp interface]
hierarchy level.Includes the
level 1 enable
andmetric
statements at the[edit protocols isis interface interface-name]
hierarchy level.Includes the
level 2 enable
andmetric
statements at the[edit protocols isis interface interface-name]
hierarchy level.Tests whether the
isis-level-1
orisis-level-1-metric
parameter is included in theapply-macro params
statement. If one or both of these parameters are included, the script includes thelevel 1
statement at the[edit protocols isis interface interface-name]
hierarchy level. If theisis-level-1
parameter is included, the script also includes the value of theisis-level-1
parameter (enable
ordisable
) at the[edit protocols isis interface interface-name level 1]
hierarchy level. If theisis-level-1-metric
parameter is included, the script also includes the value of theisis-level-1-metric
parameter at the[edit protocols isis interface interface-name level 1 metric]
hierarchy level.Tests whether the
isis-level-2
orisis-level-2-metric
parameter is included in theapply-macro params
statement. If one or both of these parameters are included, the script includes thelevel 2
statement at the[edit protocols isis interface interface-name]
hierarchy level. If theisis-level-2
parameter is included, the script also includes the value of theisis-level-2
parameter (enable
ordisable
) at the[edit protocols isis interface interface-name level 2]
hierarchy level. If theisis-level-2-metric
parameter is included, the script also includes the value of theisis-level-2-metric
parameter at the[edit protocols isis interface interface-name level 2 metric]
hierarchy level.Includes the interface name at the
[edit protocols ldp interface]
hierarchy level.
The example script is shown in both XSLT and SLAX syntax:
XSLT Syntax
<?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"> <xsl:variable name="top" select="."/> <xsl:for-each select="interfaces/interface/apply-macro[name = 'params']"> <xsl:variable name="description" select="data[name = 'description']/value"/> <xsl:variable name="inet-address" select="data[name = 'inet-address']/value"/> <xsl:variable name="encapsulation" select="data[name = 'encapsulation']/value"/> <xsl:variable name="isis-level-1" select="data[name = 'isis-level-1']/value"/> <xsl:variable name="isis-level-1-metric" select="data[name = 'isis-level-1-metric']/value"/> <xsl:variable name="isis-level-2" select="data[name = 'isis-level-2']/value"/> <xsl:variable name="isis-level-2-metric" select="data[name = 'isis-level-2-metric']/value"/> <xsl:variable name="ifname" select="concat(../name, '.0')"/> <transient-change> <interfaces> <interface> <name><xsl:value-of select="../name"/></name> <apply-groups> <name>interface-details</name> </apply-groups> <xsl:if test="$description"> <description> <xsl:value-of select="$description"/> </description> </xsl:if> <encapsulation> <xsl:choose> <xsl:when test="string-length($encapsulation) > 0"> <xsl:value-of select="$encapsulation"/> </xsl:when> <xsl:otherwise>cisco-hdlc</xsl:otherwise> </xsl:choose> </encapsulation> <unit> <name>0</name> <xsl:if test="string-length($inet-address) > 0"> <family> <inet> <address> <xsl:value-of select="$inet-address"/> </address> </inet> </family> </xsl:if> </unit> </interface> </interfaces> <protocols> <rsvp> <interface> <name><xsl:value-of select="$ifname"/></name> </interface> </rsvp> <isis> <interface> <name><xsl:value-of select="$ifname"/></name> <xsl:if test="$isis-level-1 or $isis-level-1-metric"> <level> <name>1</name> <xsl:if test="$isis-level-1"> <xsl:element name="{$isis-level-1}"/> </xsl:if> <xsl:if test="$isis-level-1-metric"> <metric> <xsl:value-of select="$isis-level-1-metric"/> </metric> </xsl:if> </level> </xsl:if> <xsl:if test="$isis-level-2 or $isis-level-2-metric"> <level> <name>2</name> <xsl:if test="$isis-level-2"> <xsl:element name="{$isis-level-2}"/> </xsl:if> <xsl:if test="$isis-level-2-metric"> <metric> <xsl:value-of select="$isis-level-2-metric"/> </metric> </xsl:if> </level> </xsl:if> </interface> </isis> <ldp> <interface> <name><xsl:value-of select="$ifname"/></name> </interface> </ldp> </protocols> </transient-change> </xsl:for-each> </xsl:template> </xsl:stylesheet>
SLAX Syntax
version 1.0; 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 { var $top = .; for-each (interfaces/interface/apply-macro[name = 'params']) { var $description = data[name = 'description']/value; var $inet-address = data[name = 'inet-address']/value; var $encapsulation = data[name = 'encapsulation']/value; var $isis-level-1 = data[name = 'isis-level-1']/value; var $isis-level-1-metric = data[name = 'isis-level-1-metric']/value; var $isis-level-2 = data[name = 'isis-level-2']/value; var $isis-level-2-metric = data[name = 'isis-level-2-metric']/value; var $ifname = ../name _ '.0'; <transient-change> { <interfaces> { <interface> { <name> ../name; <apply-groups> { <name> "interface-details"; } if ($description) { <description> $description; } <encapsulation> { if (string-length($encapsulation) > 0) { expr $encapsulation; } else { expr "cisco-hdlc"; } } <unit> { <name> "0"; if (string-length($inet-address) > 0) { <family> { <inet> { <address> $inet-address; } } } } } } <protocols> { <rsvp> { <interface> { <name> $ifname; } } <isis> { <interface> { <name> $ifname; if ($isis-level-1 or $isis-level-1-metric) { <level> { <name> "1"; if ($isis-level-1) { <xsl:element name="{$isis-level-1}">; } if ($isis-level-1-metric) { <metric> $isis-level-1-metric; } } } if ($isis-level-2 or $isis-level-2-metric) { <level> { <name> "2"; if ($isis-level-2) { <xsl:element name="{$isis-level-2}">; } if ($isis-level-2-metric) { <metric> $isis-level-2-metric; } } } } } <ldp> { <interface> { <name> $ifname; } } } } } }
Topology
Configuration
Procedure
Step-by-Step Procedure
To download, enable, and test the script:
Copy the script into a text file, name the file if-params.xsl or if-params.slax as appropriate, and copy it to the /var/db/scripts/commit/ directory on the device.
Select the following test configuration stanzas, and press Ctrl+c to copy them to the clipboard.
If you are using the SLAX version of the script, change the filename at the
[edit system scripts commit file]
hierarchy level to if-params.slax.content_copy zoom_out_mapsystem { scripts { commit { allow-transients; file if-params.xsl; } } } groups { interface-details { interfaces { <so-*/*/*> { clocking internal; } } } } interfaces { so-1/2/3 { apply-macro params { description "Link to Hoverville"; encapsulation ppp; inet-address 10.1.2.3/28; isis-level-1 enable; isis-level-1-metric 50; isis-level-2-metric 85; } } }
In configuration mode, issue the
load merge terminal
command to merge the stanzas into your device configuration.content_copy zoom_out_map[edit] user@host# load merge terminal [Type ^D at a new line to end input] ... Paste the contents of the clipboard here ...
At the prompt, paste the contents of the clipboard by using the mouse and the paste icon.
Press Enter.
Press Ctrl+d.
Commit the configuration.
content_copy zoom_out_mapuser@host# commit
Verification
Verifying the Configuration
Purpose
Verify that the script behaves as expected.
Action
Issue the show interfaces | display commit-scripts
| display inheritance
configuration mode command. The | display
commit-scripts
option displays all the statements that are in
the configuration, including statements that are generated by transient
changes. The | display inheritance
option displays
inherited configuration data and information about the source group
from which the configuration has been inherited. This option also
shows interface ranges configuration data in expanded format and information
about the source interface-range from which the configuration has
been expanded. You should see the following output:
[edit] user@host# show interfaces | display commit-scripts | display inheritance so-1/2/3 { apply-macro params { clocking internal; description "Link to Hoverville"; encapsulation ppp; inet-address 10.1.2.3/28; isis-level-1 enable; isis-level-1-metric 50; isis-level-2-metric 85; } description "Link to Hoverville"; ## ## 'internal' was inherited from group 'interface-details' ## clocking internal; encapsulation ppp; unit 0 { family inet { address 10.1.2.3/28; } } }
Issue the show protocols | display commit-scripts
configuration mode command. You should see the following output:
[edit] user@host# show protocols | display commit-scripts rsvp { interface so-1/2/3.0; } isis { interface so-1/2/3.0 { level 1 { enable; metric 50; } level 2 metric 85; } } ldp { interface so-1/2/3.0; }