Supported Platforms
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- Example: Changing the Configuration Using an Op Script
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- close() Function (jcs Namespace)
- open() Function (jcs Namespace)
- ACX, EX, M, MX, SRX, T Series
- Junos Named Templates in the jcs Namespace Summary
- SLAX Operators
jcs:load-configuration Template
XSLT Syntax
<xsl:call-template name="jcs:load-configuration"> <xsl:with-param name="action" select="(merge | override | replace)"/> <xsl:with-param name="commit-options" select="node-set"/> <xsl:with-param name="configuration" select="configuration-data"/> <xsl:with-param name="connection" select="connection-handle"/> <xsl:with-param name="rollback" select="number"/> </xsl:call-template>
SLAX Syntax
call jcs:load-configuration($action="(merge | override | replace)", $commit-options=node-set, $configuration=configuration-data, $connection=connection-handle, $rollback=number);
Description
Make structured changes to the Junos OS configuration using an op script. When called, the template locks the configuration database, loads the configuration changes, commits the configuration, and then unlocks the configuration database.
The jcs:load-configuration template makes changes to the configuration in configure exclusive mode. In this mode, Junos OS locks the candidate global configuration for as long as the script accesses the shared database and makes changes to the configuration without interference from other users.
If another user is currently editing the configuration in configure exclusive mode or if the database is already locked when the template is called, the call fails. In addition, if there are existing, uncommitted changes to the configuration when the template is called, the commit will fail. If the template call is successful but the commit fails, Junos OS discards the uncommitted changes and rolls back the configuration.
Parameters
action | — | Specifies how to load the configuration changes with respect to the candidate configuration. The following options are supported:
|
commit-options | — | Node set defining options that customize the commit command. The default value is null. Supported commit options are:
|
configuration | — | XML configuration changes. The configuration changes are incorporated into the candidate configuration as specified by the action parameter. Starting with Junos OS Release 12.2, you can also supply a NULL configuration. If the configuration data value is NULL, the template performs a simple commit of the candidate configuration. |
connection | — | Connection handle generated by a call to the jcs:open() function. |
rollback | — | Return to a previously committed configuration. Specify the rollback number of the configuration, and the configuration you specify is loaded from the associated file. The software saves the last 50 committed configurations. The rollback parameter is available starting with Junos OS Release 12.2. |
Usage Examples
The following example calls the jcs:load-configuration template to modify the configuration to disable an interface. The interface name is supplied by the user and stored in the variable interface-name. All of the values required for the jcs:load-configuration template are defined as variables, which are then passed into the template as arguments.
In this example, the configuration data that includes the changes to the configuration are stored in the variable disable. This is the value used for the configuration parameter of the jcs:load-configuration template. The load-action variable is initialized to merge, which merges the configuration changes in the disable variable with the candidate configuration. This is the equivalent of the CLI configuration mode command load merge.
The options variable uses the := operator to create a node-set, which is passed to the template as the value of the commit-options parameter. This example uses the synchronize commit option . If the commit succeeds, it will commit the configuration changes on both Routing Engines. The log tag is also included to add the description of the commit to the commit log file for future reference.
The call to the jcs:open() function opens a connection with the Junos OS management process (mgd) and returns a connection handle that is stored in the conn variable. All of the defined variables are passed as arguments to the jcs:load-configuration template at the time that it is called.
SLAX syntax:
var $disable = { <configuration> { <interfaces> { <interface> { <name> $interface-name; <disable>; } } } } var $load-action = "merge"; var $options := { <commit-options> { <synchronize>; <log> "disabling interface on both routing engines"; } var $conn = jcs:open(); var $disable-results := { call jcs:load-configuration($action=$load-action, $commit-options=$options, $configuration = $disable, $connection = $conn); } if ($disable-results//xnm:error) { for-each ($disable-results//xnm:error) { <output> message; } } var $close-results = jcs:close($conn);
The := operator copies the results of the jcs:load-configuration template call to a temporary variable and runs the node-set function on that variable. The := operator ensures that the disable-results variable is a node-set rather than a result tree fragment so that the script can access the contents. The if code block is included to output any error messages that may indicate a problem in committing the configuration. The jcs:close function closes the connection.
In XSLT, the code corresponding to the SLAX call to jcs:load-configuration template is:
<xsl:variable name="disable-results-temp"> <xsl:call-template name="jcs:load-configuration"> <xsl:with-param name="action" select="$load-action"/> <xsl:with-param name="commit-options" select="$options"/> <xsl:with-param name="configuration" select="$disable"/> <xsl:with-param name="connection" select="$conn"/> </xsl:call-template> </xsl:variable> <xsl:variable xmlns ext="http:xmlsoft.org/XSLT/namespace" \ name="disable-results" select="ext:node-set($disable-results-temp)"/>
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- Example: Changing the Configuration Using an Op Script
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- close() Function (jcs Namespace)
- open() Function (jcs Namespace)
- ACX, EX, M, MX, SRX, T Series
- Junos Named Templates in the jcs Namespace Summary
- SLAX Operators
Published: 2013-07-26
Supported Platforms
Related Documentation
- ACX, EX, M, MX, PTX, SRX, T Series
- Example: Changing the Configuration Using an Op Script
- Junos Script Automation: Named Templates in the jcs Namespace Overview
- close() Function (jcs Namespace)
- open() Function (jcs Namespace)
- ACX, EX, M, MX, SRX, T Series
- Junos Named Templates in the jcs Namespace Summary
- SLAX Operators