Example: Configuring 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.
The 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, ex-dual-re.xsl, emits 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, ex-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 emits 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.
XSLT Syntax: ex-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: ex-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: ex-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: ex-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]";
}
}
}
}
Testing the ex-dual-re and ex-dual-re2 Scripts
To test the ex-dual-re and ex-dual-re2 scripts, perform the following steps:
- Copy the XSLT or SLAX scripts from Example: Configuring Dual Routing Engines into two text files, name the files
ex-dual-re.xslandex-dual-re2.xslorex-dual-re.slaxandex-dual-re2.slaxas appropriate, and copy them to the/var/db/scripts/commitdirectory on the device. Select the following 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 ex-dual-re.slax and ex-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 ex-dual-re.xsl;file ex-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 using the mouse and the paste icon.
- Press Enter.
- Press Ctrl+d.
Issue the commit command. The following output appears. 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
Hide Navigation Pane
Show Navigation Pane
Download
SHA1