Merge Elements in Configuration Data Using the Junos XML Protocol
By default, the Junos XML protocol server merges loaded configuration data into the candidate configuration according to the following rules. (The rules also apply to a private copy of the configuration or an open instance of the ephemeral configuration database, but for simplicity the following discussion refers to the candidate configuration only.)
-
A configuration element (hierarchy level or configuration object) that exists in the candidate but not in the loaded configuration remains unchanged.
-
A configuration element that exists in the loaded configuration but not in the candidate is added to the candidate.
-
If a configuration element exists in both configurations, the semantics are as follows:
-
If a child statement of the configuration element (represented by a child tag element) exists in the candidate but not in the loaded configuration, it remains unchanged.
-
If a child statement exists in the loaded configuration but not in the candidate, it is added to the candidate.
-
If a child statement exists in both configurations, the value in the loaded configuration replaces the value in the candidate.
-
Merge mode is the default mode for new configuration elements. To merge new
configuration data with the existing configuration, the application emits the
<load-configuration> operation in an
<rpc> element.
<rpc>
<!-- For a file -->
<load-configuration url="file" [format="format"]/>
<!-- For a data stream -->
<load-configuration [format="format"]>
<!-- configuration data -->
</load-configuration>
</rpc>To explicitly specify merge mode for configuration data that uses Junos XML elements,
formatted ASCII text, or JSON format, the application can include the
action="merge" attribute in the
<load-configuration> tag, as shown in the later
examples.
For more information about the url and format
attributes, see Upload and Format Configuration Data in a Junos XML Protocol Session.
The following sections outline how to merge configuration items into the existing configuration using the different formats:
Junos XML
To use Junos XML to merge the element into the configuration, the application
first includes the basic tag elements described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. The application does not include any attributes in the element’s container
tag. To add or change the value of a child element, the application includes the
elements for it. If a child remains unchanged, the loaded configuration does not
need to include it. In the following example, the identifier tag is
<name>:
<configuration>
<!-- opening tag for each parent of the element -->
<container-tag>
<name>identifier</name> <!-- if the element has an identifier -->
<!-- tag elements for other children, if any -->
</container-tag>
<!-- closing tag for each parent of the element -->
</configuration>The following example uses Junos XML elements (the default) to merge
configuration data for interface ge-0/0/1 at the
[edit interfaces] hierarchy level.
<rpc>
<load-configuration action="merge">
<configuration>
<interfaces>
<interface>
<name>ge-0/0/1</name>
<unit>
<name>0</name>
<family>
<inet>
<address>
<name>10.0.0.1/8</name>
</address>
</inet>
</family>
</unit>
</interface>
</interfaces>
</configuration>
</load-configuration>
</rpc>Formatted ASCII Text
To use formatted ASCII text to merge statements, the application first includes
the statement path described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. The application does not include a preceding operator, but it does include
the element’s identifier if it has one. To add or change the value of a child
element, the application includes the elements for it. If a child remains
unchanged, the loaded configuration does not need to include it. To provide the
configuration data as a data stream, enclose the data in a
<configuration-text> element.
<configuration-text>
/* statements for parent levels of the element */
element identifier {
/* child statements if any */
}
/* closing braces for parent levels of the element */
</configuration-text>The following example uses formatted ASCII text to merge the configuration data for interface ge-0/0/1.
<rpc>
<load-configuration action="merge" format="text">
<configuration-text>
interfaces {
ge-0/0/1 {
unit 0 {
family inet {
address 10.0.0.1/8;
}
}
}
}
</configuration-text>
</load-configuration>
</rpc>
Configuration Mode Commands
To use configuration mode commands to merge new elements, an application includes
the set command, the statement path to the element, and the
element’s identifier if it has one. To add or change the value of a child
element, the application includes the child elements or statements in the
command. If a child remains unchanged, the configuration mode commands do not
need to include it. To provide the configuration data as a data stream, enclose
the commands in a <configuration-set> element.
<configuration-set>
set statement-path-to-element element identifier child-statements
</configuration-set>To load configuration mode commands, the application includes the
action="set" and format="text" attributes in
the <load-configuration> tag. The following example uses
configuration mode commands to define the ge-0/0/1 interface.
<rpc>
<load-configuration action="set" format="text">
<configuration-set>
set interfaces ge-0/0/1 unit 0 family inet address 10.0.0.1/8
</configuration-set>
</load-configuration>
</rpc>
JSON
To use JSON data to merge elements into the configuration, an application first
includes the basic JSON data described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. The application does not need to include any specific operation attributes
in the JSON configuration data in order to merge the new or changed element. To
add or change the value of a child element, the application includes the JSON
data or child objects for it. If a child remains unchanged, the loaded
configuration does not need to include it. To provide the configuration data as
a data stream, enclose the data in a <configuration-json>
element.
In the following example, the JSON member that specifies the element’s identifier has the field name "name":
<configuration-json>
{
"configuration" : {
/* JSON objects for parent levels of the element */
"container-tag" : {
"object" : [
{
"name" : "identifier",
"statement-name" : "statement-value", # if any
/* additional data and child objects */ # if any
}
],
/* data and child objects */ # if any
}
/* closing braces for parent levels of the element */
}
}
</configuration-json> The following example uses JSON configuration data to define the ge-0/0/1 interface.
<rpc>
<load-configuration format="json">
<configuration-json>
{
"configuration" : {
"interfaces" : {
"interface" : [
{
"name" : "ge-0/0/1",
"unit" : [
{
"name" : 0,
"family" : {
"inet" : {
"address" : [
{
"name" : "10.0.0.1/8"
}
]
}
}
}
]
}
]
}
}
}
</configuration-json>
</load-configuration>
</rpc>