Compare the Active or Candidate Configuration to a Prior Version Using the Junos XML Protocol
In the Junos OS CLI, you use the compare command to compare the active or candidate configuration to a previously
committed configuration and display the differences. You can specify
the comparison configuration by referencing its configuration revision
identifier or its rollback number.
For example, in operational mode, you can compare the active configuration to a previously committed configuration by using the following commands:
show configuration | compare revision revision-idshow configuration | compare rollback rollback-number
In configuration mode, you can compare the candidate configuration to a previously committed configuration by using the following commands:
show | compare revision revision-idshow | compare rollback rollback-number
Similarly, in a Junos XML protocol session, a client application can compare the active or
candidate configuration to a previously committed configuration (the comparison
configuration). To display the differences, the client application uses the
<get-configuration> operation with the
compare attribute. The compare attribute
accepts the following values, which indicate the method used to reference the
comparison configuration:
configuration-revision—Reference the comparison configuration by its configuration revision identifier string, which you define in theconfiguration-revision="revision-id"attribute.rollback—Reference the comparison configuration by its rollback index, which you define in therollback="rollback-number"attribute.
You can combine the compare attribute with the database
attribute to indicate whether to compare the candidate configuration or the active
configuration to the previously committed configuration. The database attribute
accepts the following values:
-
database="candidate"—Compare the candidate configuration. This value is the default. -
database="committed"—Compare the active configuration.
You specify the comparison configuration by including either the
configuration-revision or rollback attribute
and specifying the appropriate configuration revision identifier or rollback index.
If you do not provide the configuration-revision or
rollback attribute or if you provide an invalid configuration
revision identifier, the server uses the active configuration as the comparison
configuration. The active configuration corresponds to rollback number 0.
For example, to compare the candidate configuration to the configuration that has the given configuration revision identifier, use the following syntax:
<rpc>
<get-configuration compare="configuration-revision" configuration-revision="revision-id" format="text">
<!-- optional - configuration elements to compare -->
</get-configuration>
</rpc>Similarly, to compare the candidate configuration to the configuration that has the given rollback index, use the following syntax:
<rpc>
<get-configuration compare="rollback" rollback="[0-49]" format="text">
<!-- optional - configuration elements to compare -->
</get-configuration>
</rpc>To compare the active configuration to a previous configuration,
include the database="committed" attribute.
For example:
<rpc>
<get-configuration database="committed" compare="configuration-revision" configuration-revision="re0-1605138555-328"/>
</rpc>You can also specify the scope of the comparison. You can compare the full configuration, or you can compare a subset of the configuration. To compare a subset of the configuration, define a subtree filter that selects the elements to compare, as shown in the following example:
<rpc>
<get-configuration compare="configuration-revision" configuration-revision="re0-1605288042-335">
<configuration>
<system>
<scripts/>
</system>
</configuration>
</get-configuration>
</rpc>
When you compare the candidate configuration to the active configuration, the
compare operation returns XML output. For all other
comparisons, it returns the output as text using a patch format. The
<configuration-information> and
<configuration-output> tags enclose the text output. The
output uses the following conventions to specify the differences between
configurations:
Statements that are only in the active or candidate configuration are prefixed with a plus sign (+).
Statements that are only in the comparison file are prefixed with a minus sign (–).
Statements that are unchanged are prefixed with a single blank space ( ).
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.4R1/junos"> <configuration-information> <configuration-output> [edit system scripts op] - file bgp-summary.py; + file bgp-neighbors.py; </configuration-output> </configuration-information> </rpc-reply>
When you compare the candidate configuration to the active configuration, you can display the
differences in text, XML, or JSON format. To select a format, include the
format attribute in the request and specify the format
value.
For example, the following request returns XML format:
<rpc>
<get-configuration compare="rollback" rollback="0" format="xml"/>
</rpc>
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/16.1R1/junos">
<configuration>
<system>
<scripts operation="create">
<op>
<file>
<name>bgp.slax</name>
</file>
</op>
</scripts>
</system>
</configuration>
</rpc-reply>
The following request returns JSON format:
<rpc>
<get-configuration compare="rollback" rollback="0" format="json"/>
</rpc>
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/16.1R1/junos">
<configuration-information>
<json-output>
{
"configuration" : {
"system" : {
"scripts" : {
"@" : {
"operation" : "create"
},
"op" : {
"file" : [
{
"name" : "bgp.slax"
}
]
}
}
}
}
}
</json-output>
</configuration-information>
</rpc-reply>When you compare the candidate and active configurations and display the
differences in XML or JSON format, the device omits the
<configuration> tag in the XML output and omits the
configuration object in the JSON output in the following
cases:
-
The comparison returns no differences
-
The comparison returns differences for only non-native configuration data, for example, configuration data associated with an OpenConfig data model.