Filter Operational Command Output for Specific Child Tags of an Object in NETCONF and Junos XML Protocol Sessions
In a NETCONF or Junos XML protocol session with a device running
Junos OS, a client application can request operational information
for the device and filter the output to select for child elements
of a specific object. To filter the operational command output to
return specific child elements, a client application emits an RPC
request for operational information and includes a <filter type="subtree">
tag element that encloses the tag elements representing all levels
in the operational command output hierarchy from the root element
down to the immediate parent level for the object.
To represent the requested instance of the object, the application
emits its container tag element and also includes its identifier using
the <name>
tag element or equivalent
identifier element for objects that do not use <name>
as an identifier. To select specific child tags, the client application
emits all desired child tag elements and descendents.
<rpc> <operational-request> <!-- optional tag elements representing the options --> <filter type="subtree"> <!-- opening tags for each parent of the object --> <object> <name>identifier</name> <first-child/> <second-child/> <third-child> <!--tags for descendents--> </third-child> <!-- tag for each additional child to return --> </object> <!-- closing tags for each parent of the object --> </filter> </operational-request> </rpc>
The server returns the requested object and child elements in the RPC reply.
<rpc-reply xmlns="URN" xmlns:junos="URL"> <!-- opening tags for each parent of the object --> <object> <name>identifier</name> <!-- requested child tags --> </object> <!-- closing tags for each parent of the object --> </rpc-reply>
The following example requests information for the show route
command, which corresponds to the <get-route-information>
RPC request tag. The client application filters the operational
command output to return only the <active-tag>
and <nh>
elements for the <rt>
object in the inet.0 table that has identifier 172.16.0.0/12.
<rpc> <get-route-information> <filter type="subtree"> <route-information> <route-table> <table-name>inet.0</table-name> <rt> <rt-destination>172.16.0.0/12</rt-destination> <rt-entry> <active-tag/> <nh/> </rt-entry> </rt> </route-table> </route-information> </filter> </get-route-information> </rpc> ]]>]]>
The RPC reply from the server includes only the <rt>
element and child elements that were requested.
<rpc-reply xmlns="URN" xmlns:junos="URL"> <route-information xmlns="URL"> <route-table> <table-name>inet.0</table-name> <rt junos:style="brief"> <rt-destination>172.16.0.0/12</rt-destination> <rt-entry> <active-tag>*</active-tag> <nh> <selected-next-hop/> <to>192.168.167.254</to> <via>fxp0.0</via> </nh> </rt-entry> </rt> </route-table> </route-information> </rpc-reply> ]]>]]>