Fetching Configuration Subtrees Using Netconf
It took me a bit of struggling to figure out how to pull configuration subtrees via NetConf. Part of this was because I was using
I’ll work that out later… the main reason for this post is to document what I found on how to get configuration subtrees. This particular example fetches the subtree for a specific neighbor under [protocols l2circuit].
To structure the rpc request, we use the command “get-config” and specify a source of candidate. Then we add a “filter” tag with an attribute of @type=“subtree” and under that we can specify the configuration subtree as xml tags.
<rpc message-id="1002 Tue Jun 17 23:25:48 -0400 2014">
<get-config>
<source><candidate/></source>
<filter type="subtree">
<configuration>
<protocols>
<l2circuit>
<neighbor>
<name>192.168.104.69</name>
</neighbor>
</l2circuit>
</protocols>
</configuration>
</filter>
</get-config>
</rpc>
]]>]]>
This is the reply I got.
rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns:junos="http://xml.juniper.net/junos/12.3R4/junos" message-id="1002 Tue Jun 17 23:25:48 -0400 2014">
<get-config>
<source><candidate/></source>
<filter type="subtree">
<configuration>
<protocols>
<l2circuit>
<neighbor>
<name>192.168.104.69</name>
</neighbor>
</l2circuit>
</protocols>
</configuration>
</filter>
</get-config>
</rpc>
<data>
<configuration xmlns="http://xml.juniper.net/xnm/1.1/xnm" junos:changed-seconds="1402600329" junos:changed-localtime="2014-06-12 19:12:09 UTC">
<protocols>
<l2circuit>
<neighbor>
<name>192.168.104.69</name>
<interface>
<name>ae0.3909</name>
<virtual-circuit-id>55509</virtual-circuit-id>
</interface>
<interface>
<name>ae0.3933</name>
<virtual-circuit-id>55533</virtual-circuit-id>
</interface>
<interface>
<name>ae0.3959</name>
<virtual-circuit-id>55559</virtual-circuit-id>
</interface>
<interface>
<name>ae0.3983</name>
<virtual-circuit-id>55583</virtual-circuit-id>
</interface>
<interface>
<name>ae0.3991</name>
<virtual-circuit-id>55591</virtual-circuit-id>
</interface>
</neighbor>
</l2circuit>
</protocols>
</configuration>
</data>
</rpc-reply>
]]>]]>
My particular application in this case was that I wanted to get the interface associated with a certain virtual-circuit-id and neighbor. This made it easy to collect what I wanted and to also present the xml for logging.