Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Request Configuration Data Using the Junos XML Protocol

Junos XML protocol client applications can use the <get-configuration> operation to request configuration data from Junos devices.

How to Request Configuration Data Using the Junos XML Protocol

A Junos XML protocol client application can request configuration data from a device running Junos OS or a device running Junos OS Evolved. To request configuration data, a client application encloses the <get-configuration> operation in an <rpc> element. A client application can include optional attributes to specify the source and format of the configuration information to return. In addition, a client application can define the scope of the information to return by including the appropriate child tag elements. For example, the client can request the entire configuration or specific portions of the configuration.

The basic syntax is as follows:

Note:

To view configuration data in a specific instance of the ephemeral configuration database, a client application must open the ephemeral instance using the <open-configuration> operation with the appropriate child tags before executing the <get-configuration> request.

Note:

A Junos XML protocol client application can use the <get-configuration> operation to request the entire logical system configuration or specific logical system configuration hierarchies.

The following topics describe how a client application specifies the source, format, and scope of information returned by the Junos XML protocol server:

The Junos XML protocol server encloses its reply in an <rpc-reply> element. Within the <rpc-reply> element, the server encloses the configuration data within the tag that corresponds to the requested format for all formats except JavaScript Object Notation (JSON).

  • <configuration>—Encloses Junos XML-tagged output

  • <configuration-text>—Encloses formatted ASCII output

  • <configuration-set>—Encloses configuration mode commands

For Junos XML and JSON data, the server includes attributes with the junos: prefix to indicate when the configuration was last changed or committed and the user who committed it. For more information about the attributes, see Specify the Database Source for Configuration Data to Return.

Note:

When displaying operational or configuration data that contains characters outside the 7-bit ASCII character set, Junos OS escapes and encodes these character using the equivalent UTF-8 decimal character reference. For more information see Understanding Character Encoding on Devices Running Junos OS.

Applications can also request other configuration-related information, including an XML schema representation of the configuration hierarchy or information about previously committed configurations. For more information, see the following:

Specify the Database Source for Configuration Data to Return

A Junos XML protocol client application can use the <get-configuration> operation to request configuration data from a Junos device. A client application can request information from the following configuration databases:

  • Candidate configuration database

  • Active configuration database

  • Open instance of the ephemeral configuration database

A client application can request information from the candidate configuration or the active configuration by using the <get-configuration> operation and setting the database attribute to the appropriate value. By default, the <get-configuration> operation returns data from the candidate configuration database. The Junos XML protocol server returns Junos XML-tagged output by default, except when the compare attribute is included.

The database attribute can be combined with one or more of the following attributes in the <get-configuration> tag: changed, commit-scripts, compare, format, inherit and optionally groups and interface-ranges.

The following sections: outline how to specify the source of the requested configuration data; describe the Junos XML protocol server reply; and provide a sample request.

Request Candidate Configuration Data

To request information from the candidate configuration database, a client application includes the database="candidate" attribute or omits the database attribute.

Request Active Configuration Data

To request information from the active configuration database, a client application includes the database="committed" attribute.

Request Ephemeral Configuration Data

To request information from a specific instance of the ephemeral configuration database, a client application first opens the ephemeral instance using the <open-configuration> operation with the appropriate child tags.

After opening the ephemeral instance, the client application requests information from that instance by using the <get-configuration> operation. After all operations on the ephemeral instance are complete, the client application closes the instance with the <close-configuration/> operation.

Junos XML Protocol Server Reply

The Junos XML protocol server encloses its reply in an <rpc-reply> element. Depending on the database source, the Junos XML protocol server includes information about when the configuration was last changed or committed. Junos XML-tagged output and JSON data include this information as attributes in the opening configuration tag or object.

Table 1: configuration Attributes in RPC Reply
Database Attribute Description

Candidate configuration or open ephemeral instance

junos:changed-localtime="YYYY-MM-DD hh:mm:ss TZ"

Represents the time of the last change as the date and time in the device’s local time zone.

junos:changed-seconds="seconds"

Represents the time of the last change as the number of seconds since midnight on 1 January 1970.

Active configuration

junos:commit-localtime="YYYY-MM-DD hh:mm:ss TZ"

Represents the commit time as the date and time in the device’s local time zone.

junos:commit-seconds="seconds"

Represents the commit time as the number of seconds since midnight on 1 January 1970.

junos:commit-user="username"

User who requested the commit operation.

