Parsing the NETCONF Server Response
In a NETCONF session with a device running Junos
OS, a client application sends RPCs to the NETCONF server to request
information from and manage the configuration on the device. The NETCONF
server encloses its response to each client request in a separate
pair of opening
<rpc-reply> and closing
</rpc-reply> tags. Each response constitutes a well-formed
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" \
<!-- tag elements representing a response -->
xmlns attribute in the opening
<rpc-reply> tag defines the namespace for enclosed
tag elements that do not have the
junos: prefix in their names and that are not enclosed in a child container
tag that has the
xmlns attribute with a
Beginning in Junos
OS Release 15.1, if you configure the
rfc-compliant statement on the device, the NETCONF server explicitly declares
the NETCONF namespace, which is bound to the
nc prefix, and qualifies all NETCONF tags in its replies with the prefix.
xmlns:junos attribute defines
the default namespace for enclosed Junos XML tag elements that are
qualified by the
junos: prefix. The release variable in the URI represents the Junos OS release
that is running on the NETCONF server device, for example 19.3R1.
Client applications must include code for parsing the stream of response tag elements coming from the NETCONF server, either processing them as they arrive or storing them until the response is complete. The NETCONF server returns three classes of responses:
Operational responses are responses to requests for information about the status of a switching, routing, or security platform. They correspond to the output from CLI operational commands.
The Junos XML API defines response tag elements for all defined
operational request tag elements. For example, the NETCONF server
returns the information requested by the
<get-interface-information> tag in a response tag element called
<interface-information>, and returns the information requested by the
<get-chassis-inventory> tag in a response tag called
<chassis-inventory>. Operational responses also can be returned in formatted ASCII,
which is enclosed within an
or in JSON format. For more information about formatting operational
responses, see Specifying the Output Format for Operational Information Requests in a NETCONF Session.
The following sample response includes information about the
interface ge-2/3/0. The namespace indicated by the
xmlns attribute in the opening
<interface-information> tag is for interface information for Junos OS Release 19.3.
The opening tags appear on two lines here for legibility only:
<!-- other data tag elements for the ge-2/3/0 interface - ->
For more information about the
xmlns attribute and the contents of operational response tag elements,
see Requesting Operational Information Using NETCONF. For a summary of operational response tag
elements, see the Junos XML API Operational Developer Reference.
Configuration Information Responses
Configuration information responses are responses to requests for information about the device’s current configuration. The Junos XML API defines a tag element for every container and leaf statement in the configuration hierarchy.
The following sample response includes the information at the [edit system login] hierarchy level in the configuration
hierarchy. For brevity, the sample shows only one user defined at
this level. The opening
appears on two lines for legibility only. For information about the
attributes in the opening
<configuration> tag, see Specifying the Source for Configuration Information Requests Using NETCONF.
Configuration Change Responses
Configuration change responses are responses
to requests that change the state or contents of the device configuration.
The NETCONF server indicates successful execution of a request by
<ok/> tag within the
<rpc-reply> tag element:
If the operation fails, the
<rpc-reply> tag element instead encloses an
<rpc-error> element that describes the cause of the failure. For information
about handling errors, see Handling an Error or Warning in a NETCONF Session.
rfc-compliantstatement on the device, the NETCONF server explicitly declares the NETCONF namespace, which is bound to the
ncprefix, and qualifies all NETCONF tags in its replies with the prefix.