scrapli 2.0.0a0__py3-none-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
scrapli/netconf.py ADDED
@@ -0,0 +1,2804 @@
1
+ """scrapli.netconf"""
2
+
3
+ from collections.abc import Callable
4
+ from ctypes import c_bool, c_char_p, c_int, c_uint, c_uint64
5
+ from dataclasses import dataclass, field
6
+ from enum import Enum
7
+ from logging import getLogger
8
+ from types import TracebackType
9
+ from typing import Any
10
+
11
+ from scrapli.auth import Options as AuthOptions
12
+ from scrapli.exceptions import (
13
+ AllocationException,
14
+ CloseException,
15
+ GetResultException,
16
+ NoMessagesException,
17
+ NotOpenedException,
18
+ OpenException,
19
+ OperationException,
20
+ OptionsException,
21
+ SubmitOperationException,
22
+ )
23
+ from scrapli.ffi_mapping import LibScrapliMapping
24
+ from scrapli.ffi_types import (
25
+ CancelPointer,
26
+ DriverPointer,
27
+ IntPointer,
28
+ LogFuncCallback,
29
+ OperationIdPointer,
30
+ U64Pointer,
31
+ ZigSlice,
32
+ to_c_string,
33
+ )
34
+ from scrapli.helper import (
35
+ wait_for_available_operation_result,
36
+ wait_for_available_operation_result_async,
37
+ )
38
+ from scrapli.netconf_decorators import handle_operation_timeout, handle_operation_timeout_async
39
+ from scrapli.netconf_result import Result
40
+ from scrapli.session import Options as SessionOptions
41
+ from scrapli.transport import Options as TransportOptions
42
+
43
+
44
+ class Version(str, Enum):
45
+ """
46
+ Enum representing a netconf version
47
+
48
+ Args:
49
+ N/A
50
+
51
+ Returns:
52
+ None
53
+
54
+ Raises:
55
+ N/A
56
+
57
+ """
58
+
59
+ VERSION_1_0 = "1.0"
60
+ VERSION_1_1 = "1.1"
61
+
62
+
63
+ class DatastoreType(str, Enum):
64
+ """
65
+ Enum representing the datastore types
66
+
67
+ Args:
68
+ N/A
69
+
70
+ Returns:
71
+ None
72
+
73
+ Raises:
74
+ N/A
75
+
76
+ """
77
+
78
+ CONVENTIONAL = "conventional"
79
+ RUNNING = "running"
80
+ CANDIDATE = "candidate"
81
+ STARTUP = "startup"
82
+ INTENDED = "intended"
83
+ DYNAMIC = "dynamic"
84
+ OPERATIONAL = "operational"
85
+
86
+
87
+ class FilterType(str, Enum):
88
+ """
89
+ Enum representing a filter type value
90
+
91
+ Args:
92
+ N/A
93
+
94
+ Returns:
95
+ None
96
+
97
+ Raises:
98
+ N/A
99
+
100
+ """
101
+
102
+ SUBTREE = "subtree"
103
+ XPATH = "xpath"
104
+
105
+
106
+ class DefaultsType(str, Enum):
107
+ """
108
+ Enum representing a defaults type value
109
+
110
+ Args:
111
+ N/A
112
+
113
+ Returns:
114
+ None
115
+
116
+ Raises:
117
+ N/A
118
+
119
+ """
120
+
121
+ UNSET = "unset"
122
+ REPORT_ALL = "report-all"
123
+ REPORT_ALL_TAGGED = "report-all-tagged"
124
+ TRIM = "trim"
125
+ EXPLICIT = "explicit"
126
+
127
+
128
+ class SchemaFormat(str, Enum):
129
+ """
130
+ Enum representing valid schema formats
131
+
132
+ Args:
133
+ N/A
134
+
135
+ Returns:
136
+ None
137
+
138
+ Raises:
139
+ N/A
140
+
141
+ """
142
+
143
+ XSD = "xsd"
144
+ YANG = "yang"
145
+ YIN = "yin"
146
+ RNG = "rng"
147
+ RNC = "rnc"
148
+
149
+
150
+ class ConfigFilter(str, Enum):
151
+ """
152
+ Enum representing valid config filter values
153
+
154
+ Args:
155
+ N/A
156
+
157
+ Returns:
158
+ None
159
+
160
+ Raises:
161
+ N/A
162
+
163
+ """
164
+
165
+ UNSET = "unset"
166
+ TRUE = "true"
167
+ FALSE = "false"
168
+
169
+
170
+ @dataclass
171
+ class Options:
172
+ """
173
+ Options holds netconf related options to pass to the ffi layer.
174
+
175
+ Args:
176
+ error_tag: the error tag substring that identifies errors in an rpc reply
177
+ preferred_version: preferred netconf version to use
178
+ message_poll_interval_ns: interval in ns for message polling
179
+ force_close: exists to enable sending "force" on close when using the context manager, this
180
+ option causes the connection to not wait for the result of the close-session rpc. this
181
+ can be useful if the device immediately closes the connection, not sending the "ok"
182
+ reply.
183
+
184
+ Returns:
185
+ None
186
+
187
+ Raises:
188
+ N/A
189
+
190
+ """
191
+
192
+ error_tag: str | None = None
193
+ preferred_version: Version | None = None
194
+ message_poll_interval_ns: int | None = None
195
+ close_force: bool = False
196
+
197
+ _error_tag: c_char_p | None = field(init=False, default=None, repr=False)
198
+ _preferred_version: c_char_p | None = field(init=False, default=None, repr=False)
199
+
200
+ def apply(self, ffi_mapping: LibScrapliMapping, ptr: DriverPointer) -> None:
201
+ """
202
+ Applies the options to the given driver pointer.
203
+
204
+ Should not be called directly/by users.
205
+
206
+ Args:
207
+ ffi_mapping: the handle to the ffi mapping singleton
208
+ ptr: the pointer to the underlying cli or netconf object
209
+
210
+ Returns:
211
+ None
212
+
213
+ Raises:
214
+ OptionsException: if any option apply returns a non-zero return code.
215
+
216
+ """
217
+ if self.error_tag is not None:
218
+ self._error_tag = to_c_string(self.error_tag)
219
+
220
+ status = ffi_mapping.options_mapping.netconf.set_error_tag(ptr, self._error_tag)
221
+ if status != 0:
222
+ raise OptionsException("failed to set netconf error tag")
223
+
224
+ if self.preferred_version is not None:
225
+ self._preferred_version = to_c_string(self.preferred_version)
226
+
227
+ status = ffi_mapping.options_mapping.netconf.set_preferred_version(
228
+ ptr, self._preferred_version
229
+ )
230
+ if status != 0:
231
+ raise OptionsException("failed to set netconf preferred version")
232
+
233
+ if self.message_poll_interval_ns is not None:
234
+ status = ffi_mapping.options_mapping.netconf.set_message_poll_interva_ns(
235
+ ptr, c_int(self.message_poll_interval_ns)
236
+ )
237
+ if status != 0:
238
+ raise OptionsException("failed to set netconf message poll interval")
239
+
240
+ def __repr__(self) -> str:
241
+ """
242
+ Magic repr method for Options object
243
+
244
+ Args:
245
+ N/A
246
+
247
+ Returns:
248
+ str: repr for Options object
249
+
250
+ Raises:
251
+ N/A
252
+
253
+ """
254
+ return (
255
+ # it will probably be "canonical" to import Options as NetconfOptions, so we'll make
256
+ # the repr do that too
257
+ f"Netconf{self.__class__.__name__}("
258
+ f"error_tag={self.error_tag!r}, "
259
+ f"preferred_version={self.preferred_version!r} "
260
+ f"message_poll_interval_ns={self.message_poll_interval_ns!r})"
261
+ f"close_force={self.close_force!r})"
262
+ )
263
+
264
+
265
+ class Netconf:
266
+ """
267
+ Netconf represents a netconf connection object.
268
+
269
+ Args:
270
+ N/A
271
+
272
+ Returns:
273
+ None
274
+
275
+ Raises:
276
+ N/A
277
+
278
+ """
279
+
280
+ def __init__( # noqa: PLR0913
281
+ self,
282
+ host: str,
283
+ *,
284
+ logger_callback: Callable[[int, str], None] | None = None,
285
+ port: int = 830,
286
+ options: Options | None = None,
287
+ auth_options: AuthOptions | None = None,
288
+ session_options: SessionOptions | None = None,
289
+ transport_options: TransportOptions | None = None,
290
+ logging_uid: str | None = None,
291
+ ) -> None:
292
+ logger_name = f"{__name__}.{host}:{port}"
293
+ if logging_uid is not None:
294
+ logger_name += f":{logging_uid}"
295
+
296
+ self.logger = getLogger(logger_name)
297
+ self._logging_uid = logging_uid
298
+
299
+ self.ffi_mapping = LibScrapliMapping()
300
+
301
+ self.host = host
302
+ self._host = to_c_string(host)
303
+
304
+ self.logger_callback = (
305
+ LogFuncCallback(logger_callback) if logger_callback else LogFuncCallback(0)
306
+ )
307
+ self._logger_callback = logger_callback
308
+
309
+ self.port = port
310
+
311
+ self.options = options or Options()
312
+ self.auth_options = auth_options or AuthOptions()
313
+ self.session_options = session_options or SessionOptions()
314
+ self.transport_options = transport_options or TransportOptions()
315
+
316
+ self.ptr: DriverPointer | None = None
317
+ self._session_id: int | None = None
318
+
319
+ def __enter__(self: "Netconf") -> "Netconf":
320
+ """
321
+ Enter method for context manager
322
+
323
+ Args:
324
+ N/A
325
+
326
+ Returns:
327
+ Cli: a concrete implementation of the opened Cli object
328
+
329
+ Raises:
330
+ ScrapliConnectionError: if an exception occurs during opening
331
+
332
+ """
333
+ self.open()
334
+
335
+ return self
336
+
337
+ def __exit__(
338
+ self,
339
+ exception_type: BaseException | None,
340
+ exception_value: BaseException | None,
341
+ traceback: TracebackType | None,
342
+ ) -> None:
343
+ """
344
+ Exit method to cleanup for context manager
345
+
346
+ Args:
347
+ exception_type: exception type being raised
348
+ exception_value: message from exception being raised
349
+ traceback: traceback from exception being raised
350
+
351
+ Returns:
352
+ None
353
+
354
+ Raises:
355
+ N/A
356
+
357
+ """
358
+ self.close(
359
+ force=self.options.close_force,
360
+ )
361
+
362
+ async def __aenter__(self: "Netconf") -> "Netconf":
363
+ """
364
+ Enter method for context manager.
365
+
366
+ Args:
367
+ N/A
368
+
369
+ Returns:
370
+ Netconf: a concrete implementation of the opened Netconf object
371
+
372
+ Raises:
373
+ N/A
374
+
375
+ """
376
+ await self.open_async()
377
+
378
+ return self
379
+
380
+ async def __aexit__(
381
+ self,
382
+ exception_type: BaseException | None,
383
+ exception_value: BaseException | None,
384
+ traceback: TracebackType | None,
385
+ ) -> None:
386
+ """
387
+ Exit method to cleanup for context manager.
388
+
389
+ Args:
390
+ exception_type: exception type being raised
391
+ exception_value: message from exception being raised
392
+ traceback: traceback from exception being raised
393
+
394
+ Returns:
395
+ None
396
+
397
+ Raises:
398
+ N/A
399
+
400
+ """
401
+ await self.close_async(
402
+ force=self.options.close_force,
403
+ )
404
+
405
+ def __str__(self) -> str:
406
+ """
407
+ Magic str method for Netconf object.
408
+
409
+ Args:
410
+ N/A
411
+
412
+ Returns:
413
+ str: str representation of Netconf
414
+
415
+ Raises:
416
+ N/A
417
+
418
+ """
419
+ return f"scrapli.Netconf {self.host}:{self.port}"
420
+
421
+ def __repr__(self) -> str:
422
+ """
423
+ Magic repr method for Netconf object.
424
+
425
+ Args:
426
+ N/A
427
+
428
+ Returns:
429
+ str: repr for Netconf object
430
+
431
+ Raises:
432
+ N/A
433
+
434
+ """
435
+ return (
436
+ f"{self.__class__.__name__}("
437
+ f"host={self.host!r}, "
438
+ f"port={self.port!r}, "
439
+ f"options={self.options!r} "
440
+ f"auth_options={self.auth_options!r} "
441
+ f"session_options={self.auth_options!r} "
442
+ f"transport_options={self.transport_options!r}) "
443
+ )
444
+
445
+ def __copy__(self, memodict: dict[Any, Any] = {}) -> "Netconf":
446
+ # reasonably safely copy of the object... *reasonably*... basically assumes that options
447
+ # will never be mutated during an objects lifetime, which *should* be the case. probably.
448
+ return Netconf(
449
+ host=self.host,
450
+ logger_callback=self._logger_callback,
451
+ port=self.port,
452
+ options=self.options,
453
+ auth_options=self.auth_options,
454
+ session_options=self.session_options,
455
+ transport_options=self.transport_options,
456
+ logging_uid=self._logging_uid,
457
+ )
458
+
459
+ def _ptr_or_exception(self) -> DriverPointer:
460
+ if self.ptr is None:
461
+ raise NotOpenedException
462
+
463
+ return self.ptr
464
+
465
+ def _alloc(
466
+ self,
467
+ ) -> None:
468
+ ptr = self.ffi_mapping.netconf_mapping.alloc(
469
+ logger_callback=self.logger_callback,
470
+ host=self._host,
471
+ port=c_int(self.port),
472
+ transport_kind=c_char_p(self.transport_options.get_transport_kind()),
473
+ )
474
+ if ptr == 0: # type: ignore[comparison-overlap]
475
+ raise AllocationException("failed to allocate netconf")
476
+
477
+ self.ptr = ptr
478
+
479
+ poll_fd = int(
480
+ self.ffi_mapping.shared_mapping.get_poll_fd(
481
+ ptr=self._ptr_or_exception(),
482
+ )
483
+ )
484
+ if poll_fd == 0:
485
+ raise AllocationException("failed to allocate netconf")
486
+
487
+ self.poll_fd = poll_fd
488
+
489
+ def _free(
490
+ self,
491
+ ) -> None:
492
+ self.ffi_mapping.shared_mapping.free(ptr=self._ptr_or_exception())
493
+
494
+ def _open(self) -> c_uint:
495
+ self._alloc()
496
+
497
+ self.options.apply(self.ffi_mapping, self._ptr_or_exception())
498
+ self.auth_options.apply(self.ffi_mapping, self._ptr_or_exception())
499
+ self.session_options.apply(self.ffi_mapping, self._ptr_or_exception())
500
+ self.transport_options.apply(self.ffi_mapping, self._ptr_or_exception())
501
+
502
+ operation_id = OperationIdPointer(c_uint(0))
503
+ cancel = CancelPointer(c_bool(False))
504
+
505
+ status = self.ffi_mapping.netconf_mapping.open(
506
+ ptr=self._ptr_or_exception(),
507
+ operation_id=operation_id,
508
+ cancel=cancel,
509
+ )
510
+ if status != 0:
511
+ self._free()
512
+
513
+ raise OpenException("failed to submit open operation")
514
+
515
+ # cast it again, for mypy reasons
516
+ return c_uint(operation_id.contents.value)
517
+
518
+ def open(
519
+ self,
520
+ ) -> Result:
521
+ """
522
+ Open the netconf connection.
523
+
524
+ Args:
525
+ N/A
526
+
527
+ Returns:
528
+ None
529
+
530
+ Raises:
531
+ OpenException: if the operation fails
532
+
533
+ """
534
+ operation_id = self._open()
535
+
536
+ return self._get_result(operation_id=operation_id)
537
+
538
+ async def open_async(self) -> Result:
539
+ """
540
+ Open the netconf connection.
541
+
542
+ Args:
543
+ N/A
544
+
545
+ Returns:
546
+ None
547
+
548
+ Raises:
549
+ OpenException: if the operation fails
550
+
551
+ """
552
+ operation_id = self._open()
553
+
554
+ return await self._get_result_async(operation_id=operation_id)
555
+
556
+ def _close(
557
+ self,
558
+ force: bool,
559
+ ) -> c_uint:
560
+ operation_id = OperationIdPointer(c_uint(0))
561
+ cancel = CancelPointer(c_bool(False))
562
+ _force = c_bool(force)
563
+
564
+ status = self.ffi_mapping.netconf_mapping.close(
565
+ ptr=self._ptr_or_exception(),
566
+ operation_id=operation_id,
567
+ cancel=cancel,
568
+ force=_force,
569
+ )
570
+ if status != 0:
571
+ raise CloseException("submitting close operation")
572
+
573
+ return c_uint(operation_id.contents.value)
574
+
575
+ def close(
576
+ self,
577
+ *,
578
+ force: bool = False,
579
+ ) -> Result:
580
+ """
581
+ Close the netconf connection.
582
+
583
+ Args:
584
+ force: skips sending a close-session rpc and just directly shuts down the connection
585
+
586
+ Returns:
587
+ None
588
+
589
+ Raises:
590
+ NotOpenedException: if the ptr to the netconf object is None (via _ptr_or_exception)
591
+ CloseException: if the operation fails
592
+
593
+ """
594
+ operation_id = self._close(force=force)
595
+
596
+ result = self._get_result(operation_id=operation_id)
597
+
598
+ self._free()
599
+
600
+ return result
601
+
602
+ async def close_async(
603
+ self,
604
+ *,
605
+ force: bool = False,
606
+ ) -> Result:
607
+ """
608
+ Close the netconf connection.
609
+
610
+ Args:
611
+ force: skips sending a close-session rpc and just directly shuts down the connection
612
+
613
+ Returns:
614
+ None
615
+
616
+ Raises:
617
+ NotOpenedException: if the ptr to the netconf object is None (via _ptr_or_exception)
618
+ CloseException: if the operation fails
619
+
620
+ """
621
+ operation_id = self._close(force=force)
622
+
623
+ result = await self._get_result_async(operation_id=operation_id)
624
+
625
+ self._free()
626
+
627
+ return result
628
+
629
+ def _get_result(
630
+ self,
631
+ operation_id: c_uint,
632
+ ) -> Result:
633
+ wait_for_available_operation_result(self.poll_fd)
634
+
635
+ input_size = IntPointer(c_int())
636
+ result_raw_size = IntPointer(c_int())
637
+ result_size = IntPointer(c_int())
638
+ rpc_warnings_size = IntPointer(c_int())
639
+ rpc_errors_size = IntPointer(c_int())
640
+ err_size = IntPointer(c_int())
641
+
642
+ status = self.ffi_mapping.netconf_mapping.fetch_sizes(
643
+ ptr=self._ptr_or_exception(),
644
+ operation_id=operation_id,
645
+ input_size=input_size,
646
+ result_raw_size=result_raw_size,
647
+ result_size=result_size,
648
+ rpc_warnings_size=rpc_warnings_size,
649
+ rpc_errors_size=rpc_errors_size,
650
+ err_size=err_size,
651
+ )
652
+ if status != 0:
653
+ raise GetResultException("wait operation failed")
654
+
655
+ start_time = U64Pointer(c_uint64())
656
+ end_time = U64Pointer(c_uint64())
657
+
658
+ input_slice = ZigSlice(size=input_size.contents)
659
+ result_raw_slice = ZigSlice(size=result_raw_size.contents)
660
+ result_slice = ZigSlice(size=result_size.contents)
661
+
662
+ rpc_warnings_slice = ZigSlice(size=rpc_warnings_size.contents)
663
+ rpc_errors_slice = ZigSlice(size=rpc_errors_size.contents)
664
+ err_slice = ZigSlice(size=err_size.contents)
665
+
666
+ status = self.ffi_mapping.netconf_mapping.fetch(
667
+ ptr=self._ptr_or_exception(),
668
+ operation_id=operation_id,
669
+ start_time=start_time,
670
+ end_time=end_time,
671
+ input_slice=input_slice,
672
+ result_raw_slice=result_raw_slice,
673
+ result_slice=result_slice,
674
+ rpc_warnings_slice=rpc_warnings_slice,
675
+ rpc_errors_slice=rpc_errors_slice,
676
+ err_slice=err_slice,
677
+ )
678
+ if status != 0:
679
+ raise GetResultException("fetch operation failed")
680
+
681
+ err_contents = err_slice.get_decoded_contents()
682
+ if err_contents:
683
+ raise OperationException(err_contents)
684
+
685
+ return Result(
686
+ input_=input_slice.get_decoded_contents(),
687
+ host=self.host,
688
+ port=self.port,
689
+ start_time=start_time.contents.value,
690
+ end_time=end_time.contents.value,
691
+ result_raw=result_raw_slice.get_contents(),
692
+ result=result_slice.get_decoded_contents(),
693
+ rpc_warnings=rpc_warnings_slice.get_decoded_contents(),
694
+ rpc_errors=rpc_errors_slice.get_decoded_contents(),
695
+ )
696
+
697
+ async def _get_result_async(
698
+ self,
699
+ operation_id: c_uint,
700
+ ) -> Result:
701
+ await wait_for_available_operation_result_async(fd=self.poll_fd)
702
+
703
+ input_size = IntPointer(c_int())
704
+ result_raw_size = IntPointer(c_int())
705
+ result_size = IntPointer(c_int())
706
+ rpc_warnings_size = IntPointer(c_int())
707
+ rpc_errors_size = IntPointer(c_int())
708
+ err_size = IntPointer(c_int())
709
+
710
+ status = self.ffi_mapping.netconf_mapping.fetch_sizes(
711
+ ptr=self._ptr_or_exception(),
712
+ operation_id=operation_id,
713
+ input_size=input_size,
714
+ result_raw_size=result_raw_size,
715
+ result_size=result_size,
716
+ rpc_warnings_size=rpc_warnings_size,
717
+ rpc_errors_size=rpc_errors_size,
718
+ err_size=err_size,
719
+ )
720
+ if status != 0:
721
+ raise GetResultException("fetch operation sizes failed")
722
+
723
+ start_time = U64Pointer(c_uint64())
724
+ end_time = U64Pointer(c_uint64())
725
+
726
+ input_slice = ZigSlice(size=input_size.contents)
727
+ result_raw_slice = ZigSlice(size=result_raw_size.contents)
728
+ result_slice = ZigSlice(size=result_size.contents)
729
+
730
+ rpc_warnings_slice = ZigSlice(size=rpc_warnings_size.contents)
731
+ rpc_errors_slice = ZigSlice(size=rpc_errors_size.contents)
732
+ err_slice = ZigSlice(size=err_size.contents)
733
+
734
+ status = self.ffi_mapping.netconf_mapping.fetch(
735
+ ptr=self._ptr_or_exception(),
736
+ operation_id=operation_id,
737
+ start_time=start_time,
738
+ end_time=end_time,
739
+ input_slice=input_slice,
740
+ result_raw_slice=result_raw_slice,
741
+ result_slice=result_slice,
742
+ rpc_warnings_slice=rpc_warnings_slice,
743
+ rpc_errors_slice=rpc_errors_slice,
744
+ err_slice=err_slice,
745
+ )
746
+ if status != 0:
747
+ raise GetResultException("fetch operation failed")
748
+
749
+ err_contents = err_slice.get_decoded_contents()
750
+ if err_contents:
751
+ raise OperationException(err_contents)
752
+
753
+ return Result(
754
+ input_=input_slice.get_decoded_contents(),
755
+ host=self.host,
756
+ port=self.port,
757
+ start_time=start_time.contents.value,
758
+ end_time=end_time.contents.value,
759
+ result_raw=result_raw_slice.get_contents(),
760
+ result=result_slice.get_decoded_contents(),
761
+ rpc_warnings=rpc_warnings_slice.get_decoded_contents(),
762
+ rpc_errors=rpc_errors_slice.get_decoded_contents(),
763
+ )
764
+
765
+ @property
766
+ def session_id(self) -> int:
767
+ """
768
+ Get the session id of the connection.
769
+
770
+ Args:
771
+ N/A
772
+
773
+ Returns:
774
+ int: session id of the connection
775
+
776
+ Raises:
777
+ GetResultException: if fetching the session id fails
778
+
779
+ """
780
+ if self._session_id is not None:
781
+ return self._session_id
782
+
783
+ session_id = IntPointer(c_int())
784
+
785
+ status = self.ffi_mapping.netconf_mapping.get_session_id(
786
+ ptr=self._ptr_or_exception(), session_id=session_id
787
+ )
788
+ if status != 0:
789
+ raise GetResultException("fetch session id failed")
790
+
791
+ self._session_id = session_id.contents.value
792
+
793
+ return self._session_id
794
+
795
+ def get_subscription_id(self, payload: str) -> int:
796
+ """
797
+ Get the subscription id from a rpc-reply (from an establish-subscription rpc).
798
+
799
+ Args:
800
+ payload: the payload to find the subscription id in
801
+
802
+ Returns:
803
+ int: subscription id
804
+
805
+ Raises:
806
+ N/A
807
+
808
+ """
809
+ _payload = to_c_string(payload)
810
+ subscription_id = U64Pointer(c_uint64())
811
+
812
+ status = self.ffi_mapping.netconf_mapping.get_subscription_id(
813
+ payload=_payload,
814
+ subscription_id=subscription_id,
815
+ )
816
+ if status != 0:
817
+ raise GetResultException("fetch subscriptiond id failed")
818
+
819
+ return int(subscription_id.contents.value)
820
+
821
+ def get_next_notification(
822
+ self,
823
+ ) -> str:
824
+ """
825
+ Fetch the next notification message if available.
826
+
827
+ Args:
828
+ N/A
829
+
830
+ Returns:
831
+ str: the string content of the next notification
832
+
833
+ Raises:
834
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
835
+ SubmitOperationException: if the operation fails
836
+ NoMessagesException: if there are no notifications to fetch
837
+
838
+ """
839
+ notification_size = U64Pointer(c_uint64())
840
+
841
+ self.ffi_mapping.netconf_mapping.get_next_notification_size(
842
+ ptr=self._ptr_or_exception(),
843
+ notification_size=notification_size,
844
+ )
845
+
846
+ if notification_size.contents == 0:
847
+ raise NoMessagesException("no notification messages available")
848
+
849
+ notification_slice = ZigSlice(size=notification_size.contents)
850
+
851
+ status = self.ffi_mapping.netconf_mapping.get_next_notification(
852
+ ptr=self._ptr_or_exception(),
853
+ notification_slice=notification_slice,
854
+ )
855
+ if status != 0:
856
+ raise SubmitOperationException("submitting getting next notification failed")
857
+
858
+ return notification_slice.get_decoded_contents()
859
+
860
+ def get_next_subscription(
861
+ self,
862
+ subscription_id: int,
863
+ ) -> str:
864
+ """
865
+ Fetch the next notification message if available.
866
+
867
+ Args:
868
+ subscription_id: subscription id to fetch a message for
869
+
870
+ Returns:
871
+ str: the string content of the next notification
872
+
873
+ Raises:
874
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
875
+ SubmitOperationException: if the operation fails
876
+ NoMessagesException: if there are no notifications to fetch
877
+
878
+ """
879
+ subscription_size = U64Pointer(c_uint64())
880
+
881
+ self.ffi_mapping.netconf_mapping.get_next_subscription_size(
882
+ ptr=self._ptr_or_exception(),
883
+ subscription_id=c_uint64(subscription_id),
884
+ subscription_size=subscription_size,
885
+ )
886
+
887
+ if subscription_size.contents == 0:
888
+ raise NoMessagesException(
889
+ f"no subscription messages available for subscription id {subscription_id}",
890
+ )
891
+
892
+ subscription_slice = ZigSlice(size=subscription_size.contents)
893
+
894
+ status = self.ffi_mapping.netconf_mapping.get_next_subscription(
895
+ ptr=self._ptr_or_exception(),
896
+ subscription_id=c_uint64(subscription_id),
897
+ subscription_slice=subscription_slice,
898
+ )
899
+ if status != 0:
900
+ raise SubmitOperationException("submitting getting next subscription failed")
901
+
902
+ return subscription_slice.get_decoded_contents()
903
+
904
+ def _raw_rpc(
905
+ self,
906
+ *,
907
+ operation_id: OperationIdPointer,
908
+ cancel: CancelPointer,
909
+ payload: c_char_p,
910
+ base_namespace_prefix: c_char_p,
911
+ extra_namespaces: c_char_p,
912
+ ) -> c_uint:
913
+ status = self.ffi_mapping.netconf_mapping.raw_rpc(
914
+ ptr=self._ptr_or_exception(),
915
+ operation_id=operation_id,
916
+ cancel=cancel,
917
+ payload=payload,
918
+ base_namespace_prefix=base_namespace_prefix,
919
+ extra_namespaces=extra_namespaces,
920
+ )
921
+ if status != 0:
922
+ raise SubmitOperationException("submitting raw rpc operation failed")
923
+
924
+ return c_uint(operation_id.contents.value)
925
+
926
+ @handle_operation_timeout
927
+ def raw_rpc(
928
+ self,
929
+ payload: str,
930
+ *,
931
+ base_namespace_prefix: str = "",
932
+ extra_namespaces: list[tuple[str, str]] | None = None,
933
+ operation_timeout_ns: int | None = None,
934
+ ) -> Result:
935
+ """
936
+ Execute a "raw" / user crafted rpc operation.
937
+
938
+ Args:
939
+ payload: the raw rpc payload
940
+ base_namespace_prefix: prefix to use for hte base/default netconf base namespace
941
+ extra_namespaces: optional list of pairs of prefix::namespaces. this plus the base
942
+ namespace prefix can allow for weird cases like nxos where the base namespace must
943
+ be prefixed and then additional namespaces indicating desired targets must be added
944
+ operation_timeout_ns: operation timeout in ns for this operation
945
+
946
+ Returns:
947
+ Result: a Result object representing the operation
948
+
949
+ Raises:
950
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
951
+ SubmitOperationException: if the operation fails
952
+
953
+ """
954
+ # only used in the decorator
955
+ _ = operation_timeout_ns
956
+
957
+ operation_id = OperationIdPointer(c_uint(0))
958
+ cancel = CancelPointer(c_bool(False))
959
+
960
+ _payload = to_c_string(payload)
961
+ _base_namespace_prefix = to_c_string(base_namespace_prefix)
962
+
963
+ if extra_namespaces is not None:
964
+ _extra_namespaces = to_c_string(
965
+ "__libscrapli__".join(["::".join(p) for p in extra_namespaces])
966
+ )
967
+ else:
968
+ _extra_namespaces = to_c_string("")
969
+
970
+ operation_id = self._raw_rpc(
971
+ operation_id=operation_id,
972
+ cancel=cancel,
973
+ payload=_payload,
974
+ base_namespace_prefix=_base_namespace_prefix,
975
+ extra_namespaces=_extra_namespaces,
976
+ )
977
+
978
+ return self._get_result(operation_id=operation_id)
979
+
980
+ @handle_operation_timeout_async
981
+ async def raw_rpc_async(
982
+ self,
983
+ payload: str,
984
+ *,
985
+ base_namespace_prefix: str = "",
986
+ extra_namespaces: list[tuple[str, str]] | None = None,
987
+ operation_timeout_ns: int | None = None,
988
+ ) -> Result:
989
+ """
990
+ Execute a "raw" / user crafted rpc operation.
991
+
992
+ Args:
993
+ payload: the raw rpc payload
994
+ base_namespace_prefix: prefix to use for hte base/default netconf base namespace
995
+ extra_namespaces: optional list of pairs of prefix::namespaces. this plus the base
996
+ namespace prefix can allow for weird cases like nxos where the base namespace must
997
+ be prefixed and then additional namespaces indicating desired targets must be added
998
+ operation_timeout_ns: operation timeout in ns for this operation
999
+
1000
+ Returns:
1001
+ Result: a Result object representing the operation
1002
+
1003
+ Raises:
1004
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1005
+ SubmitOperationException: if the operation fails
1006
+
1007
+ """
1008
+ # only used in the decorator
1009
+ _ = operation_timeout_ns
1010
+
1011
+ operation_id = OperationIdPointer(c_uint(0))
1012
+ cancel = CancelPointer(c_bool(False))
1013
+
1014
+ _payload = to_c_string(payload)
1015
+ _base_namespace_prefix = to_c_string(base_namespace_prefix)
1016
+
1017
+ if extra_namespaces is not None:
1018
+ _extra_namespaces = to_c_string(
1019
+ "__libscrapli__".join(["::".join(p) for p in extra_namespaces])
1020
+ )
1021
+ else:
1022
+ _extra_namespaces = to_c_string("")
1023
+
1024
+ operation_id = self._raw_rpc(
1025
+ operation_id=operation_id,
1026
+ cancel=cancel,
1027
+ payload=_payload,
1028
+ base_namespace_prefix=_base_namespace_prefix,
1029
+ extra_namespaces=_extra_namespaces,
1030
+ )
1031
+
1032
+ return await self._get_result_async(operation_id=operation_id)
1033
+
1034
+ def _get_config( # noqa: PLR0913,too-many-locals
1035
+ self,
1036
+ *,
1037
+ operation_id: OperationIdPointer,
1038
+ cancel: CancelPointer,
1039
+ source: c_char_p,
1040
+ filter_: c_char_p,
1041
+ filter_type: c_char_p,
1042
+ filter_namespace_prefix: c_char_p,
1043
+ filter_namespace: c_char_p,
1044
+ defaults_type: c_char_p,
1045
+ ) -> c_uint:
1046
+ status = self.ffi_mapping.netconf_mapping.get_config(
1047
+ ptr=self._ptr_or_exception(),
1048
+ operation_id=operation_id,
1049
+ cancel=cancel,
1050
+ source=source,
1051
+ filter_=filter_,
1052
+ filter_type=filter_type,
1053
+ filter_namespace_prefix=filter_namespace_prefix,
1054
+ filter_namespace=filter_namespace,
1055
+ defaults_type=defaults_type,
1056
+ )
1057
+ if status != 0:
1058
+ raise SubmitOperationException("submitting get-config operation failed")
1059
+
1060
+ return c_uint(operation_id.contents.value)
1061
+
1062
+ @handle_operation_timeout
1063
+ def get_config( # noqa: PLR0913
1064
+ self,
1065
+ *,
1066
+ source: DatastoreType = DatastoreType.RUNNING,
1067
+ filter_: str = "",
1068
+ filter_type: FilterType = FilterType.SUBTREE,
1069
+ filter_namespace_prefix: str = "",
1070
+ filter_namespace: str = "",
1071
+ defaults_type: DefaultsType = DefaultsType.UNSET,
1072
+ operation_timeout_ns: int | None = None,
1073
+ ) -> Result:
1074
+ """
1075
+ Execute a get-config rpc operation.
1076
+
1077
+ Args:
1078
+ source: source datastore to get config from
1079
+ filter_: filter to apply to the get-config (or not if empty string)
1080
+ filter_type: type of filter to apply, subtree|xpath
1081
+ filter_namespace_prefix: filter namespace prefix
1082
+ filter_namespace: filter namespace
1083
+ defaults_type: defaults type to apply to the get-config, "unset" means dont apply one
1084
+ operation_timeout_ns: operation timeout in ns for this operation
1085
+
1086
+ Returns:
1087
+ Result: a Result object representing the operation
1088
+
1089
+ Raises:
1090
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1091
+ SubmitOperationException: if the operation fails
1092
+
1093
+ """
1094
+ # only used in the decorator
1095
+ _ = operation_timeout_ns
1096
+
1097
+ operation_id = OperationIdPointer(c_uint(0))
1098
+ cancel = CancelPointer(c_bool(False))
1099
+
1100
+ _source = to_c_string(source)
1101
+ _filter = to_c_string(filter_)
1102
+ _filter_type = to_c_string(filter_type)
1103
+ _filter_namespace_prefix = to_c_string(filter_namespace_prefix)
1104
+ _filter_namespace = to_c_string(filter_namespace)
1105
+ _defaults_type = to_c_string(defaults_type)
1106
+
1107
+ operation_id = self._get_config(
1108
+ operation_id=operation_id,
1109
+ cancel=cancel,
1110
+ source=_source,
1111
+ filter_=_filter,
1112
+ filter_type=_filter_type,
1113
+ filter_namespace_prefix=_filter_namespace_prefix,
1114
+ filter_namespace=_filter_namespace,
1115
+ defaults_type=_defaults_type,
1116
+ )
1117
+
1118
+ return self._get_result(operation_id=operation_id)
1119
+
1120
+ @handle_operation_timeout_async
1121
+ async def get_config_async( # noqa: PLR0913
1122
+ self,
1123
+ *,
1124
+ source: DatastoreType = DatastoreType.RUNNING,
1125
+ filter_: str = "",
1126
+ filter_type: FilterType = FilterType.SUBTREE,
1127
+ filter_namespace_prefix: str = "",
1128
+ filter_namespace: str = "",
1129
+ defaults_type: DefaultsType = DefaultsType.UNSET,
1130
+ operation_timeout_ns: int | None = None,
1131
+ ) -> Result:
1132
+ """
1133
+ Execute a get-config rpc operation.
1134
+
1135
+ Args:
1136
+ source: source datastore to get config from
1137
+ filter_: filter to apply to the get-config (or not if empty string)
1138
+ filter_type: type of filter to apply, subtree|xpath
1139
+ filter_namespace_prefix: filter namespace prefix
1140
+ filter_namespace: filter namespace
1141
+ defaults_type: defaults type to apply to the get-config, "unset" means dont apply one
1142
+ operation_timeout_ns: operation timeout in ns for this operation
1143
+
1144
+ Returns:
1145
+ Result: a Result object representing the operation
1146
+
1147
+ Raises:
1148
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1149
+ SubmitOperationException: if the operation fails
1150
+
1151
+ """
1152
+ # only used in the decorator
1153
+ _ = operation_timeout_ns
1154
+
1155
+ operation_id = OperationIdPointer(c_uint(0))
1156
+ cancel = CancelPointer(c_bool(False))
1157
+
1158
+ _source = to_c_string(source)
1159
+ _filter = to_c_string(filter_)
1160
+ _filter_type = to_c_string(filter_type)
1161
+ _filter_namespace_prefix = to_c_string(filter_namespace_prefix)
1162
+ _filter_namespace = to_c_string(filter_namespace)
1163
+ _defaults_type = to_c_string(defaults_type)
1164
+
1165
+ operation_id = self._get_config(
1166
+ operation_id=operation_id,
1167
+ cancel=cancel,
1168
+ source=_source,
1169
+ filter_=_filter,
1170
+ filter_type=_filter_type,
1171
+ filter_namespace_prefix=_filter_namespace_prefix,
1172
+ filter_namespace=_filter_namespace,
1173
+ defaults_type=_defaults_type,
1174
+ )
1175
+
1176
+ return await self._get_result_async(operation_id=operation_id)
1177
+
1178
+ def _edit_config(
1179
+ self,
1180
+ *,
1181
+ operation_id: OperationIdPointer,
1182
+ cancel: CancelPointer,
1183
+ config: c_char_p,
1184
+ target: c_char_p,
1185
+ ) -> c_uint:
1186
+ status = self.ffi_mapping.netconf_mapping.edit_config(
1187
+ ptr=self._ptr_or_exception(),
1188
+ operation_id=operation_id,
1189
+ cancel=cancel,
1190
+ config=config,
1191
+ target=target,
1192
+ )
1193
+ if status != 0:
1194
+ raise SubmitOperationException("submitting edit-config operation failed")
1195
+
1196
+ return c_uint(operation_id.contents.value)
1197
+
1198
+ @handle_operation_timeout
1199
+ def edit_config(
1200
+ self,
1201
+ *,
1202
+ config: str = "",
1203
+ target: DatastoreType = DatastoreType.RUNNING,
1204
+ operation_timeout_ns: int | None = None,
1205
+ ) -> Result:
1206
+ """
1207
+ Execute an edit-config rpc operation.
1208
+
1209
+ Args:
1210
+ config: string config payload to send
1211
+ target: target datastore as DatastoreType enum
1212
+ operation_timeout_ns: optional timeout in ns for this operation
1213
+
1214
+ Returns:
1215
+ Result: a Result object representing the operation
1216
+
1217
+ Raises:
1218
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1219
+ SubmitOperationException: if the operation fails
1220
+
1221
+ """
1222
+ # only used in the decorator
1223
+ _ = operation_timeout_ns
1224
+
1225
+ operation_id = OperationIdPointer(c_uint(0))
1226
+ cancel = CancelPointer(c_bool(False))
1227
+
1228
+ _config = to_c_string(config)
1229
+ _target = to_c_string(target)
1230
+
1231
+ operation_id = self._edit_config(
1232
+ operation_id=operation_id,
1233
+ cancel=cancel,
1234
+ config=_config,
1235
+ target=_target,
1236
+ )
1237
+
1238
+ return self._get_result(operation_id=operation_id)
1239
+
1240
+ @handle_operation_timeout_async
1241
+ async def edit_config_async(
1242
+ self,
1243
+ *,
1244
+ config: str = "",
1245
+ target: DatastoreType = DatastoreType.RUNNING,
1246
+ operation_timeout_ns: int | None = None,
1247
+ ) -> Result:
1248
+ """
1249
+ Execute an edit-config rpc operation.
1250
+
1251
+ Args:
1252
+ config: string config payload to send
1253
+ target: target datastore as DatastoreType enum
1254
+ operation_timeout_ns: optional timeout in ns for this operation
1255
+
1256
+ Returns:
1257
+ Result: a Result object representing the operation
1258
+
1259
+ Raises:
1260
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1261
+ SubmitOperationException: if the operation fails
1262
+
1263
+ """
1264
+ # only used in the decorator
1265
+ _ = operation_timeout_ns
1266
+
1267
+ operation_id = OperationIdPointer(c_uint(0))
1268
+ cancel = CancelPointer(c_bool(False))
1269
+
1270
+ _config = to_c_string(config)
1271
+ _target = to_c_string(target)
1272
+
1273
+ operation_id = self._edit_config(
1274
+ operation_id=operation_id,
1275
+ cancel=cancel,
1276
+ config=_config,
1277
+ target=_target,
1278
+ )
1279
+
1280
+ return await self._get_result_async(operation_id=operation_id)
1281
+
1282
+ def _copy_config(
1283
+ self,
1284
+ *,
1285
+ operation_id: OperationIdPointer,
1286
+ cancel: CancelPointer,
1287
+ target: c_char_p,
1288
+ source: c_char_p,
1289
+ ) -> c_uint:
1290
+ status = self.ffi_mapping.netconf_mapping.copy_config(
1291
+ ptr=self._ptr_or_exception(),
1292
+ operation_id=operation_id,
1293
+ cancel=cancel,
1294
+ target=target,
1295
+ source=source,
1296
+ )
1297
+ if status != 0:
1298
+ raise SubmitOperationException("submitting copy-config operation failed")
1299
+
1300
+ return c_uint(operation_id.contents.value)
1301
+
1302
+ @handle_operation_timeout
1303
+ def copy_config(
1304
+ self,
1305
+ *,
1306
+ target: DatastoreType = DatastoreType.RUNNING,
1307
+ source: DatastoreType = DatastoreType.STARTUP,
1308
+ operation_timeout_ns: int | None = None,
1309
+ ) -> Result:
1310
+ """
1311
+ Execute a copy-config rpc operation.
1312
+
1313
+ Args:
1314
+ target: target to copy *to*
1315
+ source: source to copy *from*
1316
+ operation_timeout_ns: optional timeout in ns for this operation
1317
+
1318
+ Returns:
1319
+ Result: a Result object representing the operation
1320
+
1321
+ Raises:
1322
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1323
+ SubmitOperationException: if the operation fails
1324
+
1325
+ """
1326
+ # only used in the decorator
1327
+ _ = operation_timeout_ns
1328
+
1329
+ operation_id = OperationIdPointer(c_uint(0))
1330
+ cancel = CancelPointer(c_bool(False))
1331
+
1332
+ _target = to_c_string(target)
1333
+ _source = to_c_string(source)
1334
+
1335
+ operation_id = self._copy_config(
1336
+ operation_id=operation_id,
1337
+ cancel=cancel,
1338
+ target=_target,
1339
+ source=_source,
1340
+ )
1341
+
1342
+ return self._get_result(operation_id=operation_id)
1343
+
1344
+ @handle_operation_timeout_async
1345
+ async def copy_config_async(
1346
+ self,
1347
+ *,
1348
+ target: DatastoreType = DatastoreType.RUNNING,
1349
+ source: DatastoreType = DatastoreType.STARTUP,
1350
+ operation_timeout_ns: int | None = None,
1351
+ ) -> Result:
1352
+ """
1353
+ Execute a copy-config rpc operation.
1354
+
1355
+ Args:
1356
+ target: target to copy *to*
1357
+ source: source to copy *from*
1358
+ operation_timeout_ns: optional timeout in ns for this operation
1359
+
1360
+ Returns:
1361
+ Result: a Result object representing the operation
1362
+
1363
+ Raises:
1364
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1365
+ SubmitOperationException: if the operation fails
1366
+
1367
+ """
1368
+ # only used in the decorator
1369
+ _ = operation_timeout_ns
1370
+
1371
+ operation_id = OperationIdPointer(c_uint(0))
1372
+ cancel = CancelPointer(c_bool(False))
1373
+
1374
+ _target = to_c_string(target)
1375
+ _source = to_c_string(source)
1376
+
1377
+ operation_id = self._copy_config(
1378
+ operation_id=operation_id,
1379
+ cancel=cancel,
1380
+ target=_target,
1381
+ source=_source,
1382
+ )
1383
+
1384
+ return await self._get_result_async(operation_id=operation_id)
1385
+
1386
+ def _delete_config(
1387
+ self,
1388
+ *,
1389
+ operation_id: OperationIdPointer,
1390
+ cancel: CancelPointer,
1391
+ target: c_char_p,
1392
+ ) -> c_uint:
1393
+ status = self.ffi_mapping.netconf_mapping.delete_config(
1394
+ ptr=self._ptr_or_exception(),
1395
+ operation_id=operation_id,
1396
+ cancel=cancel,
1397
+ target=target,
1398
+ )
1399
+ if status != 0:
1400
+ raise SubmitOperationException("submitting delete-config operation failed")
1401
+
1402
+ return c_uint(operation_id.contents.value)
1403
+
1404
+ @handle_operation_timeout
1405
+ def delete_config(
1406
+ self,
1407
+ *,
1408
+ target: DatastoreType = DatastoreType.RUNNING,
1409
+ operation_timeout_ns: int | None = None,
1410
+ ) -> Result:
1411
+ """
1412
+ Execute a delete-config rpc operation.
1413
+
1414
+ Args:
1415
+ target: target datastore to delete
1416
+ operation_timeout_ns: optional timeout in ns for this operation
1417
+
1418
+ Returns:
1419
+ Result: a Result object representing the operation
1420
+
1421
+ Raises:
1422
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1423
+ SubmitOperationException: if the operation fails
1424
+
1425
+ """
1426
+ # only used in the decorator
1427
+ _ = operation_timeout_ns
1428
+
1429
+ operation_id = OperationIdPointer(c_uint(0))
1430
+ cancel = CancelPointer(c_bool(False))
1431
+
1432
+ _target = to_c_string(target)
1433
+
1434
+ operation_id = self._delete_config(
1435
+ operation_id=operation_id,
1436
+ cancel=cancel,
1437
+ target=_target,
1438
+ )
1439
+
1440
+ return self._get_result(operation_id=operation_id)
1441
+
1442
+ @handle_operation_timeout_async
1443
+ async def delete_config_async(
1444
+ self,
1445
+ *,
1446
+ target: DatastoreType = DatastoreType.RUNNING,
1447
+ operation_timeout_ns: int | None = None,
1448
+ ) -> Result:
1449
+ """
1450
+ Execute a delete-config rpc operation.
1451
+
1452
+ Args:
1453
+ target: target datastore to delete
1454
+ operation_timeout_ns: optional timeout in ns for this operation
1455
+
1456
+ Returns:
1457
+ Result: a Result object representing the operation
1458
+
1459
+ Raises:
1460
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1461
+ SubmitOperationException: if the operation fails
1462
+
1463
+ """
1464
+ # only used in the decorator
1465
+ _ = operation_timeout_ns
1466
+
1467
+ operation_id = OperationIdPointer(c_uint(0))
1468
+ cancel = CancelPointer(c_bool(False))
1469
+
1470
+ _target = to_c_string(target)
1471
+
1472
+ operation_id = self._delete_config(
1473
+ operation_id=operation_id,
1474
+ cancel=cancel,
1475
+ target=_target,
1476
+ )
1477
+
1478
+ return await self._get_result_async(operation_id=operation_id)
1479
+
1480
+ def _lock(
1481
+ self,
1482
+ *,
1483
+ operation_id: OperationIdPointer,
1484
+ cancel: CancelPointer,
1485
+ target: c_char_p,
1486
+ ) -> c_uint:
1487
+ status = self.ffi_mapping.netconf_mapping.lock(
1488
+ ptr=self._ptr_or_exception(),
1489
+ operation_id=operation_id,
1490
+ cancel=cancel,
1491
+ target=target,
1492
+ )
1493
+ if status != 0:
1494
+ raise SubmitOperationException("submitting lock operation failed")
1495
+
1496
+ return c_uint(operation_id.contents.value)
1497
+
1498
+ @handle_operation_timeout
1499
+ def lock(
1500
+ self,
1501
+ *,
1502
+ target: DatastoreType = DatastoreType.RUNNING,
1503
+ operation_timeout_ns: int | None = None,
1504
+ ) -> Result:
1505
+ """
1506
+ Execute a lock rpc operation.
1507
+
1508
+ Args:
1509
+ target: target datastore to lock
1510
+ operation_timeout_ns: optional timeout in ns for this operation
1511
+
1512
+ Returns:
1513
+ Result: a Result object representing the operation
1514
+
1515
+ Raises:
1516
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1517
+ SubmitOperationException: if the operation fails
1518
+
1519
+ """
1520
+ # only used in the decorator
1521
+ _ = operation_timeout_ns
1522
+
1523
+ operation_id = OperationIdPointer(c_uint(0))
1524
+ cancel = CancelPointer(c_bool(False))
1525
+
1526
+ _target = to_c_string(target)
1527
+
1528
+ operation_id = self._lock(
1529
+ operation_id=operation_id,
1530
+ cancel=cancel,
1531
+ target=_target,
1532
+ )
1533
+
1534
+ return self._get_result(operation_id=operation_id)
1535
+
1536
+ @handle_operation_timeout_async
1537
+ async def lock_async(
1538
+ self,
1539
+ *,
1540
+ target: DatastoreType = DatastoreType.RUNNING,
1541
+ operation_timeout_ns: int | None = None,
1542
+ ) -> Result:
1543
+ """
1544
+ Execute a lock rpc operation.
1545
+
1546
+ Args:
1547
+ target: target datastore to lock
1548
+ operation_timeout_ns: optional timeout in ns for this operation
1549
+
1550
+ Returns:
1551
+ Result: a Result object representing the operation
1552
+
1553
+ Raises:
1554
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1555
+ SubmitOperationException: if the operation fails
1556
+
1557
+ """
1558
+ # only used in the decorator
1559
+ _ = operation_timeout_ns
1560
+
1561
+ operation_id = OperationIdPointer(c_uint(0))
1562
+ cancel = CancelPointer(c_bool(False))
1563
+
1564
+ _target = to_c_string(target)
1565
+
1566
+ operation_id = self._lock(
1567
+ operation_id=operation_id,
1568
+ cancel=cancel,
1569
+ target=_target,
1570
+ )
1571
+
1572
+ return await self._get_result_async(operation_id=operation_id)
1573
+
1574
+ def _unlock(
1575
+ self,
1576
+ *,
1577
+ operation_id: OperationIdPointer,
1578
+ cancel: CancelPointer,
1579
+ target: c_char_p,
1580
+ ) -> c_uint:
1581
+ status = self.ffi_mapping.netconf_mapping.unlock(
1582
+ ptr=self._ptr_or_exception(),
1583
+ operation_id=operation_id,
1584
+ cancel=cancel,
1585
+ target=target,
1586
+ )
1587
+ if status != 0:
1588
+ raise SubmitOperationException("submitting unlock operation failed")
1589
+
1590
+ return c_uint(operation_id.contents.value)
1591
+
1592
+ @handle_operation_timeout
1593
+ def unlock(
1594
+ self,
1595
+ *,
1596
+ target: DatastoreType = DatastoreType.RUNNING,
1597
+ operation_timeout_ns: int | None = None,
1598
+ ) -> Result:
1599
+ """
1600
+ Execute an unlock rpc operation.
1601
+
1602
+ Args:
1603
+ target: target datastore to unlock
1604
+ operation_timeout_ns: optional timeout in ns for this operation
1605
+
1606
+ Returns:
1607
+ Result: a Result object representing the operation
1608
+
1609
+ Raises:
1610
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1611
+ SubmitOperationException: if the operation fails
1612
+
1613
+ """
1614
+ # only used in the decorator
1615
+ _ = operation_timeout_ns
1616
+
1617
+ operation_id = OperationIdPointer(c_uint(0))
1618
+ cancel = CancelPointer(c_bool(False))
1619
+
1620
+ _target = to_c_string(target)
1621
+
1622
+ operation_id = self._unlock(
1623
+ operation_id=operation_id,
1624
+ cancel=cancel,
1625
+ target=_target,
1626
+ )
1627
+
1628
+ return self._get_result(operation_id=operation_id)
1629
+
1630
+ @handle_operation_timeout_async
1631
+ async def unlock_async(
1632
+ self,
1633
+ *,
1634
+ target: DatastoreType = DatastoreType.RUNNING,
1635
+ operation_timeout_ns: int | None = None,
1636
+ ) -> Result:
1637
+ """
1638
+ Execute an unlock rpc operation.
1639
+
1640
+ Args:
1641
+ target: target datastore to unlock
1642
+ operation_timeout_ns: optional timeout in ns for this operation
1643
+
1644
+ Returns:
1645
+ Result: a Result object representing the operation
1646
+
1647
+ Raises:
1648
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1649
+ SubmitOperationException: if the operation fails
1650
+
1651
+ """
1652
+ # only used in the decorator
1653
+ _ = operation_timeout_ns
1654
+
1655
+ operation_id = OperationIdPointer(c_uint(0))
1656
+ cancel = CancelPointer(c_bool(False))
1657
+
1658
+ _target = to_c_string(target)
1659
+
1660
+ operation_id = self._unlock(
1661
+ operation_id=operation_id,
1662
+ cancel=cancel,
1663
+ target=_target,
1664
+ )
1665
+
1666
+ return await self._get_result_async(operation_id=operation_id)
1667
+
1668
+ def _get( # noqa: PLR0913,too-many-locals
1669
+ self,
1670
+ *,
1671
+ operation_id: OperationIdPointer,
1672
+ cancel: CancelPointer,
1673
+ filter_: c_char_p,
1674
+ filter_type: c_char_p,
1675
+ filter_namespace_prefix: c_char_p,
1676
+ filter_namespace: c_char_p,
1677
+ defaults_type: c_char_p,
1678
+ ) -> c_uint:
1679
+ status = self.ffi_mapping.netconf_mapping.get(
1680
+ ptr=self._ptr_or_exception(),
1681
+ operation_id=operation_id,
1682
+ cancel=cancel,
1683
+ filter_=filter_,
1684
+ filter_type=filter_type,
1685
+ filter_namespace_prefix=filter_namespace_prefix,
1686
+ filter_namespace=filter_namespace,
1687
+ defaults_type=defaults_type,
1688
+ )
1689
+ if status != 0:
1690
+ raise SubmitOperationException("submitting get operation failed")
1691
+
1692
+ return c_uint(operation_id.contents.value)
1693
+
1694
+ @handle_operation_timeout
1695
+ def get( # noqa: PLR0913
1696
+ self,
1697
+ *,
1698
+ filter_: str = "",
1699
+ filter_type: FilterType = FilterType.SUBTREE,
1700
+ filter_namespace_prefix: str = "",
1701
+ filter_namespace: str = "",
1702
+ defaults_type: DefaultsType = DefaultsType.UNSET,
1703
+ operation_timeout_ns: int | None = None,
1704
+ ) -> Result:
1705
+ """
1706
+ Execute a get rpc operation.
1707
+
1708
+ Args:
1709
+ filter_: filter to apply to the get-config (or not if empty string)
1710
+ filter_type: type of filter to apply, subtree|xpath
1711
+ filter_namespace_prefix: filter namespace prefix
1712
+ filter_namespace: filter namespace
1713
+ defaults_type: defaults type to apply to the get-config, "unset" means dont apply one
1714
+ operation_timeout_ns: optional timeout in ns for this operation
1715
+
1716
+ Returns:
1717
+ Result: a Result object representing the operation
1718
+
1719
+ Raises:
1720
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1721
+ SubmitOperationException: if the operation fails
1722
+
1723
+ """
1724
+ # only used in the decorator
1725
+ _ = operation_timeout_ns
1726
+
1727
+ operation_id = OperationIdPointer(c_uint(0))
1728
+ cancel = CancelPointer(c_bool(False))
1729
+
1730
+ _filter = to_c_string(filter_)
1731
+ _filter_type = to_c_string(filter_type)
1732
+ _filter_namespace_prefix = to_c_string(filter_namespace_prefix)
1733
+ _filter_namespace = to_c_string(filter_namespace)
1734
+ _defaults_type = to_c_string(defaults_type)
1735
+
1736
+ operation_id = self._get(
1737
+ operation_id=operation_id,
1738
+ cancel=cancel,
1739
+ filter_=_filter,
1740
+ filter_type=_filter_type,
1741
+ filter_namespace_prefix=_filter_namespace_prefix,
1742
+ filter_namespace=_filter_namespace,
1743
+ defaults_type=_defaults_type,
1744
+ )
1745
+
1746
+ return self._get_result(operation_id=operation_id)
1747
+
1748
+ @handle_operation_timeout_async
1749
+ async def get_async( # noqa: PLR0913
1750
+ self,
1751
+ *,
1752
+ filter_: str = "",
1753
+ filter_type: FilterType = FilterType.SUBTREE,
1754
+ filter_namespace_prefix: str = "",
1755
+ filter_namespace: str = "",
1756
+ defaults_type: DefaultsType = DefaultsType.UNSET,
1757
+ operation_timeout_ns: int | None = None,
1758
+ ) -> Result:
1759
+ """
1760
+ Execute a get rpc operation.
1761
+
1762
+ Args:
1763
+ filter_: filter to apply to the get-config (or not if empty string)
1764
+ filter_type: type of filter to apply, subtree|xpath
1765
+ filter_namespace_prefix: filter namespace prefix
1766
+ filter_namespace: filter namespace
1767
+ defaults_type: defaults type to apply to the get-config, "unset" means dont apply one
1768
+ operation_timeout_ns: optional timeout in ns for this operation
1769
+
1770
+ Returns:
1771
+ Result: a Result object representing the operation
1772
+
1773
+ Raises:
1774
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1775
+ SubmitOperationException: if the operation fails
1776
+
1777
+ """
1778
+ # only used in the decorator
1779
+ _ = operation_timeout_ns
1780
+
1781
+ operation_id = OperationIdPointer(c_uint(0))
1782
+ cancel = CancelPointer(c_bool(False))
1783
+
1784
+ _filter = to_c_string(filter_)
1785
+ _filter_type = to_c_string(filter_type)
1786
+ _filter_namespace_prefix = to_c_string(filter_namespace_prefix)
1787
+ _filter_namespace = to_c_string(filter_namespace)
1788
+ _defaults_type = to_c_string(defaults_type)
1789
+
1790
+ operation_id = self._get(
1791
+ operation_id=operation_id,
1792
+ cancel=cancel,
1793
+ filter_=_filter,
1794
+ filter_type=_filter_type,
1795
+ filter_namespace_prefix=_filter_namespace_prefix,
1796
+ filter_namespace=_filter_namespace,
1797
+ defaults_type=_defaults_type,
1798
+ )
1799
+
1800
+ return await self._get_result_async(operation_id=operation_id)
1801
+
1802
+ def _close_session(
1803
+ self,
1804
+ *,
1805
+ operation_id: OperationIdPointer,
1806
+ cancel: CancelPointer,
1807
+ ) -> c_uint:
1808
+ status = self.ffi_mapping.netconf_mapping.close_session(
1809
+ ptr=self._ptr_or_exception(),
1810
+ operation_id=operation_id,
1811
+ cancel=cancel,
1812
+ )
1813
+ if status != 0:
1814
+ raise SubmitOperationException("submitting close-session operation failed")
1815
+
1816
+ return c_uint(operation_id.contents.value)
1817
+
1818
+ @handle_operation_timeout
1819
+ def close_session(
1820
+ self,
1821
+ *,
1822
+ operation_timeout_ns: int | None = None,
1823
+ ) -> Result:
1824
+ """
1825
+ Execute a close-session rpc operation.
1826
+
1827
+ Args:
1828
+ operation_timeout_ns: optional timeout in ns for this operation
1829
+
1830
+ Returns:
1831
+ Result: a Result object representing the operation
1832
+
1833
+ Raises:
1834
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1835
+ SubmitOperationException: if the operation fails
1836
+
1837
+ """
1838
+ # only used in the decorator
1839
+ _ = operation_timeout_ns
1840
+
1841
+ operation_id = OperationIdPointer(c_uint(0))
1842
+ cancel = CancelPointer(c_bool(False))
1843
+
1844
+ operation_id = self._close_session(
1845
+ operation_id=operation_id,
1846
+ cancel=cancel,
1847
+ )
1848
+
1849
+ return self._get_result(operation_id=operation_id)
1850
+
1851
+ @handle_operation_timeout_async
1852
+ async def close_session_async(
1853
+ self,
1854
+ *,
1855
+ operation_timeout_ns: int | None = None,
1856
+ ) -> Result:
1857
+ """
1858
+ Execute a close-session rpc operation.
1859
+
1860
+ Args:
1861
+ operation_timeout_ns: optional timeout in ns for this operation
1862
+
1863
+ Returns:
1864
+ Result: a Result object representing the operation
1865
+
1866
+ Raises:
1867
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1868
+ SubmitOperationException: if the operation fails
1869
+
1870
+ """
1871
+ # only used in the decorator
1872
+ _ = operation_timeout_ns
1873
+
1874
+ operation_id = OperationIdPointer(c_uint(0))
1875
+ cancel = CancelPointer(c_bool(False))
1876
+
1877
+ operation_id = self._close_session(
1878
+ operation_id=operation_id,
1879
+ cancel=cancel,
1880
+ )
1881
+
1882
+ return await self._get_result_async(operation_id=operation_id)
1883
+
1884
+ def _kill_session(
1885
+ self,
1886
+ *,
1887
+ operation_id: OperationIdPointer,
1888
+ cancel: CancelPointer,
1889
+ session_id: int,
1890
+ ) -> c_uint:
1891
+ status = self.ffi_mapping.netconf_mapping.kill_session(
1892
+ ptr=self._ptr_or_exception(),
1893
+ operation_id=operation_id,
1894
+ cancel=cancel,
1895
+ session_id=c_int(session_id),
1896
+ )
1897
+ if status != 0:
1898
+ raise SubmitOperationException("submitting kill-session operation failed")
1899
+
1900
+ return c_uint(operation_id.contents.value)
1901
+
1902
+ @handle_operation_timeout
1903
+ def kill_session(
1904
+ self,
1905
+ session_id: int,
1906
+ *,
1907
+ operation_timeout_ns: int | None = None,
1908
+ ) -> Result:
1909
+ """
1910
+ Execute a kill-session rpc operation.
1911
+
1912
+ Args:
1913
+ session_id: session id to kill
1914
+ operation_timeout_ns: optional timeout in ns for this operation
1915
+
1916
+ Returns:
1917
+ Result: a Result object representing the operation
1918
+
1919
+ Raises:
1920
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1921
+ SubmitOperationException: if the operation fails
1922
+
1923
+ """
1924
+ # only used in the decorator
1925
+ _ = operation_timeout_ns
1926
+
1927
+ operation_id = OperationIdPointer(c_uint(0))
1928
+ cancel = CancelPointer(c_bool(False))
1929
+
1930
+ operation_id = self._kill_session(
1931
+ operation_id=operation_id,
1932
+ cancel=cancel,
1933
+ session_id=session_id,
1934
+ )
1935
+
1936
+ return self._get_result(operation_id=operation_id)
1937
+
1938
+ @handle_operation_timeout_async
1939
+ async def kill_session_async(
1940
+ self,
1941
+ session_id: int,
1942
+ *,
1943
+ operation_timeout_ns: int | None = None,
1944
+ ) -> Result:
1945
+ """
1946
+ Execute a kill-session rpc operation.
1947
+
1948
+ Args:
1949
+ session_id: session id to kill
1950
+ operation_timeout_ns: optional timeout in ns for this operation
1951
+
1952
+ Returns:
1953
+ Result: a Result object representing the operation
1954
+
1955
+ Raises:
1956
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
1957
+ SubmitOperationException: if the operation fails
1958
+
1959
+ """
1960
+ # only used in the decorator
1961
+ _ = operation_timeout_ns
1962
+
1963
+ operation_id = OperationIdPointer(c_uint(0))
1964
+ cancel = CancelPointer(c_bool(False))
1965
+
1966
+ operation_id = self._kill_session(
1967
+ operation_id=operation_id,
1968
+ cancel=cancel,
1969
+ session_id=session_id,
1970
+ )
1971
+
1972
+ return await self._get_result_async(operation_id=operation_id)
1973
+
1974
+ def _commit(
1975
+ self,
1976
+ *,
1977
+ operation_id: OperationIdPointer,
1978
+ cancel: CancelPointer,
1979
+ ) -> c_uint:
1980
+ status = self.ffi_mapping.netconf_mapping.commit(
1981
+ ptr=self._ptr_or_exception(),
1982
+ operation_id=operation_id,
1983
+ cancel=cancel,
1984
+ )
1985
+ if status != 0:
1986
+ raise SubmitOperationException("submitting commit operation failed")
1987
+
1988
+ return c_uint(operation_id.contents.value)
1989
+
1990
+ @handle_operation_timeout
1991
+ def commit(
1992
+ self,
1993
+ *,
1994
+ operation_timeout_ns: int | None = None,
1995
+ ) -> Result:
1996
+ """
1997
+ Execute a commit rpc operation.
1998
+
1999
+ Args:
2000
+ operation_timeout_ns: optional timeout in ns for this operation
2001
+
2002
+ Returns:
2003
+ Result: a Result object representing the operation
2004
+
2005
+ Raises:
2006
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2007
+ SubmitOperationException: if the operation fails
2008
+
2009
+ """
2010
+ # only used in the decorator
2011
+ _ = operation_timeout_ns
2012
+
2013
+ operation_id = OperationIdPointer(c_uint(0))
2014
+ cancel = CancelPointer(c_bool(False))
2015
+
2016
+ operation_id = self._commit(
2017
+ operation_id=operation_id,
2018
+ cancel=cancel,
2019
+ )
2020
+
2021
+ return self._get_result(operation_id=operation_id)
2022
+
2023
+ @handle_operation_timeout_async
2024
+ async def commit_async(
2025
+ self,
2026
+ *,
2027
+ operation_timeout_ns: int | None = None,
2028
+ ) -> Result:
2029
+ """
2030
+ Execute a commit rpc operation.
2031
+
2032
+ Args:
2033
+ operation_timeout_ns: optional timeout in ns for this operation
2034
+
2035
+ Returns:
2036
+ Result: a Result object representing the operation
2037
+
2038
+ Raises:
2039
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2040
+ SubmitOperationException: if the operation fails
2041
+
2042
+ """
2043
+ # only used in the decorator
2044
+ _ = operation_timeout_ns
2045
+
2046
+ operation_id = OperationIdPointer(c_uint(0))
2047
+ cancel = CancelPointer(c_bool(False))
2048
+
2049
+ operation_id = self._commit(
2050
+ operation_id=operation_id,
2051
+ cancel=cancel,
2052
+ )
2053
+
2054
+ return await self._get_result_async(operation_id=operation_id)
2055
+
2056
+ def _discard(
2057
+ self,
2058
+ *,
2059
+ operation_id: OperationIdPointer,
2060
+ cancel: CancelPointer,
2061
+ ) -> c_uint:
2062
+ status = self.ffi_mapping.netconf_mapping.discard(
2063
+ ptr=self._ptr_or_exception(),
2064
+ operation_id=operation_id,
2065
+ cancel=cancel,
2066
+ )
2067
+ if status != 0:
2068
+ raise SubmitOperationException("submitting discard operation failed")
2069
+
2070
+ return c_uint(operation_id.contents.value)
2071
+
2072
+ @handle_operation_timeout
2073
+ def discard(
2074
+ self,
2075
+ *,
2076
+ operation_timeout_ns: int | None = None,
2077
+ ) -> Result:
2078
+ """
2079
+ Execute a discard rpc operation.
2080
+
2081
+ Args:
2082
+ operation_timeout_ns: optional timeout in ns for this operation
2083
+
2084
+ Returns:
2085
+ Result: a Result object representing the operation
2086
+
2087
+ Raises:
2088
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2089
+ SubmitOperationException: if the operation fails
2090
+
2091
+ """
2092
+ # only used in the decorator
2093
+ _ = operation_timeout_ns
2094
+
2095
+ operation_id = OperationIdPointer(c_uint(0))
2096
+ cancel = CancelPointer(c_bool(False))
2097
+
2098
+ operation_id = self._discard(
2099
+ operation_id=operation_id,
2100
+ cancel=cancel,
2101
+ )
2102
+
2103
+ return self._get_result(operation_id=operation_id)
2104
+
2105
+ @handle_operation_timeout_async
2106
+ async def discard_async(
2107
+ self,
2108
+ *,
2109
+ operation_timeout_ns: int | None = None,
2110
+ ) -> Result:
2111
+ """
2112
+ Execute a discard rpc operation.
2113
+
2114
+ Args:
2115
+ operation_timeout_ns: optional timeout in ns for this operation
2116
+
2117
+ Returns:
2118
+ Result: a Result object representing the operation
2119
+
2120
+ Raises:
2121
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2122
+ SubmitOperationException: if the operation fails
2123
+
2124
+ """
2125
+ # only used in the decorator
2126
+ _ = operation_timeout_ns
2127
+
2128
+ operation_id = OperationIdPointer(c_uint(0))
2129
+ cancel = CancelPointer(c_bool(False))
2130
+
2131
+ operation_id = self._discard(
2132
+ operation_id=operation_id,
2133
+ cancel=cancel,
2134
+ )
2135
+
2136
+ return await self._get_result_async(operation_id=operation_id)
2137
+
2138
+ def _cancel_commit(
2139
+ self,
2140
+ *,
2141
+ operation_id: OperationIdPointer,
2142
+ cancel: CancelPointer,
2143
+ ) -> c_uint:
2144
+ status = self.ffi_mapping.netconf_mapping.cancel_commit(
2145
+ ptr=self._ptr_or_exception(),
2146
+ operation_id=operation_id,
2147
+ cancel=cancel,
2148
+ )
2149
+ if status != 0:
2150
+ raise SubmitOperationException("submitting cancel-commit operation failed")
2151
+
2152
+ return c_uint(operation_id.contents.value)
2153
+
2154
+ @handle_operation_timeout
2155
+ def cancel_commit(
2156
+ self,
2157
+ *,
2158
+ operation_timeout_ns: int | None = None,
2159
+ ) -> Result:
2160
+ """
2161
+ Execute a cancel-commit rpc operation.
2162
+
2163
+ Args:
2164
+ operation_timeout_ns: optional timeout in ns for this operation
2165
+
2166
+ Returns:
2167
+ Result: a Result object representing the operation
2168
+
2169
+ Raises:
2170
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2171
+ SubmitOperationException: if the operation fails
2172
+
2173
+ """
2174
+ # only used in the decorator
2175
+ _ = operation_timeout_ns
2176
+
2177
+ operation_id = OperationIdPointer(c_uint(0))
2178
+ cancel = CancelPointer(c_bool(False))
2179
+
2180
+ operation_id = self._cancel_commit(
2181
+ operation_id=operation_id,
2182
+ cancel=cancel,
2183
+ )
2184
+
2185
+ return self._get_result(operation_id=operation_id)
2186
+
2187
+ @handle_operation_timeout_async
2188
+ async def cancel_commit_async(
2189
+ self,
2190
+ *,
2191
+ operation_timeout_ns: int | None = None,
2192
+ ) -> Result:
2193
+ """
2194
+ Execute a cancel-commit rpc operation.
2195
+
2196
+ Args:
2197
+ operation_timeout_ns: optional timeout in ns for this operation
2198
+
2199
+ Returns:
2200
+ Result: a Result object representing the operation
2201
+
2202
+ Raises:
2203
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2204
+ SubmitOperationException: if the operation fails
2205
+
2206
+ """
2207
+ # only used in the decorator
2208
+ _ = operation_timeout_ns
2209
+
2210
+ operation_id = OperationIdPointer(c_uint(0))
2211
+ cancel = CancelPointer(c_bool(False))
2212
+
2213
+ operation_id = self._cancel_commit(
2214
+ operation_id=operation_id,
2215
+ cancel=cancel,
2216
+ )
2217
+
2218
+ return await self._get_result_async(operation_id=operation_id)
2219
+
2220
+ def _validate(
2221
+ self,
2222
+ *,
2223
+ operation_id: OperationIdPointer,
2224
+ cancel: CancelPointer,
2225
+ source: c_char_p,
2226
+ ) -> c_uint:
2227
+ status = self.ffi_mapping.netconf_mapping.validate(
2228
+ ptr=self._ptr_or_exception(),
2229
+ operation_id=operation_id,
2230
+ cancel=cancel,
2231
+ source=source,
2232
+ )
2233
+ if status != 0:
2234
+ raise SubmitOperationException("submitting validate operation failed")
2235
+
2236
+ return c_uint(operation_id.contents.value)
2237
+
2238
+ @handle_operation_timeout
2239
+ def validate(
2240
+ self,
2241
+ *,
2242
+ source: DatastoreType = DatastoreType.RUNNING,
2243
+ operation_timeout_ns: int | None = None,
2244
+ ) -> Result:
2245
+ """
2246
+ Execute a validate rpc operation.
2247
+
2248
+ Args:
2249
+ source: datastore to validate
2250
+ operation_timeout_ns: optional timeout in ns for this operation
2251
+
2252
+ Returns:
2253
+ Result: a Result object representing the operation
2254
+
2255
+ Raises:
2256
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2257
+ SubmitOperationException: if the operation fails
2258
+
2259
+ """
2260
+ # only used in the decorator
2261
+ _ = operation_timeout_ns
2262
+
2263
+ operation_id = OperationIdPointer(c_uint(0))
2264
+ cancel = CancelPointer(c_bool(False))
2265
+
2266
+ _source = to_c_string(source)
2267
+
2268
+ operation_id = self._validate(
2269
+ operation_id=operation_id,
2270
+ cancel=cancel,
2271
+ source=_source,
2272
+ )
2273
+
2274
+ return self._get_result(operation_id=operation_id)
2275
+
2276
+ @handle_operation_timeout_async
2277
+ async def validate_async(
2278
+ self,
2279
+ *,
2280
+ source: DatastoreType = DatastoreType.RUNNING,
2281
+ operation_timeout_ns: int | None = None,
2282
+ ) -> Result:
2283
+ """
2284
+ Execute a validate rpc operation.
2285
+
2286
+ Args:
2287
+ source: datastore to validate
2288
+ operation_timeout_ns: optional timeout in ns for this operation
2289
+
2290
+ Returns:
2291
+ Result: a Result object representing the operation
2292
+
2293
+ Raises:
2294
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2295
+ SubmitOperationException: if the operation fails
2296
+
2297
+ """
2298
+ # only used in the decorator
2299
+ _ = operation_timeout_ns
2300
+
2301
+ operation_id = OperationIdPointer(c_uint(0))
2302
+ cancel = CancelPointer(c_bool(False))
2303
+
2304
+ _source = to_c_string(source)
2305
+
2306
+ operation_id = self._validate(
2307
+ operation_id=operation_id,
2308
+ cancel=cancel,
2309
+ source=_source,
2310
+ )
2311
+
2312
+ return await self._get_result_async(operation_id=operation_id)
2313
+
2314
+ def _get_schema(
2315
+ self,
2316
+ *,
2317
+ operation_id: OperationIdPointer,
2318
+ cancel: CancelPointer,
2319
+ identifier: c_char_p,
2320
+ version: c_char_p,
2321
+ format_: c_char_p,
2322
+ ) -> c_uint:
2323
+ status = self.ffi_mapping.netconf_mapping.get_schema(
2324
+ ptr=self._ptr_or_exception(),
2325
+ operation_id=operation_id,
2326
+ cancel=cancel,
2327
+ identifier=identifier,
2328
+ version=version,
2329
+ format_=format_,
2330
+ )
2331
+ if status != 0:
2332
+ raise SubmitOperationException("submitting get-schema operation failed")
2333
+
2334
+ return c_uint(operation_id.contents.value)
2335
+
2336
+ @handle_operation_timeout
2337
+ def get_schema(
2338
+ self,
2339
+ identifier: str,
2340
+ *,
2341
+ version: str = "",
2342
+ format_: SchemaFormat = SchemaFormat.YANG,
2343
+ operation_timeout_ns: int | None = None,
2344
+ ) -> Result:
2345
+ """
2346
+ Execute a get-schema rpc operation.
2347
+
2348
+ Args:
2349
+ identifier: schema identifier to get
2350
+ version: optional schema version to request
2351
+ format_: schema format to apply
2352
+ operation_timeout_ns: optional timeout in ns for this operation
2353
+
2354
+ Returns:
2355
+ Result: a Result object representing the operation
2356
+
2357
+ Raises:
2358
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2359
+ SubmitOperationException: if the operation fails
2360
+
2361
+ """
2362
+ # only used in the decorator
2363
+ _ = operation_timeout_ns
2364
+
2365
+ operation_id = OperationIdPointer(c_uint(0))
2366
+ cancel = CancelPointer(c_bool(False))
2367
+
2368
+ _identifier = to_c_string(identifier)
2369
+ _version = to_c_string(version)
2370
+ _format = to_c_string(format_)
2371
+
2372
+ operation_id = self._get_schema(
2373
+ operation_id=operation_id,
2374
+ cancel=cancel,
2375
+ identifier=_identifier,
2376
+ version=_version,
2377
+ format_=_format,
2378
+ )
2379
+
2380
+ return self._get_result(operation_id=operation_id)
2381
+
2382
+ @handle_operation_timeout_async
2383
+ async def get_schema_async(
2384
+ self,
2385
+ identifier: str,
2386
+ *,
2387
+ version: str = "",
2388
+ format_: SchemaFormat = SchemaFormat.YANG,
2389
+ operation_timeout_ns: int | None = None,
2390
+ ) -> Result:
2391
+ """
2392
+ Execute a get-schema rpc operation.
2393
+
2394
+ Args:
2395
+ identifier: schema identifier to get
2396
+ version: optional schema version to request
2397
+ format_: schema format to apply
2398
+ operation_timeout_ns: optional timeout in ns for this operation
2399
+
2400
+ Returns:
2401
+ Result: a Result object representing the operation
2402
+
2403
+ Raises:
2404
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2405
+ SubmitOperationException: if the operation fails
2406
+
2407
+ """
2408
+ # only used in the decorator
2409
+ _ = operation_timeout_ns
2410
+
2411
+ operation_id = OperationIdPointer(c_uint(0))
2412
+ cancel = CancelPointer(c_bool(False))
2413
+
2414
+ _identifier = to_c_string(identifier)
2415
+ _version = to_c_string(version)
2416
+ _format = to_c_string(format_)
2417
+
2418
+ operation_id = self._get_schema(
2419
+ operation_id=operation_id,
2420
+ cancel=cancel,
2421
+ identifier=_identifier,
2422
+ version=_version,
2423
+ format_=_format,
2424
+ )
2425
+
2426
+ return await self._get_result_async(operation_id=operation_id)
2427
+
2428
+ def _get_data( # noqa: PLR0913,too-many-locals
2429
+ self,
2430
+ *,
2431
+ operation_id: OperationIdPointer,
2432
+ cancel: CancelPointer,
2433
+ source: c_char_p,
2434
+ filter_: c_char_p,
2435
+ filter_type: c_char_p,
2436
+ filter_namespace_prefix: c_char_p,
2437
+ filter_namespace: c_char_p,
2438
+ config_filter: c_char_p,
2439
+ origin_filters: c_char_p,
2440
+ max_depth: int,
2441
+ with_origin: bool,
2442
+ defaults_type: c_char_p,
2443
+ ) -> c_uint:
2444
+ status = self.ffi_mapping.netconf_mapping.get_data(
2445
+ ptr=self._ptr_or_exception(),
2446
+ operation_id=operation_id,
2447
+ cancel=cancel,
2448
+ source=source,
2449
+ filter_=filter_,
2450
+ filter_type=filter_type,
2451
+ filter_namespace_prefix=filter_namespace_prefix,
2452
+ filter_namespace=filter_namespace,
2453
+ config_filter=config_filter,
2454
+ origin_filters=origin_filters,
2455
+ max_depth=c_int(max_depth),
2456
+ with_origin=c_bool(with_origin),
2457
+ defaults_type=defaults_type,
2458
+ )
2459
+ if status != 0:
2460
+ raise SubmitOperationException("submitting copy-config operation failed")
2461
+
2462
+ return c_uint(operation_id.contents.value)
2463
+
2464
+ @handle_operation_timeout
2465
+ def get_data( # noqa: PLR0913
2466
+ self,
2467
+ *,
2468
+ source: DatastoreType = DatastoreType.RUNNING,
2469
+ filter_: str = "",
2470
+ filter_type: FilterType = FilterType.SUBTREE,
2471
+ filter_namespace_prefix: str = "",
2472
+ filter_namespace: str = "",
2473
+ config_filter: ConfigFilter = ConfigFilter.UNSET,
2474
+ origin_filters: str = "",
2475
+ max_depth: int = 0,
2476
+ with_origin: bool = False,
2477
+ defaults_type: DefaultsType = DefaultsType.UNSET,
2478
+ operation_timeout_ns: int | None = None,
2479
+ ) -> Result:
2480
+ """
2481
+ Execute a get-data rpc operation.
2482
+
2483
+ Args:
2484
+ source: source datastore to get data from
2485
+ filter_: filter to apply to the get-config (or not if empty string)
2486
+ filter_type: type of filter to apply, subtree|xpath
2487
+ filter_namespace_prefix: filter namespace prefix
2488
+ filter_namespace: filter namespace
2489
+ config_filter: config filter true/false, or unset to leave up to the server
2490
+ origin_filters: fully formed origin filter xml payload to embed
2491
+ max_depth: max depth of data requested
2492
+ with_origin: include origin data
2493
+ defaults_type: defaults type to apply to the get-config, "unset" means dont apply one
2494
+ operation_timeout_ns: optional timeout in ns for this operation
2495
+
2496
+ Returns:
2497
+ Result: a Result object representing the operation
2498
+
2499
+ Raises:
2500
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2501
+ SubmitOperationException: if the operation fails
2502
+
2503
+ """
2504
+ # only used in the decorator
2505
+ _ = operation_timeout_ns
2506
+
2507
+ operation_id = OperationIdPointer(c_uint(0))
2508
+ cancel = CancelPointer(c_bool(False))
2509
+
2510
+ _source = to_c_string(source)
2511
+ _filter = to_c_string(filter_)
2512
+ _filter_type = to_c_string(filter_type)
2513
+ _filter_namespace_prefix = to_c_string(filter_namespace_prefix)
2514
+ _filter_namespace = to_c_string(filter_namespace)
2515
+ _config_filter = to_c_string(config_filter)
2516
+ _origin_filters = to_c_string(origin_filters)
2517
+ _defaults_type = to_c_string(defaults_type)
2518
+
2519
+ operation_id = self._get_data(
2520
+ operation_id=operation_id,
2521
+ cancel=cancel,
2522
+ source=_source,
2523
+ filter_=_filter,
2524
+ filter_type=_filter_type,
2525
+ filter_namespace_prefix=_filter_namespace_prefix,
2526
+ filter_namespace=_filter_namespace,
2527
+ config_filter=_config_filter,
2528
+ origin_filters=_origin_filters,
2529
+ max_depth=max_depth,
2530
+ with_origin=with_origin,
2531
+ defaults_type=_defaults_type,
2532
+ )
2533
+
2534
+ return self._get_result(operation_id=operation_id)
2535
+
2536
+ @handle_operation_timeout_async
2537
+ async def get_data_async( # noqa: PLR0913
2538
+ self,
2539
+ *,
2540
+ source: DatastoreType = DatastoreType.RUNNING,
2541
+ filter_: str = "",
2542
+ filter_type: FilterType = FilterType.SUBTREE,
2543
+ filter_namespace_prefix: str = "",
2544
+ filter_namespace: str = "",
2545
+ config_filter: ConfigFilter = ConfigFilter.UNSET,
2546
+ origin_filters: str = "",
2547
+ max_depth: int = 0,
2548
+ with_origin: bool = False,
2549
+ defaults_type: DefaultsType = DefaultsType.UNSET,
2550
+ operation_timeout_ns: int | None = None,
2551
+ ) -> Result:
2552
+ """
2553
+ Execute a get-data rpc operation.
2554
+
2555
+ Args:
2556
+ source: source datastore to get data from
2557
+ filter_: filter to apply to the get-config (or not if empty string)
2558
+ filter_type: type of filter to apply, subtree|xpath
2559
+ filter_namespace_prefix: filter namespace prefix
2560
+ filter_namespace: filter namespace
2561
+ config_filter: config filter true/false, or unset to leave up to the server
2562
+ origin_filters: fully formed origin filter xml payload to embed
2563
+ max_depth: max depth of data requested
2564
+ with_origin: include origin data
2565
+ defaults_type: defaults type to apply to the get-config, "unset" means dont apply one
2566
+ operation_timeout_ns: optional timeout in ns for this operation
2567
+
2568
+ Returns:
2569
+ Result: a Result object representing the operation
2570
+
2571
+ Raises:
2572
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2573
+ SubmitOperationException: if the operation fails
2574
+
2575
+ """
2576
+ # only used in the decorator
2577
+ _ = operation_timeout_ns
2578
+
2579
+ operation_id = OperationIdPointer(c_uint(0))
2580
+ cancel = CancelPointer(c_bool(False))
2581
+
2582
+ _source = to_c_string(source)
2583
+ _filter = to_c_string(filter_)
2584
+ _filter_type = to_c_string(filter_type)
2585
+ _filter_namespace_prefix = to_c_string(filter_namespace_prefix)
2586
+ _filter_namespace = to_c_string(filter_namespace)
2587
+ _config_filter = to_c_string(config_filter)
2588
+ _origin_filters = to_c_string(origin_filters)
2589
+ _defaults_type = to_c_string(defaults_type)
2590
+
2591
+ operation_id = self._get_data(
2592
+ operation_id=operation_id,
2593
+ cancel=cancel,
2594
+ source=_source,
2595
+ filter_=_filter,
2596
+ filter_type=_filter_type,
2597
+ filter_namespace_prefix=_filter_namespace_prefix,
2598
+ filter_namespace=_filter_namespace,
2599
+ config_filter=_config_filter,
2600
+ origin_filters=_origin_filters,
2601
+ max_depth=max_depth,
2602
+ with_origin=with_origin,
2603
+ defaults_type=_defaults_type,
2604
+ )
2605
+
2606
+ return await self._get_result_async(operation_id=operation_id)
2607
+
2608
+ def _edit_data(
2609
+ self,
2610
+ *,
2611
+ operation_id: OperationIdPointer,
2612
+ cancel: CancelPointer,
2613
+ content: c_char_p,
2614
+ target: c_char_p,
2615
+ ) -> c_uint:
2616
+ status = self.ffi_mapping.netconf_mapping.edit_data(
2617
+ ptr=self._ptr_or_exception(),
2618
+ operation_id=operation_id,
2619
+ cancel=cancel,
2620
+ content=content,
2621
+ target=target,
2622
+ )
2623
+ if status != 0:
2624
+ raise SubmitOperationException("submitting copy-config operation failed")
2625
+
2626
+ return c_uint(operation_id.contents.value)
2627
+
2628
+ @handle_operation_timeout
2629
+ def edit_data(
2630
+ self,
2631
+ content: str,
2632
+ *,
2633
+ target: DatastoreType = DatastoreType.RUNNING,
2634
+ operation_timeout_ns: int | None = None,
2635
+ ) -> Result:
2636
+ """
2637
+ Execute an edit-data rpc operation.
2638
+
2639
+ Args:
2640
+ content: full payload content to send
2641
+ target: datastore to target
2642
+ operation_timeout_ns: optional timeout in ns for this operation
2643
+
2644
+ Returns:
2645
+ Result: a Result object representing the operation
2646
+
2647
+ Raises:
2648
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2649
+ SubmitOperationException: if the operation fails
2650
+
2651
+ """
2652
+ # only used in the decorator
2653
+ _ = operation_timeout_ns
2654
+
2655
+ operation_id = OperationIdPointer(c_uint(0))
2656
+ cancel = CancelPointer(c_bool(False))
2657
+
2658
+ _content = to_c_string(content)
2659
+ _target = to_c_string(target)
2660
+
2661
+ operation_id = self._edit_data(
2662
+ operation_id=operation_id,
2663
+ cancel=cancel,
2664
+ content=_content,
2665
+ target=_target,
2666
+ )
2667
+
2668
+ return self._get_result(operation_id=operation_id)
2669
+
2670
+ @handle_operation_timeout_async
2671
+ async def edit_data_async(
2672
+ self,
2673
+ content: str,
2674
+ *,
2675
+ target: DatastoreType = DatastoreType.RUNNING,
2676
+ operation_timeout_ns: int | None = None,
2677
+ ) -> Result:
2678
+ """
2679
+ Execute an edit-data rpc operation.
2680
+
2681
+ Args:
2682
+ content: full payload content to send
2683
+ target: datastore to target
2684
+ operation_timeout_ns: optional timeout in ns for this operation
2685
+
2686
+ Returns:
2687
+ Result: a Result object representing the operation
2688
+
2689
+ Raises:
2690
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2691
+ SubmitOperationException: if the operation fails
2692
+
2693
+ """
2694
+ # only used in the decorator
2695
+ _ = operation_timeout_ns
2696
+
2697
+ operation_id = OperationIdPointer(c_uint(0))
2698
+ cancel = CancelPointer(c_bool(False))
2699
+
2700
+ _content = to_c_string(content)
2701
+ _target = to_c_string(target)
2702
+
2703
+ operation_id = self._edit_data(
2704
+ operation_id=operation_id,
2705
+ cancel=cancel,
2706
+ content=_content,
2707
+ target=_target,
2708
+ )
2709
+
2710
+ return await self._get_result_async(operation_id=operation_id)
2711
+
2712
+ def _action(
2713
+ self,
2714
+ *,
2715
+ operation_id: OperationIdPointer,
2716
+ cancel: CancelPointer,
2717
+ action: c_char_p,
2718
+ ) -> c_uint:
2719
+ status = self.ffi_mapping.netconf_mapping.action(
2720
+ ptr=self._ptr_or_exception(),
2721
+ operation_id=operation_id,
2722
+ cancel=cancel,
2723
+ action=action,
2724
+ )
2725
+ if status != 0:
2726
+ raise SubmitOperationException("submitting action operation failed")
2727
+
2728
+ return c_uint(operation_id.contents.value)
2729
+
2730
+ @handle_operation_timeout
2731
+ def action(
2732
+ self,
2733
+ action: str,
2734
+ *,
2735
+ operation_timeout_ns: int | None = None,
2736
+ ) -> Result:
2737
+ """
2738
+ Execute an action rpc operation.
2739
+
2740
+ Args:
2741
+ action: action to execute
2742
+ operation_timeout_ns: optional timeout in ns for this operation
2743
+
2744
+ Returns:
2745
+ Result: a Result object representing the operation
2746
+
2747
+ Raises:
2748
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2749
+ SubmitOperationException: if the operation fails
2750
+
2751
+ """
2752
+ # only used in the decorator
2753
+ _ = operation_timeout_ns
2754
+
2755
+ operation_id = OperationIdPointer(c_uint(0))
2756
+ cancel = CancelPointer(c_bool(False))
2757
+
2758
+ _action = to_c_string(action)
2759
+
2760
+ operation_id = self._action(
2761
+ operation_id=operation_id,
2762
+ cancel=cancel,
2763
+ action=_action,
2764
+ )
2765
+
2766
+ return self._get_result(operation_id=operation_id)
2767
+
2768
+ @handle_operation_timeout_async
2769
+ async def action_async(
2770
+ self,
2771
+ action: str,
2772
+ *,
2773
+ operation_timeout_ns: int | None = None,
2774
+ ) -> Result:
2775
+ """
2776
+ Execute an action rpc operation.
2777
+
2778
+ Args:
2779
+ action: action to execute
2780
+ operation_timeout_ns: optional timeout in ns for this operation
2781
+
2782
+ Returns:
2783
+ Result: a Result object representing the operation
2784
+
2785
+ Raises:
2786
+ NotOpenedException: if the ptr to the cli object is None (via _ptr_or_exception)
2787
+ SubmitOperationException: if the operation fails
2788
+
2789
+ """
2790
+ # only used in the decorator
2791
+ _ = operation_timeout_ns
2792
+
2793
+ operation_id = OperationIdPointer(c_uint(0))
2794
+ cancel = CancelPointer(c_bool(False))
2795
+
2796
+ _action = to_c_string(action)
2797
+
2798
+ operation_id = self._action(
2799
+ operation_id=operation_id,
2800
+ cancel=cancel,
2801
+ action=_action,
2802
+ )
2803
+
2804
+ return await self._get_result_async(operation_id=operation_id)