Using an OP script, it is possible to load an XML formatted configuration from the command line (CLI) mode in JUNOS. This script could be used for loading XML format configuration that is saved from NSM.
The information below explains how to load XML configuration in CLI mode on JUNOS using an OP script.
lab# show | no-more | save /config/db/scripts/op/test.xml | display xml Wrote 191 lines of output to '/config/db/scripts/op/test.xml' root@:RE:0% cd /config/db/scripts/op root@:RE:0% more test.xml <configuration junos:changed-seconds="1299828253" junos:changed-localtime="2011-03-11 07:24:13 UTC"> <version> 10.3R1.9 <system> <root-authentication> <encrypted-password> $ABC123 <login> <user> <name> lab <uid> 2000 <class> super-user <authentication> <encrypted-password> $ABC123 <services> <ftp> <ssh> <telnet> <netconf> <ssh> ------------------------------omission---------------------------
lab> start shell % su - Password: root@:RE:0% cd /config/db/scripts/op/ root@:RE:0% vi load-configration.slax
Copy and paste blow context in vi editor
*OP script file i,e, load-configration.slax /* * Loads the text configuration stored in <file> using the <action> specified. * * file = full pathname for file * action = [merge], override, replace, update * format = [ascii] or xml */ 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"; /* Command-line arguments */ var $arguments = { <argument> { <name> "filename"; <description> "The configuration file to load, including the full path."; } <argument> { <name> "action"; <description> "Load action: merge, override, replace, update"; } <argument> { <name> "format"; <description> "Either ascii or xml format"; } } param $filename; param $action = "merge"; param $format = "ascii"; match / { <op-script-results> { if( string-length( $filename ) == 0 ) { <xsl:message terminate="yes"> "Configuration file must be specified."; } /* Lock the configuration */ var $connection = jcs:open(); var $lock-results = jcs:execute( $connection, "lock-configuration" ); if( jcs:empty( $lock-results/..//xnm:error ) ) { var $load-rpc = <load-configuration url=$filename action=$action format=$format> ; var $load-results = jcs:execute( $connection, $load-rpc ); if( jcs:empty( $load-results/..//xnm:error ) ) { var $commit-results = jcs:execute( $connection, "commit-configuration" ); copy-of $commit-results; var $unlock-results = jcs:execute( $connection, "unlock-configuration" ); copy-of $unlock-results; } else { copy-of $load-results; /* Don't leave it locked because the load failed */ var $unlock-results = jcs:execute( $connection, "unlock-configuration" ); copy-of $unlock-results; } } else { copy-of $lock-results; } expr jcs:close( $connection ); } }
root@EX4200:RE:0% cd /config/db/scripts/op root@EX4200:RE:0% ls test.xml stats-temp load-configuration.slax temp.slax
lab@EX4200# show system root-authentication { encrypted-password "$ABC123"; ## SECRET-DATA } scripts { op { file load-configuration.slax; } } login { user lab { uid 2001; class super-user; authentication { encrypted-password "$ABC123"; ## SECRET-DATA } } }
lab@EX4200> op load-configuration ? Possible completions: <[Enter]> Execute this command <name> Argument name action Load action: merge, override, replace, update detail Display detailed output filename The configuration file to load, including the full path. format Either ascii or xml format | Pipe through a command {master:0} lab@EX4200>op load-configuration filename /config/db/scripts/op/test.xml format xml action merge configuration check succeeds commit complete