robshakir / pyangbind

A plugin for pyang that creates Python bindings for a YANG model.
Other
204 stars 121 forks source link

Using XPath to set/modify nodes #252

Closed knollpoi closed 9 months ago

knollpoi commented 5 years ago

I am integrating with a well-known Netconf server implementation. That server supplies XPath strings to my code when an action is taken in the module/subtree of interest to indicate what was changed. I would like to use that XPath string to find the corresponding method in my pyangbind-generated module and then take appropriate action based on the action inidicated by the NC server.

For example, if the NC server indicates that the client added a node, then it would give me a structure sort of like: {'xpath': '/module:container/list[key='keyvalue']/leaf', action: 'create', value: 'somevalue'}, or {'xpath': '/module:container/list[key='keyvalue']/leaf', action: 'modify', value: 'somenewvalue'}, or {'xpath': '/module:container/list[key='keyvalue']/leaf', action: 'delete'}, or even {'xpath': '/module:container/list[key='keyvalue']', action: 'delete'}

I see in the documentation that XPathHelper allows the user to get values based on a supplied XPath, but could it (and how) provide a way to modify/create/delete nodes in the tree based on the supplied XPath?

Thanks

JoseIgnacioTamayo commented 9 months ago

Maybe the examples in https://github.com/robshakir/pyangbind/blob/master/docs/xpathhelper.md can help.