Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscription: return parent node to oper_state callback #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sysrepo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ def subscribe_module_change_unsafe(
* netconf_id: the NETCONF session ID set for the event originator
sysrepo session
* user: the effective username of the event originator sysrepo session
* parent_xpath: XPath to an existing parent of the requested nodes. It is
None for top-level nodes. Caller is supposed to append the requested
nodes to this data subtree and return either the original parent or a
top-level node.

The callback is expected to return a python dictionary containing the operational
data. The dictionary should be in the libyang "dict" format. It will be parsed to a
Expand Down
5 changes: 5 additions & 0 deletions sysrepo/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,14 @@ def oper_data_callback(session, sub_id, module, xpath, req_xpath, req_id, parent
callback = subscription.callback
private_data = subscription.private_data
if subscription.extra_info:
parent_xpath = None
if parent[0]:
with session.get_ly_ctx() as ly_ctx:
parent_xpath = DNode.new(ly_ctx, parent[0]).path()
extra_info = {
"netconf_id": session.get_netconf_id(),
"user": session.get_user(),
"parent_xpath": parent_xpath,
}
else:
extra_info = {}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_subs_oper.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ def oper_data_cb(xpath, private_data, **kwargs):
self.assertEqual(getpass.getuser(), kwargs["user"])
self.assertIn("netconf_id", kwargs)
self.assertEqual(kwargs["netconf_id"], 12)
self.assertIn("parent_xpath", kwargs)
self.assertIsNone(kwargs["parent_xpath"])
calls.append((xpath, private_data, kwargs))
return {"state": {}}

Expand Down
Loading