Create New Elements in Configuration Data Using the Junos XML Protocol
A Junos XML protocol client application can create new configuration elements (hierarchy levels or configuration objects) on devices running Junos OS or devices running Junos OS Evolved. A client application first includes the basic tag elements, formatted ASCII statements, configuration mode commands, or JSON objects described in Create, Modify, or Delete Configuration Elements Using the Junos XML Protocol.
For Junos XML elements and formatted ASCII text, you can create new elements in either merge mode
or replace mode. For more information, see Merge Elements in Configuration Data Using the Junos XML Protocol and Replace Elements in Configuration Data Using the Junos XML Protocol. In replace mode, the application includes the action="replace"
attribute in the <load-configuration> tag. When you use
JavaScript Object Notation (JSON), you must use merge mode to create new objects.
The following sections outline how to create new configuration items using the different formats:
Junos XML
To use Junos XML to create the element, an application includes each of the
element’s identifier tags (if it has them) and all child tag elements that it is
defining for the element. In the following example, the identifier tag is
<name>. The application does not need to include any
attributes in the opening container tag for the new element.
<configuration>
<!-- opening tag for each parent of the element -->
<container-tag>
<name>identifier</name>
<!-- tag elements for other children, if any -->
</container-tag>
<!-- closing tag for each parent of the element -->
</configuration>Formatted ASCII Text
To use formatted ASCII text to create the element, an application includes each
of the element’s identifiers (if it has them) and all child statements (with
values if appropriate) that it is defining for the element. It does not need to
include an operator before the new element. 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>Configuration Mode Commands
To use configuration mode commands to create new elements, an application
includes the set command as you would execute it in the CLI.
The command includes the statement path to the element, the element’s identifier
if it has one, and all child statements (with values if appropriate) that it is
defining for the element. 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-elements
</configuration-set>JSON
To use JSON to create the object, an application includes the object’s
identifiers (if it has them) and all data and child objects that it is defining
for the object. The application does not need to include any specific operation
attributes to create the new object. To provide the configuration data as a data
stream, enclose the data in a <configuration-json>
element.
In the following example, the object’s identifier is the field designated as "name".
<configuration-json>
{
"configuration" : {
/* JSON objects for parent levels of the element */
"container-tag" : {
"object" : [
{
"name" : "identifier",
/* data and child objects */ # if any
}
],
/* data and child objects */ # if any
}
/* closing braces for parent levels of the element */
}
}
</configuration-json>