Replace Elements in Configuration Data Using the Junos XML Protocol
A Junos XML protocol client application can use the
<load-configuration> operation with the replace
action to replace individual configuration elements, including hierarchy levels or
configuration objects.
A Junos XML protocol client application can replace individual configuration elements
(hierarchy levels or configuration objects) on a device running Junos OS or a device
running Junos OS Evolved. To replace individual elements, a client application emits
the <load-configuration> element with the
action="replace" attribute in an <rpc>
element.
<rpc>
<!-- For a file -->
<load-configuration action="replace" url="file" [format=("xml"|"text")]/>
<!-- For a data stream -->
<load-configuration action="replace" [format=("xml"|"text")]>
<!-- configuration data -->
</load-configuration>
</rpc>Starting in Junos OS Release 18.1R1, the ephemeral configuration database
supports loading configuration data using the
<load-configuration>
action attribute values of override and
replace in addition to the previously supported values of
merge and set.
Junos OS does not support using the replace operation when loading JSON configuration data. To replace configuration elements when using JSON, you must delete the existing element and then add the replacement element.
To perform replace operations, a client application must load configuration data as Junos XML elements or formatted ASCII text. The configuration data must specify which objects to replace. The following sections discuss how to replace configuration elements using the different formats.
Junos XML
To use Junos XML elements to define the data to replace, the application first
includes the basic tag elements described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. The application includes the replace="replace" attribute in
the opening container tag of the object to replace. Within the container tag,
the application includes the same child tag elements as for a new element: each
of the replacement’s identifier tag elements (if it has them) and all child tag
elements being defined for the replacement element.
In the following example, the application replaces the object that has the
replace="replace" attribute and the identifier specified in
the <name> element.
<configuration>
<!-- opening tag for each parent of the element -->
<container-tag replace="replace">
<name>identifier</name>
<!-- tag elements for other children, if any -->
</container-tag>
<!-- closing tag for each parent of the element -->
</configuration>The following example replaces the configuration for the admin
class at the [edit system login class] hierarchy level. The
configuration data uses Junos XML-tagged format (the default).
<rpc>
<load-configuration action="replace">
<configuration>
<system>
<login>
<class replace="replace">
<name>admin</name>
<permissions>configure</permissions>
<permissions>admin</permissions>
<permissions>admin-control</permissions>
</class>
</login>
</system>
</configuration>
</load-configuration>
</rpc>Formatted ASCII Text
To use formatted ASCII text to replace the element, the application first
includes the complete statement path described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. For the replacement element, the application includes each of the
replacement’s identifiers (if it has them) and all child statements (with values
if appropriate) that it is defining. The request includes the
replace: statement on the line that just precedes the
element’s container statement. 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 */
replace:
element identifier {
/* child statements if any */
}
/* closing braces for parent levels of the element */
</configuration-text>The following example uses formatted ASCII text to replace the configuration for
the admin class at the
[edit system login class] hierarchy level.
<rpc>
<load-configuration action="replace" format="text">
<configuration-text>
system {
login {
replace:
class admin {
permissions [configure admin admin-control]
}
}
}
</configuration-text>
</load-configuration>
</rpc>Change History Table
Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.
<load-configuration> action attribute values of override and replace in
addition to the previously supported values of merge and set.