08-17-2020 10:20 AM
Given a Maagic "Node" object, I need to automatically generate an xpath to it.
I know NSO can already do this, as it generates xpaths when running "show full-configuration foo bar | display xpath". Is there any way to do this using NSO's Python API?
I know I can get the keypath to the node using the "_path" attribute, but that value can't be saved in a leaf with the "instance-identifier" type, as it has to be an xpath.
Solved! Go to Solution.
08-17-2020 10:53 AM
You can use _ncs.xpath_pp_kpath for this.
08-17-2020 10:53 AM
You can use _ncs.xpath_pp_kpath for this.
08-18-2020 01:24 AM - edited 08-18-2020 04:30 AM
That sounds ideal, but there is one issue: It requires a HKeypathRef object, but all I get from node._path is a string. Is there some way to convert a string to a HKeypathRef object, or can I get a HKeypathRef from a Maagic node somehow?
08-19-2020 11:13 AM
This is one way to get it, although I do think it is not quite elegant:
def maagic_node_to_xpath(maagic_node): with ncs.maapi.single_read_trans('admin', 'system') as m: m.cd(maagic_node._path) return _ncs.xpath_pp_kpath(m.getcwd_kpath())
"getcwd_kpath" returns the current position in maapi, as a HKeypathRef. So, you first 'cd' to the required path, then get it's HKeypathRef using which you get the XPath.
/Ram
01-31-2023 11:06 PM
Is there any restconf equivalent call to get the service configs in xpath format?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide