Example: Configure Dual Routing Engines
If your device has redundant (also called dual) Routing Engines, your Junos OS configuration can be complex. This example shows how you can use commit scripts to simplify and control the configuration of dual Routing Engine platforms.
Requirements
This example uses a device running Junos OS with dual Routing Engines.
Overview and Commit Script
Junos OS supports two special configuration groups: re0
and re1
. When these groups are applied using the apply-groups [ re0 re1 ]
statement, they take
effect if the Routing Engine name matches the group name. Statements
included at the [edit groups re0]
hierarchy level are inherited
only on the Routing Engine named RE0, and statements included at the [edit groups re1]
hierarchy level are inherited only on the
Routing Engine named RE1.
This example includes two commit scripts. The first script, dual-re.xsl, generates a warning if the system host-name
statement, any IP version 4 (IPv4) interface address, or the
fxp0 interface configuration is configured in the target configuration
instead of in a configuration group.
The second script, dual-re2.xsl, first checks whether the hostname configuration is configured and
then checks whether it is configured in a configuration group. The otherwise
construct generates an error message if the
hostname is not configured at all. The first when
construct allows the script to do nothing if the hostname is already
configured in a configuration group. The second when
construct takes effect when the hostname is configured in the target
configuration. In this case, the script generates a transient change that places the hostname configuration
into the re0
and re1
configuration groups, copies
the configured hostname into those groups, concatenates each group
hostname with -RE0
and -RE1
, and deactivates the hostname in the target configuration so the
configuration group hostnames can be inherited.
The example scripts are shown in both XSLT and SLAX syntax:
XSLT Syntax: dual-re.xsl Script
<?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:for-each select="system/host-name | interfaces/interface/unit/family/inet/address | interfaces/interface[name = 'fxp0']"> <xsl:if test="not(@junos:group) or not(starts-with(@junos:group, 're'))"> <xnm:warning> <xsl:call-template name="jcs:edit-path"> <xsl:with-param name="dot" select=".."/> </xsl:call-template> <xsl:call-template name="jcs:statement"/> <message> <xsl:text>statement should not be in target</xsl:text> <xsl:text> configuration on dual RE system</xsl:text> </message> </xnm:warning> </xsl:if> </xsl:for-each> </xsl:template> </xsl:stylesheet>
XSLT Syntax: dual-re2.xsl Script
<?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="hn" select="system/host-name"/> <xsl:choose> <xsl:when test="$hn/@junos:group"/> <xsl:when test="$hn"> <transient-change> <groups> <name>re0</name> <system> <host-name> <xsl:value-of select="concat($hn, '-RE0')"/> </host-name> </system> </groups> <groups> <name>re1</name> <system> <host-name> <xsl:value-of select="concat($hn, '-RE1')"/> </host-name> </system> </groups> <system> <host-name inactive="inactive"/> </system> </transient-change> </xsl:when> <xsl:otherwise> <xnm:error> <message>Missing [system host-name]</message> </xnm:error> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
SLAX Syntax: dual-re.xsl Script
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 { for-each (system/host-name | interfaces/interface/unit/family/inet/address | interfaces/interface[name = 'fxp0']) { if (not(@junos:group) or not(starts-with(@junos:group, 're'))) { <xnm:warning> { call jcs:edit-path($dot = ..); call jcs:statement(); <message> { expr "statement should not be in target"; expr " configuration on dual RE system"; } } } } }
SLAX Syntax: dual-re2.xsl Script
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 $hn = system/host-name; if ($hn/@junos:group) { } else if ($hn) { <transient-change> { <groups> { <name> "re0"; <system> { <host-name> $hn _ '-RE0'; } } <groups> { <name> "re1"; <system> { <host-name> $hn _ '-RE1'; } } <system> { <host-name inactive="inactive">; } } else { <xnm:error> { <message> "Missing [system host-name]"; } } } }
Configuration
Procedure
Step-by-Step Procedure
To download, enable, and run the scripts:
Copy the scripts into two text files, name the files dual-re.xsl and dual-re2.xsl or dual-re.slax and dual-re2.slax as appropriate, and copy them 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 filenames at the
[edit system scripts commit file]
hierarchy level to dual-re.slax and dual-re2.slax.groups { re0 { interfaces { fxp0 { unit 0 { family inet { address 10.0.0.1/24; } } } } } } apply-groups re0; system { host-name router1; scripts { commit { file dual-re.xsl; file dual-re2.xsl; } } } interfaces { fe-0/0/0 { unit 0 { family inet { address 192.168.220.1/30; } } } }
In configuration mode, issue the
load merge terminal
command to merge the stanzas into your device configuration.[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.
user@host# commit
Verification
Verifying the Commit Script Changes
Purpose
Verify that the script behaves as expected.
Action
Review the output of the commit
command. After
the commit operation completes, the device hostname is changed to
router1-RE0.
[edit] user@host# commit [edit system] 'host-name router1;' warning: statement should not be in target configuration on dual RE system [edit interfaces interface fe-0/0/0 unit 0 family inet] 'address 192.168.220.1/30;' warning: statement should not be in target configuration on dual RE system commit complete