diff --git a/sysrepo/session.py b/sysrepo/session.py index 79c3493..f0ed440 100644 --- a/sysrepo/session.py +++ b/sysrepo/session.py @@ -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 diff --git a/sysrepo/subscription.py b/sysrepo/subscription.py index 342adfb..d2c9588 100644 --- a/sysrepo/subscription.py +++ b/sysrepo/subscription.py @@ -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 = {} diff --git a/tests/test_subs_oper.py b/tests/test_subs_oper.py index c16a2a3..d58f365 100644 --- a/tests/test_subs_oper.py +++ b/tests/test_subs_oper.py @@ -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": {}}