Upload Configuration Data as a File Using the Junos XML Protocol
Junos XML protocol client applications can use the
<load-configuration> operation to load configuration data onto a
Junos device from a local or remote file.
A Junos XML protocol client application can load configuration data from a file onto a device running Junos OS or a device running Junos OS Evolved. The file can be a local file on the Junos device or a remote file on an FTP or HTTP server. After loading the configuration data, the client must commit the configuration to make it active.
Before loading the file, an administrator saves the configuration data as the contents of the file. The configuration data can be Junos XML elements, formatted ASCII text, Junos OS configuration mode commands, or JavaScript Object Notation (JSON). For more information, see Define the Format of Configuration Data to Upload in a Junos XML Protocol Session.
When you load configuration data from a file, you do not need to enclose data
formatted as ASCII text, configuration mode commands, or JSON in
<configuration-text>,
<configuration-set>, or
<configuration-json> elements as you do for a data
stream.
To load the configuration data from a local or remote file, the Junos XML protocol
client application emits the <rpc> element and encloses the
<load-configuration/> operation with the
url attribute. The format and
action attributes specify the format of the data and how to
load the data into the target configuration database.
<rpc>
<load-configuration url="url" format="format" action="action"/>
</rpc>
The value of the url attribute can be a local file path, an FTP
location, or an HTTP URL.
-
A local file can have one of the following forms:
-
/path/filename —File on a mounted file system, either on the local flash drive or on hard disk.
-
a:filename or a:path/filename —File on the local drive. The default path is / (the root-level directory). The removable media can be in MS-DOS or UNIX (UFS) format.
-
-
A file on an FTP server has the following form:
ftp://username:password@hostname/path/filename
-
A file on an HTTP server has the following form:
http://username:password@hostname/path/filename
In each case, the default value for the path variable is the
user's home directory. To specify an absolute path, start the path with the
characters %2F; for example,
ftp://username:password@hostname/%2Fpath/filename
.
You can combine the url attribute with one or more of the following
attributes in the <load-configuration/> tag:
-
format -
action
The request must include the format attribute to specify the format
of the data in the file unless the data format is Junos XML elements, which is the
default. You can also include the action attribute to specify how
to load the new data into the existing configuration.
Table 1 outlines the data format and corresponding attributes.
| Data Format | format Attribute |
action Attribute |
|---|---|---|
|
ASCII text |
|
|
|
Configuration mode commands |
|
|
|
JSON |
|
|
|
Junos XML elements (default) |
|
|
For example, if the data is Junos XML tag elements, include the
format="xml" attribute or omit the format
attribute, which defaults to XML.
<rpc>
<load-configuration url="file-location"/>
</rpc>
If the data is formatted ASCII text, include the format="text"
attribute.
<rpc>
<load-configuration url="file-location" format="text"/>
</rpc>
If the data comprises configuration mode commands, include the
action="set" and format="text" attributes.
<rpc>
<load-configuration url="file-location" action="set" format="text"/>
</rpc>
If the data uses JSON format, include the format="json" attribute.
<rpc>
<load-configuration url="file-location" format="json"/>
</rpc>
The following example loads Junos XML-tagged configuration data stored in the file
/var/configs/user-accounts from the FTP server
cfg-server.mycompany.com. The opening <load-configuration>
tag appears on two lines for legibility only.
<rpc>
<load-configuration
url="ftp://admin:AdminPwd@cfg-server.mycompany.com/var/configs/user-accounts"/>
</rpc>The Junos XML Protocol server response is:
<rpc-reply xmlns:junos="url">
<load-configuration-results>
<load-success/>
</load-configuration-results>
</rpc>