ConfD User Community

Got exception badly formatted or nonexistent path

I need to fetch oper data from a device via netconfd using low-level cdb apis. However, when I run the below code via cdb.get(), it throws “Got exception badly formatted or nonexistent path (8): bad path” error. Am I doing wrong in passing the xpath?

xpath = "/devices/device/{%s}/live-status/ex1/ex2/ex3/ex4[key = {%d}]/ex5" % (device, slot)                         

running = cdb.get(cdbsock, xpath)

The path is indeed invalid. There are only few ConfD API functions that work with proper XPath expressions, and none of them in the CDB API, the rest use keypaths. Have a look at the section “Using keypaths” in the CDB chapter of the ConfD user guide; in short, you always use syntax like

/path/to/a/list{keyval1 keval2}/subcontainer/leaf

For CDB API you can also use list[n-1] for the n-th instance of the list list. So there are two problems in your keypath: 1. {%s} should immediately follow device, without slash; 2. there are no predicates, if key is the only list key, just write ex4{%d}.

2 Likes

Thanks for your reply. I used maapi context to perform “get” operation.I get error after “live-status” on my container level.

"badly formatted or nonexistent path (8): Bad path element “ex1” after: /devices/device/live-status"

path = “/devices/device{netconfd}/live-status/ex1/ex2/ex3/ex4{0}/running”
running = maapi.get_elem(sock_maapi, th, path)

I think that means that either ex1 is not unique and you need to use a prefix like .../live-status/modprefix:ex1/..., or your device model has not been properly loaded by the system.

You might make things a bit easier for you if you use so-called high-level Python API and maagic API; I think you are using NSO - in that case check the corresponding chapters in NSO Development guide.

If things are set up correctly, something like the following should return True:

from ncs import maapi

with maapi.single_read_trans('admin', 'system') as tp:
    root = maagic.get_root(tp)
    device = root.devices.device['netconfd']
    'ex1' in [c._name for c in device.live_status._children.get_children()]

(Note that the code is using attributes _children or _name that should be used only for debugging.)

1 Like

Yes you are right, the device modules were not fully loaded. Working fine now. Thanks a ton! :smiley: