Hi zhiang, I wrote a script that retrieves the interfaces and routing-options configuration from an XML configuration file, and changes the configuration, loading the content of the file. Probably you can do the same with the plain text configuration file, but I found it simpler to go with XML.
In any case, backing up the configuration in XML should not be a problem (you can follow the method descripted in here, adding the "| display xml" to the show command).
So here it is the script code:
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 / {
<op-script-results> {
/* Load the configuration file into script */
var $read_configuration = document("/var/tmp/XML_CONFIG.xml");
/* Retrieve interfaces hierarchy */
var $interfaces = $read_configuration//interfaces;
/* Retrieve routing-options hierarchy */
var $routing-options = $read_configuration//routing-options;
/* Create configuration change variable */
var $configuration = <configuration> {
copy-of $interfaces;
copy-of $routing-options;
}
/* Open the connection */
var $connection = jcs:open();
expr jcs:output( "Junoscript commit" );
var $results := { call jcs:load-configuration( $connection, $configuration ); }
/* Check for errors – report them if they occurred */
if( $results//xnm:error ) {
for-each( $results//xnm:error ) {
<output> message;
}
} else {
expr jcs:output( "Junoscript commit complete" );
}
/* The connection is closed */
var $close-results = jcs:close($connection);
}
}
The load behavior is the default one (a merge), but you can use load merge, load replace, load override, or load update as well, as described in the book Junos Automation Reference for Slax 1.0.
Let me know if it works for you!
Cheers,
Mattia