GitHub Links
The source code below is also available from GitHub at the following locations:
SLAX Script Contents
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";
ns ext = "http://xmlsoft.org/XSLT/namespace";
import "../import/junos.xsl";
/*
* This commit-script ensures that all interfaces configured
* under protocols/ospf have family/mpls configured and are
* in protocols/mpls, protocols/ldp and protocols/rsvp.
*/
match configuration {
var $ospfIntsRaw = { call ospfInterfaces(); }
var $ospfInts = ext:node-set($ospfIntsRaw);
var $rsvpIntsRaw = { call rsvpInterfaces(); }
var $rsvpInts = ext:node-set($rsvpIntsRaw);
var $ldpIntsRaw = { call ldpInterfaces(); }
var $ldpInts = ext:node-set($ldpIntsRaw);
var $mplsIntsRaw = { call mplsInterfaces(); }
var $mplsInts = ext:node-set($mplsIntsRaw);
for-each (interfaces/interface) {
var $int = name;
var $unit = unit/name;
var $fullint = $int _ "." _ $unit;
var $ospf = $ospfInts/ospfInts[@name == $fullint]/@value;
var $rsvp = $rsvpInts/rsvpInts[@name == $fullint]/@value;
var $mpls = $mplsInts/mplsInts[@name == $fullint]/@value;
var $ldp = $ldpInts/ldpInts[@name == $fullint]/@value;
if ($ospf == 1) {
var $intMpls = count (unit/family/mpls);
if (not ($intMpls == 1) && (not (contains ($int, "lo0")))) {
<xnm:warning> {
<message> {
expr "OSPF interface ";
expr $int;
expr ".";
expr $unit;
expr " is not configured for MPLS";
}
}
}
if (not ($mpls == 1)) {
<xnm:warning> {
<message> {
expr "OSPF interface ";
expr $int;
expr ".";
expr $unit;
expr " is not configured under protocols MPLS";
}
}
}
if (not ($ldp == 1)) {
<xnm:warning> {
<message> {
expr "OSPF interface ";
expr $int;
expr ".";
expr $unit;
expr " is not configured under protocols LDP";
}
}
}
if (not ($rsvp == 1)) {
<xnm:warning> {
<message> {
expr "OSPF interface ";
expr $int;
expr ".";
expr $unit;
expr " is not configured under protocols RSVP";
}
}
}
}
}
}
template ospfInterfaces () {
for-each (protocols/ospf/area/interface) {
var $int = name;
<ospfInts name=$int value=1>;
}
}
template rsvpInterfaces () {
for-each (protocols/rsvp/interface) {
var $int = name;
<rsvpInts name=$int value=1>;
}
}
template ldpInterfaces () {
for-each (protocols/ldp/interface) {
var $int = name;
<ldpInts name=$int value=1>;
}
}
template mplsInterfaces () {
for-each (protocols/mpls/interface) {
var $int = name;
<mplsInts name=$int value=1>;
}
}
XML Script Contents
<?xml version="1.0"?>
<script>
<title>ospf-interfaces.slax</title>
<author>jpanagos</author>
<synopsis>
Ensure consistent configuration for OSPF protocol and interfaces
</synopsis>
<coe>commit</coe>
<type>interfaces</type>
<description>
This commit-script ensures that all interfaces configured under protocols/ospf have family/mpls configured and are in protocols/mpls, protocols/ldp and protocols/rsvp
</description>
<xhtml:script xmlns:xhtml="http://www.w3.org/1999/xhtml"
src="../../../../../web/leaf.js"
type="text/javascript"/>
</script>