scrapli 2.0.0a2__py3-none-manylinux2010_x86_64.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.
@@ -0,0 +1,646 @@
1
+ """scrapli.ffi_mapping_cli"""
2
+
3
+ from collections.abc import Callable
4
+ from ctypes import (
5
+ CDLL,
6
+ c_bool,
7
+ c_char_p,
8
+ c_int,
9
+ c_uint8,
10
+ )
11
+
12
+ from _ctypes import POINTER
13
+
14
+ from scrapli.ffi_types import (
15
+ CancelPointer,
16
+ DriverPointer,
17
+ IntPointer,
18
+ LogFuncCallback,
19
+ OperationId,
20
+ OperationIdPointer,
21
+ U64Pointer,
22
+ ZigSlice,
23
+ ZigSlicePointer,
24
+ ZigU64Slice,
25
+ )
26
+
27
+
28
+ class LibScrapliCliMapping:
29
+ """
30
+ Mapping to libscrapli cli object functions mapping.
31
+
32
+ Should not be used/called directly.
33
+
34
+ Args:
35
+ N/A
36
+
37
+ Returns:
38
+ None
39
+
40
+ Raises:
41
+ N/A
42
+
43
+ """
44
+
45
+ def __init__(self, lib: CDLL) -> None:
46
+ self._alloc: Callable[
47
+ [
48
+ c_char_p,
49
+ LogFuncCallback,
50
+ c_char_p,
51
+ c_int,
52
+ c_char_p,
53
+ ],
54
+ DriverPointer,
55
+ ] = lib.ls_cli_alloc
56
+ lib.ls_cli_alloc.argtypes = [
57
+ c_char_p,
58
+ LogFuncCallback,
59
+ c_char_p,
60
+ c_int,
61
+ c_char_p,
62
+ ]
63
+ lib.ls_cli_alloc.restype = DriverPointer
64
+
65
+ self._get_ntc_templates_platform: Callable[
66
+ [
67
+ DriverPointer,
68
+ ZigSlicePointer,
69
+ ],
70
+ int,
71
+ ] = lib.ls_cli_get_ntc_templates_platform
72
+ lib.ls_cli_get_ntc_templates_platform.argtypes = [
73
+ DriverPointer,
74
+ POINTER(ZigSlice),
75
+ ]
76
+ lib.ls_cli_get_ntc_templates_platform.restype = c_uint8
77
+
78
+ self._get_genie_platform: Callable[
79
+ [
80
+ DriverPointer,
81
+ ZigSlicePointer,
82
+ ],
83
+ int,
84
+ ] = lib.ls_cli_get_genie_platform
85
+ lib.ls_cli_get_genie_platform.argtypes = [
86
+ DriverPointer,
87
+ POINTER(ZigSlice),
88
+ ]
89
+ lib.ls_cli_get_genie_platform.restype = c_uint8
90
+
91
+ self._open: Callable[
92
+ [
93
+ DriverPointer,
94
+ OperationIdPointer,
95
+ CancelPointer,
96
+ ],
97
+ int,
98
+ ] = lib.ls_cli_open
99
+ lib.ls_cli_open.argtypes = [
100
+ DriverPointer,
101
+ OperationIdPointer,
102
+ CancelPointer,
103
+ ]
104
+ lib.ls_cli_open.restype = c_uint8
105
+
106
+ self._close: Callable[
107
+ [
108
+ DriverPointer,
109
+ OperationIdPointer,
110
+ CancelPointer,
111
+ ],
112
+ int,
113
+ ] = lib.ls_cli_close
114
+ lib.ls_cli_close.argtypes = [
115
+ DriverPointer,
116
+ OperationIdPointer,
117
+ CancelPointer,
118
+ ]
119
+ lib.ls_cli_close.restype = c_uint8
120
+
121
+ self._fetch_sizes: Callable[
122
+ [
123
+ DriverPointer,
124
+ OperationId,
125
+ IntPointer,
126
+ IntPointer,
127
+ IntPointer,
128
+ IntPointer,
129
+ IntPointer,
130
+ IntPointer,
131
+ ],
132
+ int,
133
+ ] = lib.ls_cli_fetch_operation_sizes
134
+ lib.ls_cli_fetch_operation_sizes.argtypes = [
135
+ DriverPointer,
136
+ OperationId,
137
+ IntPointer,
138
+ IntPointer,
139
+ IntPointer,
140
+ IntPointer,
141
+ IntPointer,
142
+ IntPointer,
143
+ ]
144
+ lib.ls_cli_fetch_operation_sizes.restype = c_uint8
145
+
146
+ self._fetch: Callable[
147
+ [
148
+ DriverPointer,
149
+ OperationId,
150
+ IntPointer,
151
+ ZigU64Slice,
152
+ ZigSlicePointer,
153
+ ZigSlicePointer,
154
+ ZigSlicePointer,
155
+ ZigSlicePointer,
156
+ ZigSlicePointer,
157
+ ],
158
+ int,
159
+ ] = lib.ls_cli_fetch_operation
160
+ lib.ls_cli_fetch_operation.argtypes = [
161
+ DriverPointer,
162
+ OperationId,
163
+ U64Pointer,
164
+ POINTER(ZigU64Slice),
165
+ POINTER(ZigSlice),
166
+ POINTER(ZigSlice),
167
+ POINTER(ZigSlice),
168
+ POINTER(ZigSlice),
169
+ POINTER(ZigSlice),
170
+ ]
171
+ lib.ls_cli_fetch_operation.restype = c_uint8
172
+
173
+ self._enter_mode: Callable[
174
+ [DriverPointer, OperationIdPointer, CancelPointer, c_char_p], int
175
+ ] = lib.ls_cli_enter_mode
176
+ lib.ls_cli_enter_mode.argtypes = [
177
+ DriverPointer,
178
+ OperationIdPointer,
179
+ CancelPointer,
180
+ c_char_p,
181
+ ]
182
+ lib.ls_cli_enter_mode.restype = c_uint8
183
+
184
+ self._get_prompt: Callable[[DriverPointer, OperationIdPointer, CancelPointer], int] = (
185
+ lib.ls_cli_get_prompt
186
+ )
187
+ lib.ls_cli_get_prompt.argtypes = [
188
+ DriverPointer,
189
+ OperationIdPointer,
190
+ CancelPointer,
191
+ ]
192
+ lib.ls_cli_get_prompt.restype = c_uint8
193
+
194
+ self._send_input: Callable[
195
+ [
196
+ DriverPointer,
197
+ OperationIdPointer,
198
+ CancelPointer,
199
+ c_char_p,
200
+ c_char_p,
201
+ c_char_p,
202
+ c_bool,
203
+ c_bool,
204
+ ],
205
+ int,
206
+ ] = lib.ls_cli_send_input
207
+ lib.ls_cli_send_input.argtypes = [
208
+ DriverPointer,
209
+ OperationIdPointer,
210
+ CancelPointer,
211
+ c_char_p,
212
+ c_char_p,
213
+ c_char_p,
214
+ c_bool,
215
+ c_bool,
216
+ ]
217
+ lib.ls_cli_send_input.restype = c_uint8
218
+
219
+ self._send_prompted_input: Callable[
220
+ [
221
+ DriverPointer,
222
+ OperationIdPointer,
223
+ CancelPointer,
224
+ c_char_p,
225
+ c_char_p,
226
+ c_char_p,
227
+ c_char_p,
228
+ c_char_p,
229
+ c_char_p,
230
+ c_char_p,
231
+ c_bool,
232
+ c_bool,
233
+ ],
234
+ int,
235
+ ] = lib.ls_cli_send_prompted_input
236
+ lib.ls_cli_send_prompted_input.argtypes = [
237
+ DriverPointer,
238
+ OperationIdPointer,
239
+ CancelPointer,
240
+ c_char_p,
241
+ c_char_p,
242
+ c_char_p,
243
+ c_char_p,
244
+ c_char_p,
245
+ c_char_p,
246
+ c_char_p,
247
+ c_bool,
248
+ c_bool,
249
+ ]
250
+ lib.ls_cli_send_prompted_input.restype = c_uint8
251
+
252
+ def alloc(
253
+ self,
254
+ *,
255
+ definition_string: c_char_p,
256
+ logger_callback: LogFuncCallback,
257
+ host: c_char_p,
258
+ port: c_int,
259
+ transport_kind: c_char_p,
260
+ ) -> DriverPointer:
261
+ """
262
+ Allocate a cli object.
263
+
264
+ Should (generally) not be called directly/by users.
265
+
266
+ Args:
267
+ definition_string: yaml definition string
268
+ logger_callback: pointer to logger callback function
269
+ host: host to connect to
270
+ port: port at which to connect
271
+ transport_kind: transport kind to use
272
+
273
+ Returns:
274
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
275
+ ctypes.
276
+
277
+ Raises:
278
+ N/A
279
+
280
+ """
281
+ return self._alloc(definition_string, logger_callback, host, port, transport_kind)
282
+
283
+ def get_ntc_templates_platform(
284
+ self,
285
+ *,
286
+ ptr: DriverPointer,
287
+ ntc_templates_platform: ZigSlicePointer,
288
+ ) -> int:
289
+ """
290
+ Writes the ntc templates platform into the given slice pointer.
291
+
292
+ Should (generally) not be called directly/by users.
293
+
294
+ Args:
295
+ ptr: ptr to the cli object
296
+ ntc_templates_platform: slice to write the ntc templates platform into
297
+
298
+ Returns:
299
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
300
+ ctypes.
301
+
302
+ Raises:
303
+ N/A
304
+
305
+ """
306
+ return self._get_ntc_templates_platform(
307
+ ptr,
308
+ ntc_templates_platform,
309
+ )
310
+
311
+ def get_genie_platform(
312
+ self,
313
+ *,
314
+ ptr: DriverPointer,
315
+ genie_platform: ZigSlicePointer,
316
+ ) -> int:
317
+ """
318
+ Writes the (cisco/pyats) genie platform into the given slice pointer.
319
+
320
+ Should (generally) not be called directly/by users.
321
+
322
+ Args:
323
+ ptr: ptr to the cli object
324
+ genie_platform: slice to write the ntc templates platform into
325
+
326
+ Returns:
327
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
328
+ ctypes.
329
+
330
+ Raises:
331
+ N/A
332
+
333
+ """
334
+ return self._get_genie_platform(
335
+ ptr,
336
+ genie_platform,
337
+ )
338
+
339
+ def open(
340
+ self, ptr: DriverPointer, operation_id: OperationIdPointer, cancel: CancelPointer
341
+ ) -> int:
342
+ """
343
+ Open the driver at ptr.
344
+
345
+ Should (generally) not be called directly/by users.
346
+
347
+ Args:
348
+ ptr: the ptr to the libscrapli cli object.
349
+ operation_id: c_int pointer that is filled with the operation id to poll for completion.
350
+ cancel: bool pointer that can be set to true to cancel the operation.
351
+
352
+ Returns:
353
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
354
+ ctypes.
355
+
356
+ Raises:
357
+ N/A
358
+
359
+ """
360
+ return self._open(ptr, operation_id, cancel)
361
+
362
+ def close(
363
+ self,
364
+ ptr: DriverPointer,
365
+ operation_id: OperationIdPointer,
366
+ cancel: CancelPointer,
367
+ ) -> int:
368
+ """
369
+ Close the driver at ptr.
370
+
371
+ Should (generally) not be called directly/by users.
372
+
373
+ Args:
374
+ ptr: the ptr to the libscrapli cli object.
375
+ operation_id: c_int pointer that is filled with the operation id to poll for completion.
376
+ cancel: bool pointer that can be set to true to cancel the operation.
377
+
378
+ Returns:
379
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
380
+ ctypes.
381
+
382
+ Raises:
383
+ N/A
384
+
385
+ """
386
+ return self._close(
387
+ ptr,
388
+ operation_id,
389
+ cancel,
390
+ )
391
+
392
+ def fetch_sizes(
393
+ self,
394
+ *,
395
+ ptr: DriverPointer,
396
+ operation_id: OperationId,
397
+ operation_count: IntPointer,
398
+ inputs_size: IntPointer,
399
+ results_raw_size: IntPointer,
400
+ results_size: IntPointer,
401
+ results_failed_indicator_size: IntPointer,
402
+ err_size: IntPointer,
403
+ ) -> int:
404
+ """
405
+ Fetch the sizes of a cli operation's results.
406
+
407
+ Should (generally) not be called directly/by users.
408
+
409
+ Args:
410
+ ptr: ptr to the cli object
411
+ operation_id: operation id of which to poll
412
+ operation_count: int pointer to fill with the count of operations
413
+ inputs_size: int pointer to fill with the operation's input size
414
+ results_raw_size: int pointer to fill with the operation's result raw size
415
+ results_size: int pointer to fill with the operation's result size
416
+ results_failed_indicator_size: int pointer to fill with the operation's failed indicator
417
+ size
418
+ err_size: int pointer to fill with the operation's error size
419
+
420
+ Returns:
421
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
422
+ ctypes.
423
+
424
+ Raises:
425
+ N/A
426
+
427
+ """
428
+ return self._fetch_sizes(
429
+ ptr,
430
+ operation_id,
431
+ operation_count,
432
+ inputs_size,
433
+ results_raw_size,
434
+ results_size,
435
+ results_failed_indicator_size,
436
+ err_size,
437
+ )
438
+
439
+ def fetch(
440
+ self,
441
+ *,
442
+ ptr: DriverPointer,
443
+ operation_id: OperationId,
444
+ start_time: U64Pointer,
445
+ splits: ZigU64Slice,
446
+ inputs_slice: ZigSlicePointer,
447
+ results_raw_slice: ZigSlicePointer,
448
+ results_slice: ZigSlicePointer,
449
+ results_failed_indicator_slice: ZigSlicePointer,
450
+ err_slice: ZigSlicePointer,
451
+ ) -> int:
452
+ """
453
+ Fetch the result of a cli operation.
454
+
455
+ Should (generally) not be called directly/by users.
456
+
457
+ Args:
458
+ ptr: ptr to the cli object
459
+ operation_id: operation id of which to poll
460
+ start_time: int pointer to fill with the operation's start time
461
+ splits: slice of u64 timestamps -- the end time (in unix ns) for each operation
462
+ inputs_slice: pre allocated slice to fill with the operations input
463
+ results_raw_slice: pre allocated slice to fill with the operations result raw
464
+ results_slice: pre allocated slice to fill with the operations result
465
+ results_failed_indicator_slice: pre allocated slice to fill with the operations failed
466
+ indicator
467
+ err_slice: pre allocated slice to fill with the operations error
468
+
469
+ Returns:
470
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
471
+ ctypes.
472
+
473
+ Raises:
474
+ N/A
475
+
476
+ """
477
+ return self._fetch(
478
+ ptr,
479
+ operation_id,
480
+ start_time,
481
+ splits,
482
+ inputs_slice,
483
+ results_raw_slice,
484
+ results_slice,
485
+ results_failed_indicator_slice,
486
+ err_slice,
487
+ )
488
+
489
+ def enter_mode(
490
+ self,
491
+ *,
492
+ ptr: DriverPointer,
493
+ operation_id: OperationIdPointer,
494
+ cancel: CancelPointer,
495
+ requested_mode: c_char_p,
496
+ ) -> int:
497
+ """
498
+ Enter the given mode for the cli object.
499
+
500
+ Should (generally) not be called directly/by users.
501
+
502
+ Args:
503
+ ptr: ptr to the cli object
504
+ operation_id: int pointer to fill with the id of the submitted operation
505
+ cancel: bool pointer that can be set to true to cancel the operation
506
+ requested_mode: string name of the mode to enter
507
+
508
+ Returns:
509
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
510
+ ctypes.
511
+
512
+ Raises:
513
+ N/A
514
+
515
+ """
516
+ return self._enter_mode(ptr, operation_id, cancel, requested_mode)
517
+
518
+ def get_prompt(
519
+ self, *, ptr: DriverPointer, operation_id: OperationIdPointer, cancel: CancelPointer
520
+ ) -> int:
521
+ """
522
+ Get the current prompt for the cli object.
523
+
524
+ Should (generally) not be called directly/by users.
525
+
526
+ Args:
527
+ ptr: ptr to the cli object
528
+ operation_id: int pointer to fill with the id of the submitted operation
529
+ cancel: bool pointer that can be set to true to cancel the operation
530
+
531
+ Returns:
532
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
533
+ ctypes.
534
+
535
+ Raises:
536
+ N/A
537
+
538
+ """
539
+ return self._get_prompt(ptr, operation_id, cancel)
540
+
541
+ def send_input(
542
+ self,
543
+ *,
544
+ ptr: DriverPointer,
545
+ operation_id: OperationIdPointer,
546
+ cancel: CancelPointer,
547
+ input_: c_char_p,
548
+ requested_mode: c_char_p,
549
+ input_handling: c_char_p,
550
+ retain_input: c_bool,
551
+ retain_trailing_prompt: c_bool,
552
+ ) -> int:
553
+ """
554
+ Send some input to the cli object.
555
+
556
+ Should (generally) not be called directly/by users.
557
+
558
+ Args:
559
+ ptr: ptr to the cli object
560
+ operation_id: int pointer to fill with the id of the submitted operation
561
+ cancel: bool pointer that can be set to true to cancel the operation
562
+ input_: the input to send
563
+ requested_mode: string name of the mode to send the input in
564
+ input_handling: string mapping to input handling enum that governs how the input is
565
+ handled
566
+ retain_input: boolean indicating whether to retain the input after entering
567
+ retain_trailing_prompt: boolean indicating whether to retain the trailing
568
+
569
+ Returns:
570
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
571
+ ctypes.
572
+
573
+ Raises:
574
+ N/A
575
+
576
+ """
577
+ return self._send_input(
578
+ ptr,
579
+ operation_id,
580
+ cancel,
581
+ input_,
582
+ requested_mode,
583
+ input_handling,
584
+ retain_input,
585
+ retain_trailing_prompt,
586
+ )
587
+
588
+ def send_prompted_input(
589
+ self,
590
+ *,
591
+ ptr: DriverPointer,
592
+ operation_id: OperationIdPointer,
593
+ cancel: CancelPointer,
594
+ input_: c_char_p,
595
+ prompt: c_char_p,
596
+ prompt_pattern: c_char_p,
597
+ response: c_char_p,
598
+ abort_input: c_char_p,
599
+ requested_mode: c_char_p,
600
+ input_handling: c_char_p,
601
+ hidden_response: c_bool,
602
+ retain_trailing_prompt: c_bool,
603
+ ) -> int:
604
+ """
605
+ Send some prompted input to the cli object.
606
+
607
+ Should (generally) not be called directly/by users.
608
+
609
+ Args:
610
+ ptr: ptr to the cli object
611
+ operation_id: int pointer to fill with the id of the submitted operation
612
+ cancel: bool pointer that can be set to true to cancel the operation
613
+ input_: the input to send
614
+ prompt: the prompt to expect
615
+ prompt_pattern: the prompt pattern to expect
616
+ response: the response to write when the prompt has been seen
617
+ abort_input: the input to send to abort the "prompted input" operation if an error
618
+ is encountered
619
+ requested_mode: string name of the mode to send the input in
620
+ input_handling: string mapping to input handling enum that governs how the input is
621
+ handled
622
+ hidden_response: bool indicated if the response we write will be "hidden" on the device
623
+ retain_trailing_prompt: boolean indicating whether to retain the trailing
624
+
625
+ Returns:
626
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
627
+ ctypes.
628
+
629
+ Raises:
630
+ N/A
631
+
632
+ """
633
+ return self._send_prompted_input(
634
+ ptr,
635
+ operation_id,
636
+ cancel,
637
+ input_,
638
+ prompt,
639
+ prompt_pattern,
640
+ response,
641
+ abort_input,
642
+ requested_mode,
643
+ input_handling,
644
+ hidden_response,
645
+ retain_trailing_prompt,
646
+ )