libyang icon indicating copy to clipboard operation
libyang copied to clipboard

Question: Is there a method that would allow us to convert an lyd_node into a NETCONF request like edit/get?

Open rabhat31 opened this issue 2 years ago • 3 comments

rabhat31 avatar Jul 10 '23 22:07 rabhat31

Um, lyd_print_mem(), for example? You need to be more specific, struct lyd_node is the data tree stored as structures in memory. It may represent any YANG data including an RPC request.

michalvasko avatar Jul 11 '23 06:07 michalvasko

For example, say I have an lyd_node which has this configuration data:

<native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
    <interface>
      <GigabitEthernet>
        <name>1/0/5</name>
        <description>Testing </description>
        <mac-address>a:b:c:d:e:f</mac-address>
      </GigabitEthernet>
    </interface>
</native>

Is there a libyang function I can use to wrap this into an edit-config RPC ? The end result would looks something like:

'<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
  <edit-config>
    <target>
      <running/>
    </target>
    <config>
      <native xmlns="http://cisco.com/ns/yang/Cisco-IOS-XE-native">
        <interface>
          <GigabitEthernet>
            <name>1/0/5</name>
            <description>Testing </description>
            <mac-address>a:b:c:d:e:f</mac-address>
          </GigabitEthernet>
        </interface>
      </native>
    </config>
  </edit-config>
</rpc>'

rabhat31 avatar Jul 11 '23 21:07 rabhat31

There's libnetconf2 which has nc_rpc_edit if you're looking for a way of actually making these operations. If you "just" want to make a string out of them, I'm sure you can build the "outer" RPC shell with libyang on its own (just load the corresponding NETCONF module), and feed the anyxml which is the payload of your <edit-config> as a string.

What problem are you trying to solve?

jktjkt avatar Jul 11 '23 22:07 jktjkt