Upload and Format Configuration Data in a NETCONF Session
A NETCONF client application can specify the delivery mechanism and the format of the configuration data when modifying the Junos device configuration. Client applications can use a text file or streaming data to upload configuration data in one of the accepted formats to the candidate configuration or open configuration database.
A client can choose to stream configuration changes within the session or reference data files that include the desired configuration changes. Each method has advantages and disadvantages. Streaming data allows you to send your configuration change data in line, using your NETCONF connection. This is useful when the device is behind a firewall and you cannot establish another connection to upload a data file. With text files you can keep the edit configuration commands simple; there is no need to include the possibly complex configuration data stream.
The <copy-config>
and <edit-config>
operations
accept one of two formats for the Junos configuration data: Junos XML or CLI configuration
statements. The choice between one data format over the other is personal preference.
When managing Junos devices, a NETCONF client can use the Junos XML protocol
<load-configuration>
operation in a NETCONF session to upload
configuration data formatted using JSON or configuration mode set
commands,
in addition to Junos XML or CLI configuration statement formats.
The delivery mechanism and the format are discussed in detail in the following sections.
Referencing Configuration Data Files
A client application can use the <copy-config>
or
<edit-config>
operation to upload configuration data stored in a
file. The <copy-config>
operation replaces the entire
configuration. The <edit-config>
operation loads the data as
indicated by the edit configuration mode specified in the
<default-operation>
element or the individual configuration data
elements.
Before loading the file, the client application or an administrator saves
Junos XML tag elements or CLI configuration statements as the contents of the file. The
file includes the tag elements or configuration statements representing all levels of the
configuration hierarchy from the root (represented by the
<configuration>
tag element) down to each element to change.
To specify the file, the client includes the <url>
element
as shown in the examples.
<rpc> <copy-config> <target> <candidate/> </target> <source> <url> <!-- location and name of file containing configuration data --> </url> </source> </copy-config> </rpc> ]]>]]>
<rpc> <edit-config> <target> <candidate/> </target> <url> <!-- location and name of file containing configuration data --> </url> </edit-config> </rpc> ]]>]]>
The data within these files can be formatted as either Junos XML elements
or CLI configuration statements. When the configuration data is formatted as CLI
configuration statements, include the format="text"
attribute in the
<url>
tag.
<url format="text"> <!-- location and name of file containing configuration data --> </url>
The configuration file can be placed locally or as a network resource.
-
When placed locally, the configuration file path can be relative or absolute.
-
Relative file path—The file location is relative to the user’s home directory. For example:
<url>config-replace.xml</url>
-
Absolute file path—The file location is based on the directory structure of the device, for example <drive>:filename or <drive>/:path/filename. If you are using removable media, the drive can be in the MS-DOS or UNIX (UFS) format. Junos OS also supports the
file://
URI. For example:<url>/var/tmp/config-replace.xml</url>
<url>file:///var/tmp/config-replace.xml</url>
-
-
When located on the network, the configuration file can be accessed using FTP or HTTP:
-
FTP example:
ftp://username:password@hostname/path/filename
Note:By default, the FTP path variable is relative to 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.
-
HTTP example:
http://username:password@hostname/path/filename
-
The following example shows how to incorporate configuration data stored in the file /var/tmp/configFile on the FTP server called ftp.myco.com:
Streaming Configuration Data
To provide configuration data as a data stream, a client application emits the
<config>
or <config-text>
tag elements
within the <rpc>
and <edit-config>
tag
elements. To specify the configuration elements to change, the application emits Junos XML
or CLI configuration statements representing all levels of the configuration hierarchy
from the root (represented by the <configuration>
or
<configuration-text>
tag element) down to each element to change.
<rpc> <edit-config> <target> <candidate/> </target> <config> <configuration> <!-- configuration changes --> </configuration> </config> </edit-config> </rpc> ]]>]]>
<rpc> <edit-config> <target> <candidate/> </target> <config-text> <configuration-text> <!-- configuration changes --> </configuration-text> </config-text> </edit-config> </rpc> ]]>]]>
The following example shows how to provide Junos XML configuration data in a data stream to configure the messages system log file:
Formatting Data: Junos XML versus CLI Configuration Statements
The NETCONF <copy-config>
and <edit-config>
operations accept one of two formats
for Junos OS configuration data: Junos XML or CLI configuration statements.
The choice between one data format over the other is personal preference.
When managing Junos devices, a NETCONF client can use the Junos XML protocol
<load-configuration>
operation in a NETCONF session to upload
configuration data formatted using JSON or configuration mode set
commands, in addition to Junos XML or CLI configuration statement formats.
When you load configuration data from a file, you include the <url>
element
with the file location. The default format for the configuration data is Junos XML.
<url>dataFile</url>
To specify that the data file contains CLI configuration statements, include the
format="text"
attribute in the <url>
tag.
<url format="text">dataFile</url>
When streaming data, you specify the data format by including one of two tags:
<config>
for Junos XML elements or
<config-text>
for CLI configuration statements.
In the following example, the <configuration>
element encloses Junos XML-formatted configuration data:
<config> <configuration> <system> <services> <ssh> <protocol-version>v2</protocol-version> </ssh> </services> </system> </configuration> </config>
In the following example, the <configuration-text>
element encloses the same data formatted as CLI configuration statements:
<config-text> <configuration-text> system { services { ssh { protocol-version v2; } } } </configuration-text> </config-text>