Looking better. Here are my thoughts...
The libslax docs can be somewhat terse. I recommend grabbing the following "This Week" docs from juniper online:
- "This Week: Junos Automation Reference for SLAX 1.0" by Curtis Call
- "This Week: Applying Junos Automation" by Curtis Call
The Junos Automation Reference doc has a much more detailed description of the import function (and all other SLAX operators, functions and templates. The Applying Automation guide has some really good, clear examples.
Use of templates in your example is close... but won't work like you have them.
Here's a notional file to import:
/* Your file ospfstuff.slax would look something like this: */
/* it would have the same "boilerplate" at top-of-file like any other, including
* you ns declarations, etc.
* then, just be a collection of your various "ospf" functions and templates.
*/
version 1.0;
/* standard namespace declarations */
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";
/* exslt, as needed */
ns func extension = "http://exslt.org/functions";
ns str = "http://exslt.org/strings";
ns date extension = "http://exslt.org/dates-and-times";
/* this library or others, as needed */
ns ospfstuff extension = "http://xml.juniper.net/ospfstuff";
/*
* End of boilerplate. Functions & templates from here on out...
*/
/*****************************************************************/
template ospfstuff:get-ospf-neighbor-information($con) {
var $rpc = <get-ospf-neighbor-information>;
var $res = jcs:execute($con,$rpc);
/*
* check $res/..//xnm:error and do the needful.
* if OK, then emit the XML RTF back to the caller.
*/
copy-of $res;
}
/*****************************************************************/
/*****************************************************************/
template ospfstuff:get-ospf-statistics-information($con) {
var $rpc = <get-ospf-statistics-information>;
var $res = jcs:execute($con,$rpc);
/*
* check $res/..//xnm:error and do the needful.
* if OK, then emit the XML RTF back to the caller.
*/
copy-of $res;
}
/*****************************************************************/
/*****************************************************************/
template ospfstuff:get-ospf-database-information($con) {
var $rpc = <get-ospf-database-information>;
var $res = jcs:execute($con,$rpc);
/*
* check $res/..//xnm:error and do the needful.
* if OK, then emit the XML RTF back to the caller.
*/
copy-of $res;
}
/*****************************************************************/
/*
* Etc, etc.
* Turtles all the way down.
*/
After you imported that into your "main", you could then do something like this in your "main" slax file...:
version 1.1; /* or version 1.0 if you prefer */
/*
* usual boilerplate and ns declarations go here
* This example probably has typoes in it. Good luck.
*/
import "../lib/ospfstuff.slax"
match / {
var $con = jcs:open();
/* check status */
/* build up xml nodeset containing ospf neighbor data */
var $ospf-nbr-info := { call ospfstuff:get-ospf-neighbor-information($con) };
/* build up xml nodeset containing ospf database data */
var $ospf-database-info := { call ospfstuff:get-ospf-database-information($con) };
/* etc */
/* Now have fun with the data we collected */
expr jcs:output("Neighbor is ", $ospf-nbr-info/ospf-neighbor/neighbor-address);
for-each ($ospf-database-info/ospf-database) {
expr jcs:output("LSA type: ", ./lsa-type, "\t LSA ID: ", ./lsa-id);
}
/* etc */
}
Does that clarify ?
/doug