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, so the application simply emits the <load-configuration>
tag element in an <rpc>
tag element:
<rpc> <!-- For a file --> <load-configuration url="file" [format="format"]/> <!-- For a data stream --> <load-configuration [format="format"]> <!-- configuration data --> </load-configuration> </rpc>
For more information about the url
and format
attributes, see Uploading and Formatting Configuration Data in a
Junos XML Protocol Session.
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 examples at the end of this section.
When using Junos XML tag elements to represent the element
to merge into the configuration, the application includes the basic
tag elements described in Creating, Modifying,
or Deleting Configuration Elements Using the Junos XML Protocol. It does not include any attributes in the element’s container
tag. If adding or changing the value of a child element, the application
includes the tag elements for it. If a child remains unchanged, it
does not need to be included in the loaded configuration. In the following,
the identifier tag element is called <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>
When using formatted ASCII text, the application includes the statement path described in Creating, Modifying, or Deleting Configuration Elements Using the Junos XML Protocol. It does not include a preceding operator, but does include the element’s identifier if it has one. If adding or changing the value of a child element, the application includes the tag elements for it. If a child remains unchanged, it does not need to be included in the loaded configuration.
<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>
Starting in Junos OS Release 16.1, you can load configuration data formatted using JavaScript Object Notation (JSON) on the device. When using JSON to represent the elements to merge into the configuration, the application includes the basic JSON data described in Creating, Modifying, or Deleting Configuration Elements Using the Junos XML Protocol. It does not need to include any specific operation attributes in the JSON configuration data in order to merge the new or changed element. If adding or changing the value of a child element, the application includes the JSON data or child objects for it. If a child remains unchanged, it does not need to be included in the loaded configuration. 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>
When using configuration mode commands to merge new elements,
the application includes the action="set"
and format="text"
attributes in the <load-configuration>
tag, as shown in the examples
at the end of this section. The application includes the set
command, the statement path to the element, and the element’s
identifier if it has one. If adding or changing the value of a child
element, the application includes the child elements or statements
in the command. If a child remains unchanged, it does not need to
be included.
<configuration-set> set statement-path-to-element element identifier child-statements </configuration-set>
The following example shows how to merge in a new interface
called so-3/0/0 at the [edit interfaces]
hierarchy
level in the configuration. The information is provided as Junos XML
tag elements (the default).
The following example shows how to use formatted ASCII text to define the same new interface.
The following example shows how to use JSON configuration data to define the same interface.
<rpc> <load-configuration format="json"> <configuration-json> { "configuration" : { "interfaces" : { "interface" : [ { "name" : "so-3/0/0", "unit" : [ { "name" : 0, "family" : { "inet" : { "address" : [ { "name" : "10.0.0.1/8" } ] } } } ] } ] } } } </configuration-json> </load-configuration> </rpc> <rpc-reply xmlns:junos="http://xml.juniper.net/junos/16.2R2/junos"> <load-configuration-results> <load-success/> </load-configuration-results> </rpc-reply>
The following example shows how to use configuration mode commands to define the same interface.