Delete Elements in Configuration Data Using the Junos XML Protocol
Junos XML protocol client applications can delete configuration elements from the selected configuration database on Junos devices.
Junos XML protocol client applications can delete configuration elements (hierarchy levels or configuration objects) from the candidate configuration or open configuration database on devices running Junos OS or devices running Junos OS Evolved. To delete elements, a client application first emits the basic tag elements described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. A client application then includes the appropriate attribute or operator for the chosen format.
Table 1 summarizes how a client application deletes configuration objects using the different data formats. The placement of the attribute or operator depends on the type of element to delete.
| Format | Method to Delete Object |
|---|---|
|
Junos XML |
Include the |
|
Formatted ASCII text |
Include the |
|
Configuration mode commands |
Use the |
|
JSON |
Include the |
To provide the configuration data as a data stream, enclose formatted ASCII text,
configuration mode commands, or JSON data in a <configuration-text>,
<configuration-set>, or <configuration-json>
element, respectively. To load the data from a file, you do not need to include any
additional elements.
Delete a Hierarchy Level or Container Object
A client application can delete a hierarchy level and all of its children (or a container object that has children but no identifier). To delete a hierarchy level, a client application first includes the basic tag elements or configuration statements for its parent levels, as described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol.
To use Junos XML elements to delete a hierarchy level, an application includes
the delete="delete" attribute in the empty tag that represents
the hierarchy level or container object.
<configuration>
<!-- opening tag for each parent level -->
<level-or-object delete="delete"/>
<!-- closing tag for each parent level -->
</configuration>To use formatted ASCII text, an application places the delete:
statement on the line that precedes the hierarchy level to remove. The
application also places a semicolon after the level to remove (even though the
existing configuration uses curly braces that enclose its child statements).
/* statements for parent levels */
delete:
object-or-level;
/* closing braces for parent levels */To use configuration mode commands, an application specifies the
delete command and the statement path to the hierarchy
level or object to remove.
delete statement-path-to-level-or-object
To use JSON configuration data, an application includes the
"operation" : "delete" attribute in the attribute list for
the hierarchy or container object to remove.
{
"configuration" : {
/* JSON objects for parent levels */
"object-or-level" : {
"@" : {
"operation" : "delete"
}
}
/* closing braces for parent levels */
}
}The following example removes the [edit protocols ospf]
hierarchy level from the candidate configuration using Junos XML tag
elements:
<rpc>
<load-configuration>
<configuration>
<protocols>
<ospf delete="delete"/>
</protocols>
</configuration>
</load-configuration>
</rpc>The following example removes the [edit protocols ospf]
hierarchy level from the candidate configuration using JSON configuration data.
The request provides the configuration data as a data stream, so the application
encloses the data in a <configuration-json> element.
<rpc>
<load-configuration format="json">
<configuration-json>
{
"configuration" : {
"protocols" : {
"ospf" : {
"@" : {
"operation" : "delete"
}
}
}
}
}
</configuration-json>
</load-configuration>
</rpc>Delete a Configuration Object That Has an Identifier
To delete a configuration object that has an identifier, a client application first includes the basic tag elements or configuration statements for its parent levels, as described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol.
To Junos XML elements to delete the object, an application includes the
delete="delete" attribute in the opening tag for the object
to remove. In the object's container element, the application encloses only the
identifier element, not the elements that represent any other characteristics of
the object. In the following example, the <name> element
is the object's identifier:
<configuration>
<!-- opening tag for each parent of the object -->
<object delete="delete">
<name>identifier</name>
</object>
<!-- closing tag for each parent of the object -->
</configuration>The delete attribute appears in the opening container tag,
not in the identifier tag. The presence of the identifier tag element
results in the removal of the specified object, not in the removal of the
entire hierarchy level represented by the container tag element.
To use formatted ASCII text to delete the object, an application places the
delete: statement on the line that precedes the object and
its identifier.
/* statements for parent levels of the object */
delete:
object identifier;
/* closing braces for parent levels of the object */To use configuration mode commands, an application specifies the
delete command, the statement path to the object, and the
object and its identifier.
delete statement-path-to-object object identifier
To use JSON configuration data, an application includes the
"operation" : "delete" attribute in the attribute list for
the object. In the container object, it encloses only the name/value pair
representing the identifier. In the following example, the "name" field
identifies the object to remove:
{
"configuration" : {
/* JSON objects for parent levels of the object */
"object" : [
{
"@" : {
"operation" : "delete"
},
"name" : "identifier"
}
]
/* closing braces for parent levels of the object */
}
}
The following example uses Junos XML tag elements to remove the user object
barbara from the [edit system login user]
hierarchy level in the candidate configuration.
<rpc>
<load-configuration>
<configuration>
<system>
<login>
<user delete="delete">
<name>barbara</name>
</user>
</login>
</system>
</configuration>
</load-configuration>
</rpc>The following example uses JSON configuration data to remove the user object
barbara from the [edit system login user]
hierarchy level in the candidate configuration. The request provides the
configuration data as a data stream, so the application encloses the data in a
<configuration-json> element.
<rpc>
<load-configuration format="json">
<configuration-json>
{
"configuration" : {
"system" : {
"login" : {
"user" : [
{
"@" : {
"operation" : "delete"
},
"name" : "barbara"
}
]
}
}
}
}
</configuration-json>
</load-configuration>
</rpc>Delete a Single-Value or Fixed-Form Option from a Configuration Object
A client application can delete either a fixed-form option or an option that takes just one value from a configuration object. The client application first includes the basic tag elements or configuration statements for its parent levels, as described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol. For information about deleting an option that can take multiple values, see Delete Values from a Multivalue Option of a Configuration Object.
To use Junos
XML tag elements to delete the option, an application includes the
delete="delete" attribute in the empty tag for that option.
The application does not include tag elements for children that should remain in
the configuration. In the following example, the <name>
element is the object's identifier:
<configuration>
<!-- opening tag for each parent of the object -->
<object>
<name>identifier</name> <!-- if object has an identifier -->
<option1 delete="delete"/>
<option2 delete="delete"/>
<!-- tag elements for other options to delete -->
</object>
<!-- closing tag for each parent of the object -->
</configuration>When using formatted ASCII text, the application places the
delete: statement above each option:
/* statements for parent levels of the object */
object identifier;
delete:
option1;
delete:
option2;
/* closing braces for parent levels of the object */When
using configuration mode commands, the application specifies the
delete command, the statement path to the option, and the
option to be removed. The commands can specify the full path to the option
statement. Alternatively, the commands can navigate to the hierarchy level of
the object and delete the option statement from that location. Use a separate
command to delete each
option.
delete statement-path-to-object object identifier option1
delete statement-path-to-object object identifier option2
edit statement-path-to-object object identifier
delete option1
delete option2 "operation" : "delete" attribute in the option's attribute
list. To delete options for a hierarchy level or container object, specify the
options to delete at that level.{
"configuration" : {
/* JSON objects for parent levels */
"level-or-object" : {
"@option1" : {
"operation" : "delete"
},
"@option2" : {
"operation" : "delete"
}
}
/* closing braces for parent levels */
}
}
To delete options for an object that has an identifier, include the identifier first, and then specify the options to delete. In the following example, the element’s identifier has the field name "name":
{
"configuration" : {
/* JSON objects for parent levels of the object */
"object" : [
{
"name" : "identifier",
"@option1" : {
"operation" : "delete"
},
"@option2" : {
"operation" : "delete"
}
}
]
/* closing braces for parent levels of the object */
}
}
The following example removes the fixed-form option
disable at the
[edit forwarding-options sampling] hierarchy level using
Junos XML tag elements.
<rpc>
<load-configuration>
<configuration>
<forwarding-options>
<sampling>
<disable delete="delete"/>
</sampling>
</forwarding-options>
</configuration>
</load-configuration>
</rpc>Delete Values from a Multivalue Option of a Configuration Object
Some Junos OS configuration objects are leaf statements that have multiple values. In the formatted ASCII CLI representation, the values are enclosed in square brackets following the name of the object:
object [value1 value2 value3 ...];
The Junos XML representation does not use a parent tag for the object, but
instead uses a separate instance of the object element for each value. In the
following example, the <name> element is the
identifier:
<parent-object>
<name>identifier</name>
<object>value1</object>
<object>value2</object>
<object>value3</object>
</parent-object>
For example, consider the permissions of a login class, which are displayed as a list in brackets.
class admin {
permissions [ admin admin-control configure ];
}
Junos XML format lists each permission in a separate
<permissions> element.
<configuration>
<system>
<login>
<class>
<name>admin</name>
<permissions>admin</permissions>
<permissions>admin-control</permissions>
<permissions>configure</permissions>
</class>
</login>
</system>
</configuration>To remove one or more values for such an object, a client application first includes the basic tag elements or configuration statements for its parent levels, as described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol.
When using Junos XML elements to remove a value, the application includes the
delete="delete" attribute in the opening tag for each
value. It does not include elements that represent values to be retained. In the
following example, the parent object's identifier
is <name>:
<configuration>
<!-- opening tag for each parent of the parent object -->
<parent-object>
<name>identifier</name>
<object delete="delete">value1</object>
<object delete="delete">value2</object>
</parent-object>
<!-- closing tag for each parent of the parent object -->
</configuration>When using formatted ASCII text, the application repeats the parent statement for
each value and places the delete: statement above each paired
statement and value:
/* statements for parent levels of the parent object */
parent-object identifier;
delete:
object value1;
delete:
object value2;
/* closing braces for parent levels of the parent object */
When using configuration mode commands, the application specifies the
delete command, the statement path to each value, and the
value to be removed. The commands can specify the full path to the value.
Alternatively, the commands can navigate to the hierarchy level of the object
and delete the value from that location. Use a separate command to delete each
value.
delete statement-path-to-parent-object parent-object identifier object value1
delete statement-path-to-parent-object parent-object identifier object value2
edit statement-path-to-parent-object parent-object identifier object
delete value1
delete value2
In JSON, a multivalue option is a name/value pair where the field name is the object name, and its value, which represents the options, is an array of strings. Junos OS does not support using JSON to delete single values from an object with a multivalue option. To update the option list, you must delete the existing object and then configure a new object with the required set of values.
The following example uses Junos XML elements to remove two of the permissions
granted to the user-accounts login class.
<rpc>
<load-configuration>
<configuration>
<system>
<login>
<class>
<name>user-accounts</name>
<permissions delete="delete">configure</permissions>
<permissions delete="delete">control</permissions>
</class>
</login>
</system>
</configuration>
</load-configuration>
</rpc>