Delete Elements in Configuration Data Using the Junos XML Protocol
In a Junos XML protocol session with a device
running Junos OS, to delete configuration elements (hierarchy levels
or configuration objects) from the candidate configuration or open
configuration database, a client application emits the basic tag elements
described in Creating, Modifying, or Deleting
Configuration Elements Using the Junos XML Protocol. When
using Junos XML tag elements to represent the elements to delete,
the client application includes the delete="delete"
attribute in the opening tag for each element. When using formatted
ASCII text, the client application precedes each element to delete
with the delete:
operator. When using configuration
mode commands to delete elements, the client application uses the delete
command and specifies the path to the element. When
using JSON data to delete an element, the client application includes
the "operation" : "delete"
attribute
in the attribute list for that element. The placement of the attribute
or operator depends on the type of element being deleted, as described
in the following sections:
You can load configuration data formatted using JavaScript Object Notation (JSON) starting in Junos OS Release 16.1.
Deleting a Hierarchy Level or Container Object
To delete a hierarchy level and all of its children (or a container object that has children but no identifier), a client application includes the basic tag elements or configuration statements for its parent levels, as described in Creating, Modifying, or Deleting Configuration Elements Using the Junos XML Protocol.
When using Junos XML tag elements, the application includes
the delete="delete"
attribute in the empty
tag that represents the level or container object:
<configuration> <!-- opening tag for each parent level --> <level-or-object delete="delete"/> <!-- closing tag for each parent level --> </configuration>
When using formatted ASCII text, the application places
the delete:
statement above the level to
be removed, which is followed by a semicolon (even though in the existing
configuration it is followed by curly braces that enclose its child
statements):
<configuration-text> /* statements for parent levels */ delete: object-or-level; /* closing braces for parent levels */ </configuration-text>
When using configuration mode commands, the application
specifies the delete
command and the statement path to
the hierarchy level or object to be removed.
<configuration-set> delete statement-path-to-level-or-object </configuration-set>
When using JSON configuration data to delete a hierarchy
level or container object, the application includes the "operation" : "delete"
attribute in the attribute
list for the hierarchy or container object:
<configuration-json> { "configuration" : { /* JSON objects for parent levels */ "object-or-level" : { "@" : { "operation" : "delete" } } /* closing braces for parent levels */ } } </configuration-json>
The following example shows how to remove the [edit protocols ospf]
hierarchy level from the candidate configuration using Junos XML
tag elements:
The following example shows how to remove the [edit protocols ospf]
hierarchy level from the candidate configuration using configuration
data formatted in JSON:
<rpc> <load-configuration format="json"> <configuration-json> { "configuration" : { "protocols" : { "ospf" : { "@" : { "operation" : "delete" } } } } } </configuration-json> </load-configuration> </rpc>
Deleting a Configuration Object That Has an Identifier
To delete a configuration object that has an identifier, a client application includes the basic tag elements or configuration statements for its parent levels, as described in Creating, Modifying, or Deleting Configuration Elements Using the Junos XML Protocol.
When using Junos XML tag elements, the application includes
the delete="delete"
attribute in the opening
tag for the object. In the container tag element for the object, it
encloses only the identifier tag element, not tag elements that represent
any other characteristics of the object. In the following, the identifier
tag element is called <name>
:
<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 element. 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.
When using formatted ASCII text, the application places
the delete:
statement above the object
and its identifier:
<configuration-text> /* statements for parent levels of the object */ delete: object identifier; /* closing braces for parent levels of the object */ </configuration-text>
When using configuration mode commands, the application
specifies the delete
command, the statement path to the
object, and the object and its identifier.
<configuration-set> delete statement-path-to-object object identifier </configuration-set>
When using JSON configuration data, the 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 JSON member that specifies the element’s
identifier has the field name "name":
<configuration-json> { "configuration" : { /* JSON objects for parent levels of the object */ "object" : [ { "@" : { "operation" : "delete" }, "name" : "identifier" } ] /* closing braces for parent levels of the object */ } } </configuration-json>
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.
The following example uses JSON-formatted configuration
data to remove the user object barbara
from the [edit system login user]
hierarchy level in the candidate configuration.
<rpc> <load-configuration format="json"> <configuration-json> { "configuration" : { "system" : { "login" : { "user" : [ { "@" : { "operation" : "delete" }, "name" : "barbara" } ] } } } } </configuration-json> </load-configuration> </rpc>
Deleting a Single-Value or Fixed-Form Option from a Configuration Object
To delete from a configuration object either a fixed-form option or an option that takes just one value, a client application includes the basic tag elements or configuration statements for its parent levels, as described in Creating, Modifying, or Deleting Configuration Elements Using the Junos XML Protocol. (For information about deleting an option that can take multiple values, see Deleting Values from a Multivalue Option of a Configuration Object.)
When using Junos XML tag elements, the application includes
the delete="delete"
attribute in the empty
tag for each option. It does not include tag elements for children
that are to remain in the configuration. In the following, the identifier
tag element for the object is called <name>
:
<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:
<configuration-text> /* statements for parent levels of the object */ object identifier; delete: option1; delete: option2; /* closing braces for parent levels of the object */ </configuration-text>
When using configuration mode commands, the application
specifies the delete
command, the statement path to the
option, and the option to be removed. You can specify the full path
to the option statement or navigate to the hierarchy level of the
object and delete the option statement from that location. Use a separate
command to delete each option.
<configuration-set> delete statement-path-to-object object identifier option1 delete statement-path-to-object object identifier option2 </configuration-set> <configuration-set> edit statement-path-to-object object identifier delete option1 delete option2 </configuration-set>
When using JSON configuration data to delete an option,
the application includes the "operation" : "delete"
attribute in the attribute list for that option. To delete options
for a hierarchy level or container object, specify the options to
delete at that level.
<configuration-json> { "configuration" : { /* JSON objects for parent levels */ "level-or-object" : { "@option1" : { "operation" : "delete" }, "@option2" : { "operation" : "delete" } } /* closing braces for parent levels */ } } </configuration-json>
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 JSON member that specifies the element’s identifier has the field name "name":
<configuration-json> { "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 */ } } </configuration-json>
The following example shows how to remove the fixed-form disable
option at the [edit forwarding-options sampling]
hierarchy level using Junos XML tag elements.
Deleting Values from a Multivalue Option of a Configuration Object
As described in Mapping Configuration Statements to Junos XML Tag Elements, 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 tag element for each value. In the
following, the identifier tag element is called
<name>
:
<parent-object> <name>identifier</name> <object>value1</object> <object>value2</object> <object>value3</object> </parent-object>
To
remove one or more values for such an object, a client application includes the
basic tag elements or configuration statements for its parent levels, as
described in Creating, Modifying, or Deleting Configuration Elements Using the Junos XML
Protocol. When using Junos XML tag elements, the application includes
the delete="delete"
attribute in the opening tag for each
value. It does not include tag elements that represent values to be retained. In
the following, the identifier tag element for the parent object is
called <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:
<configuration-text> /* 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 */ </configuration-text>
When
using configuration mode commands, the application specifies the
delete
command, the statement path to each value, and the
value to be removed. You can specify the full path to the value or navigate to
the hierarchy level of the object and delete the value from that location. Use a
separate command to delete each
value.
<configuration-set> delete statement-path-to-parent-object parent-object identifier object value1 delete statement-path-to-parent-object parent-object identifier object value2 </configuration-set> <configuration-set> edit statement-path-to-parent-object parent-object identifier object delete value1 delete value2 </configuration-set>
The JSON representation for an object with 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 desired set of values.
The following example shows how to remove two
of the permissions granted to the user-accounts
login class
using Junos XML tag elements.