Parse 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
XML document.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" \ xmlns:junos="http://xml.juniper.net/junos/release/junos" \ [echoed attributes]> <!-- tag elements representing a response --> </rpc-reply> ]]>]]>
The 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
different value.
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.
The 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 20.4R1.
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
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 output
element,
or in JSON format. For more information about formatting operational
responses, see Specify 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 20.4.
The opening tags appear on two lines here for legibility only:
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"\ xmlns:junos="http://xml.juniper.net/junos/20.4R1/junos"> <interface-information \ xmlns="http://xml.juniper.net/junos/20.4R1/junos-interface"> <physical-interface> <name>ge-2/3/0</name> <!-- other data tag elements for the ge-2/3/0 interface - -> </physical-interface> </interface-information> </rpc-reply> ]]>]]>
For more information about the xmlns
attribute and the contents of operational response tag elements,
see Request 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 <rpc-reply>
tag appears
on two lines for legibility only. For information about the attributes
in the opening <configuration>
tag,
see Specify the Source for Configuration Information Requests Using NETCONF.
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"\ xmlns:junos="http://xml.juniper.net/junos/20.4R1/junos"> <data> <configuration attributes> <system> <login> <user> <name>admin</name> <full-name>Administrator</full-name> <!-- other data tag elements for the admin user --> </user> </login> </system> </configuration> </data> </rpc-reply> ]]>]]>
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
returning the <ok/>
tag within the <rpc-reply>
tag element:
<rpc-reply xmlns="URN" xmlns:junos="URL"> <ok/> </rpc-reply> ]]>]]>
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 Handle an Error or Warning in a NETCONF Session.
Change History Table
Feature support is determined by the platform and release you are using. Use Feature Explorer to determine if a feature is supported on your platform.
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.