For example, when returning information from the candidate configuration or from an instance of the ephemeral configuration database, the output includes information about when the configuration was last changed.

When returning information from the active configuration, the output includes information about when the configuration was last committed.

Example: Request the Active Configuration

The following example requests the entire committed configuration. In actual output, the Junos-version variable is replaced by a value such as 20.4R1 for the initial version of Junos OS Release 20.4.

Client application sends RPC request for committed configuration to Junos XML Protocol Server, which replies with configuration and system details.

Specify the Output Format for Configuration Data to Return

A Junos XML protocol client application can use the <get-configuration> operation to request configuration data from a Junos device. A client application can include the optional format attribute to specify the format of the configuration data. The application can request configuration data in the following formats:

  • Junos XML format (default)

  • Formatted ASCII text

  • Configuration mode commands

  • JSON

Note:

Client applications use Junos XML tag elements to represent the configuration elements to display regardless of which output format they request. The format attribute controls the format of the Junos XML protocol server’s output only.

The following sections: outline how to specify the format of the requested configuration data; discuss the attributes that you can combine with the format attribute; and provide a sample request.

Request Junos XML Format

To request that the Junos XML protocol server return configuration data in Junos XML-tagged output, a client application includes the format="xml" attribute in the <get-configuration> tag or omits the format attribute. The Junos XML protocol server returns Junos XML-tagged output by default, except when the compare attribute is included.

When the application requests Junos XML tag elements, the Junos XML protocol server encloses its output in <rpc-reply> and <configuration> elements.

Request Formatted ASCII Text

To request that the Junos XML protocol server return configuration data as formatted ASCII text, a client application includes the format="text" attribute in the <get-configuration> tag.

When the application requests formatted ASCII output, the Junos XML protocol server encloses the data in <rpc-reply> and <configuration-text> elements. The server formats the data in the same way that the CLI show configuration command displays configuration data. The output uses the newline character, tabs, braces, and square brackets to indicate the hierarchical relationships between configuration statements.

Request Configuration Mode Commands

To request configuration data formatted as configuration mode commands, a client application includes the format="set" attribute in the <get-configuration> tag.

When the application requests configuration mode commands, the Junos XML protocol server encloses the data in <rpc-reply> and <configuration-set> elements. The server formats the data in the same way that the CLI show configuration | display set command displays configuration data.

Request JSON Format

To return configuration data in JSON format, a client application includes the format="json" attribute in the <get-configuration> tag.

When the application requests JSON format, the Junos XML protocol server encloses the JSON data in an <rpc-reply> element.

Note:

Junos OS configuration data emitted in JSON format does not enclose integers in quotation marks.

Include Additional Attributes

The format attribute can be combined with one or more of the following other attributes in the <get-configuration/> tag:

  • compare with the value compare="rollback" and with rollback="0". When you compare the candidate configuration to the active configuration (rollback="0"), you can display the differences in formats other than text by including the appropriate value for the format attribute in the request.

  • commit-scripts with a value of commit-scripts="apply" or commit-scripts="apply-no-transients". The commit-scripts="view" attribute returns Junos XML-tagged output by default, even if the format="text" attribute is included, since this is the format that is input to commit scripts.

  • database, which is described in Specify the Database Source for Configuration Data to Return.

  • inherit and optionally groups and interface-ranges, which are described in Specify How to Display Inheritance for Configuration Groups and Interface Ranges Using the Junos XML Protocol.

The change and identifier indicators appear only in Junos XML-tagged output and JSON output. Thus, you cannot combine the format="text" attribute with the changed attribute or include it after requesting an indicator for identifiers.

Example: Request Configuration Data and Specify the Format

The following example requests the [edit policy-options] hierarchy level in the candidate configuration as formatted ASCII output.

Client Application sends an RPC request to Junos XML Protocol Server to get configuration in text format for policy-options. Server replies with configuration text including policy-statement load-balancing-policy with route-filter rules for IP ranges 192.168.10/24 orlonger and 10.114/16 orlonger, and a then clause specifying load-balance per-packet.

Specify the Scope of the Configuration Data to Return

A Junos XML protocol client application can use the <get-configuration> operation to request configuration data from a Junos device. A client application can request the entire configuration or specific portions of the configuration from the device. To request the complete or partial configuration, a client application encloses the <get-configuration> operation in an <rpc> element and includes the appropriate child tag elements.

For information about specifying the scope of the configuration information to return, see the following topics: