Implementing a non-trivial `subscribe_oper_data_request` callback
mcfvs opened this issue · 2 comments
Hi there!
The examples/
directory contains an example registration of a callback with subscribe_oper_data_request
. However, the example is trivial, and returns some hard-coded data. Is it possible to fetch data from sysrepo as if the callback wasn't there, then modify it before returning?
Initially I thought this can be done with session.get_data()
passing the xpath received as a callback argument, however I either get an empty dict or SysrepoNotFoundError
, so I'm pretty sure I don't know what I'm doing. So I decided to reach directly to you and ask if you can come up with such an example.
Cheers.
Hi,
this is not really how sysrepo is intended to work. You are free to acquire the operational data from whichever source you deem relevant (netlink, read files, network requests, etc.).
oper_data_cb
is supposed to return data related to the yang module for which it has been registered. Fetching oper data from your own callback does not make any sense (chicken & egg problem).
If you need to "rewrite" the operational data from another module and expose it via your own oper_data_callback, you will need to open another session on the operational datastore, fetch data, rewrite it and return it.
I don't think opening of a new session did any difference. But because the data I wanted to modify was the list of modules as defined by ietf-yang-library
I think it will work just fine if I fetch the data right after connecting to sysrepo, store it in a variable, and then register a callback to return this stored data.
Just for the record the issue was that the list of modules contained schema
leaves referring to local disk storage, which is not helpful at all to the client fetching this information, and I thought it's the simplest way to fix that.
I think we can close this issue, thanks for your help.