@@ -121,6 +121,30 @@ def set_error(self, xpath: Optional[str], message: str):
121
121
lib .sr_set_error , self .cdata , str2c (xpath ), str2c ("%s" ), str2c (message )
122
122
)
123
123
124
+ def get_netconf_id (self ) -> int :
125
+ """
126
+ It can only be called on an implicit sysrepo.Session (i.e., it can only be
127
+ called from an event callback)
128
+
129
+ :returns: the NETCONF session ID set for the event originator sysrepo session
130
+ """
131
+ if not self .is_implicit :
132
+ raise SysrepoUnsupportedError (
133
+ "can only report netconf id on implicit sessions"
134
+ )
135
+ return lib .sr_session_get_event_nc_id (self .cdata )
136
+
137
+ def get_user (self ) -> str :
138
+ """
139
+ It can only be called on an implicit sysrepo.Session (i.e., it can only be
140
+ called from an event callback)
141
+
142
+ :returns: the effective username of the event originator sysrepo session
143
+ """
144
+ if not self .is_implicit :
145
+ raise SysrepoUnsupportedError ("can only report user on implicit sessions" )
146
+ return c2str (lib .sr_session_get_event_user (self .cdata ))
147
+
124
148
def get_ly_ctx (self ) -> libyang .Context :
125
149
"""
126
150
:returns:
@@ -152,6 +176,13 @@ def get_ly_ctx(self) -> libyang.Context:
152
176
have changed.
153
177
:arg private_data:
154
178
Private context opaque to sysrepo used when subscribing.
179
+ :arg kwargs (optional):
180
+ If the callback was registered with the argument extra_info=True (see
181
+ Session.subscribe_module_change), then extra keyword arguments are passed when
182
+ calling the callback:
183
+ * netconf_id: the NETCONF session ID set for the event originator
184
+ sysrepo session
185
+ * user: the effective username of the event originator sysrepo session
155
186
156
187
When event is one of ("update", "change"), if the callback raises an exception, the
157
188
changes will be rejected and the error will be forwarded to the client that made the
@@ -174,7 +205,8 @@ def subscribe_module_change(
174
205
enabled : bool = False ,
175
206
private_data : Any = None ,
176
207
asyncio_register : bool = False ,
177
- include_implicit_defaults : bool = True
208
+ include_implicit_defaults : bool = True ,
209
+ extra_info : bool = False
178
210
) -> None :
179
211
"""
180
212
Subscribe for changes made in the specified module.
@@ -210,6 +242,10 @@ def subscribe_module_change(
210
242
monitored read file descriptors. Implies `no_thread=True`.
211
243
:arg include_implicit_defaults:
212
244
Include implicit default nodes in changes.
245
+ :arg extra_info:
246
+ When True, the given callback is called with extra keyword arguments
247
+ containing extra information of the sysrepo session that gave origin to the
248
+ event (see ModuleChangeCallbackType for more details)
213
249
"""
214
250
if self .is_implicit :
215
251
raise SysrepoUnsupportedError ("cannot subscribe with implicit sessions" )
@@ -220,6 +256,7 @@ def subscribe_module_change(
220
256
private_data ,
221
257
asyncio_register = asyncio_register ,
222
258
include_implicit_defaults = include_implicit_defaults ,
259
+ extra_info = extra_info ,
223
260
)
224
261
sub_p = ffi .new ("sr_subscription_ctx_t **" )
225
262
@@ -253,6 +290,13 @@ def subscribe_module_change(
253
290
module operational data.
254
291
:arg private_data:
255
292
Private context opaque to sysrepo used when subscribing.
293
+ :arg kwargs (optional):
294
+ If the callback was registered with the argument extra_info=True (see
295
+ Session.subscribe_module_change), then extra keyword arguments are passed when
296
+ calling the callback:
297
+ * netconf_id: the NETCONF session ID set for the event originator
298
+ sysrepo session
299
+ * user: the effective username of the event originator sysrepo session
256
300
257
301
The callback is expected to return a python dictionary containing the operational
258
302
data. The dictionary should be in the libyang "dict" format. It will be parsed to a
@@ -272,7 +316,8 @@ def subscribe_oper_data_request(
272
316
no_thread : bool = False ,
273
317
private_data : Any = None ,
274
318
asyncio_register : bool = False ,
275
- strict : bool = False
319
+ strict : bool = False ,
320
+ extra_info : bool = False
276
321
) -> None :
277
322
"""
278
323
Register for providing operational data at the given xpath.
@@ -296,13 +341,21 @@ def subscribe_oper_data_request(
296
341
:arg strict:
297
342
Reject the whole data returned by callback if it contains elements without
298
343
schema definition.
344
+ :arg extra_info:
345
+ When True, the given callback is called with extra keyword arguments
346
+ containing extra information of the sysrepo session that gave origin to the
347
+ event (see OperDataCallbackType for more details)
299
348
"""
300
349
if self .is_implicit :
301
350
raise SysrepoUnsupportedError ("cannot subscribe with implicit sessions" )
302
351
_check_subscription_callback (callback , self .OperDataCallbackType )
303
352
304
353
sub = Subscription (
305
- callback , private_data , asyncio_register = asyncio_register , strict = strict
354
+ callback ,
355
+ private_data ,
356
+ asyncio_register = asyncio_register ,
357
+ strict = strict ,
358
+ extra_info = extra_info ,
306
359
)
307
360
sub_p = ffi .new ("sr_subscription_ctx_t **" )
308
361
@@ -369,6 +422,13 @@ def subscribe_oper_data_request(
369
422
will be called with 'abort'.
370
423
:arg private_data:
371
424
Private context opaque to sysrepo used when subscribing.
425
+ :arg kwargs (optional):
426
+ If the callback was registered with the argument extra_info=True (see
427
+ Session.subscribe_module_change), then extra keyword arguments are passed when
428
+ calling the callback:
429
+ * netconf_id: the NETCONF session ID set for the event originator
430
+ sysrepo session
431
+ * user: the effective username of the event originator sysrepo session
372
432
373
433
The callback is expected to return a python dictionary containing the RPC output
374
434
data. The dictionary should be in the libyang "dict" format and must only contain
@@ -393,7 +453,8 @@ def subscribe_rpc_call(
393
453
private_data : Any = None ,
394
454
asyncio_register : bool = False ,
395
455
strict : bool = False ,
396
- include_implicit_defaults : bool = True
456
+ include_implicit_defaults : bool = True ,
457
+ extra_info : bool = False
397
458
) -> None :
398
459
"""
399
460
Subscribe for the delivery of an RPC/action.
@@ -418,6 +479,10 @@ def subscribe_rpc_call(
418
479
schema definition.
419
480
:arg include_implicit_defaults:
420
481
Include implicit defaults into input parameters passed to callbacks.
482
+ :arg extra_info:
483
+ When True, the given callback is called with extra keyword arguments
484
+ containing extra information of the sysrepo session that gave origin to the
485
+ event (see RpcCallbackType for more details)
421
486
"""
422
487
if self .is_implicit :
423
488
raise SysrepoUnsupportedError ("cannot subscribe with implicit sessions" )
@@ -429,6 +494,7 @@ def subscribe_rpc_call(
429
494
asyncio_register = asyncio_register ,
430
495
strict = strict ,
431
496
include_implicit_defaults = include_implicit_defaults ,
497
+ extra_info = extra_info ,
432
498
)
433
499
sub_p = ffi .new ("sr_subscription_ctx_t **" )
434
500
@@ -480,6 +546,13 @@ def subscribe_rpc_call(
480
546
Timestamp of the notification as an unsigned 32-bits integer.
481
547
:arg private_data:
482
548
Private context opaque to sysrepo used when subscribing.
549
+ :arg kwargs (optional):
550
+ If the callback was registered with the argument extra_info=True (see
551
+ Session.subscribe_module_change), then extra keyword arguments are passed when
552
+ calling the callback:
553
+ * netconf_id: the NETCONF session ID set for the event originator
554
+ sysrepo session
555
+ * user: the effective username of the event originator sysrepo session
483
556
"""
484
557
485
558
def subscribe_notification (
@@ -492,7 +565,8 @@ def subscribe_notification(
492
565
stop_time : int = 0 ,
493
566
no_thread : bool = False ,
494
567
asyncio_register : bool = False ,
495
- private_data : Any = None
568
+ private_data : Any = None ,
569
+ extra_info : bool = False
496
570
) -> None :
497
571
"""
498
572
Subscribe for the delivery of a notification.
@@ -516,6 +590,10 @@ def subscribe_notification(
516
590
read file descriptors. Implies no_thread=True.
517
591
:arg private_data:
518
592
Private context passed to the callback function, opaque to sysrepo.
593
+ :arg extra_info:
594
+ When True, the given callback is called with extra keyword arguments
595
+ containing extra information of the sysrepo session that gave origin to the
596
+ event (see RpcCallbackType for more details)
519
597
"""
520
598
521
599
if self .is_implicit :
@@ -526,6 +604,7 @@ def subscribe_notification(
526
604
callback ,
527
605
private_data ,
528
606
asyncio_register = asyncio_register ,
607
+ extra_info = extra_info ,
529
608
)
530
609
531
610
sub_p = ffi .new ("sr_subscription_ctx_t **" )
0 commit comments