scrapli 2.0.0a3__py3-none-musllinux_1_1_aarch64.whl → 2.0.0a5__py3-none-musllinux_1_1_aarch64.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.
Files changed (59) hide show
  1. scrapli/__init__.py +5 -5
  2. scrapli/auth.py +14 -7
  3. scrapli/cli.py +334 -66
  4. scrapli/cli_parse.py +1 -1
  5. scrapli/cli_result.py +42 -0
  6. scrapli/definitions/aethra_atosnt.yaml +9 -0
  7. scrapli/definitions/alcatel_aos.yaml +9 -0
  8. scrapli/definitions/arista_eos.yaml +1 -0
  9. scrapli/definitions/aruba_aoscx.yaml +33 -0
  10. scrapli/definitions/cisco_aireos.yaml +31 -0
  11. scrapli/definitions/cisco_asa.yaml +48 -0
  12. scrapli/definitions/cisco_cbs.yaml +50 -0
  13. scrapli/definitions/cisco_ftd.yaml +42 -0
  14. scrapli/definitions/cisco_nxos.yaml +2 -0
  15. scrapli/definitions/cumulus_linux.yaml +28 -0
  16. scrapli/definitions/cumulus_vtysh.yaml +42 -0
  17. scrapli/definitions/datacom_dmos.yaml +30 -0
  18. scrapli/definitions/datacom_dmswitch.yaml +32 -0
  19. scrapli/definitions/default.yaml +9 -0
  20. scrapli/definitions/dell_emc.yaml +46 -0
  21. scrapli/definitions/dell_enterprisesonic.yaml +40 -0
  22. scrapli/definitions/dlink_os.yaml +46 -0
  23. scrapli/definitions/edgecore_ecs.yaml +35 -0
  24. scrapli/definitions/eltex_esr.yaml +43 -0
  25. scrapli/definitions/fortinet_fortios.yaml +20 -0
  26. scrapli/definitions/fortinet_wlc.yaml +33 -0
  27. scrapli/definitions/hp_comware.yaml +31 -0
  28. scrapli/definitions/huawei_smartax.yaml +61 -0
  29. scrapli/definitions/huawei_vrp.yaml +56 -0
  30. scrapli/definitions/juniper_junos.yaml +3 -0
  31. scrapli/definitions/nokia_srlinux.yaml +13 -2
  32. scrapli/definitions/nokia_sros.yaml +31 -0
  33. scrapli/definitions/nokia_sros_classic.yaml +33 -0
  34. scrapli/definitions/nokia_sros_classic_aram.yaml +25 -0
  35. scrapli/definitions/paloalto_panos.yaml +36 -0
  36. scrapli/definitions/raisecom_ros.yaml +45 -0
  37. scrapli/definitions/ruckus_fastiron.yaml +45 -0
  38. scrapli/definitions/ruckus_unleashed.yaml +64 -0
  39. scrapli/definitions/siemens_roxii.yaml +28 -0
  40. scrapli/definitions/versa_flexvnf.yaml +45 -0
  41. scrapli/definitions/vyos_vyos.yaml +35 -0
  42. scrapli/definitions/zyxel_dslam.yaml +18 -0
  43. scrapli/ffi.py +1 -1
  44. scrapli/ffi_mapping.py +92 -37
  45. scrapli/ffi_mapping_cli.py +146 -22
  46. scrapli/ffi_mapping_netconf.py +28 -60
  47. scrapli/ffi_mapping_options.py +38 -6
  48. scrapli/ffi_types.py +43 -3
  49. scrapli/helper.py +56 -0
  50. scrapli/lib/{libscrapli.0.0.1-alpha.10.dylib → libscrapli.0.0.1-alpha.17.dylib} +0 -0
  51. scrapli/lib/{libscrapli.so.0.0.1-alpha.10 → libscrapli.so.0.0.1-alpha.17} +0 -0
  52. scrapli/netconf.py +36 -147
  53. scrapli/transport.py +71 -130
  54. {scrapli-2.0.0a3.dist-info → scrapli-2.0.0a5.dist-info}/METADATA +1 -1
  55. scrapli-2.0.0a5.dist-info/RECORD +68 -0
  56. scrapli-2.0.0a3.dist-info/RECORD +0 -35
  57. {scrapli-2.0.0a3.dist-info → scrapli-2.0.0a5.dist-info}/WHEEL +0 -0
  58. {scrapli-2.0.0a3.dist-info → scrapli-2.0.0a5.dist-info}/licenses/LICENSE +0 -0
  59. {scrapli-2.0.0a3.dist-info → scrapli-2.0.0a5.dist-info}/top_level.txt +0 -0
scrapli/ffi_mapping.py CHANGED
@@ -7,7 +7,6 @@ from ctypes import (
7
7
  c_char_p,
8
8
  c_int,
9
9
  c_uint8,
10
- c_uint32,
11
10
  )
12
11
 
13
12
  from scrapli.ffi import get_libscrapli_path
@@ -43,12 +42,12 @@ class LibScrapliSharedMapping:
43
42
  [
44
43
  DriverPointer,
45
44
  ],
46
- c_uint32,
45
+ c_int,
47
46
  ] = lib.ls_shared_get_poll_fd
48
47
  lib.ls_shared_get_poll_fd.argtypes = [
49
48
  DriverPointer,
50
49
  ]
51
- lib.ls_cli_alloc.restype = c_uint32
50
+ lib.ls_cli_alloc.restype = c_int
52
51
 
53
52
  self._free: Callable[
54
53
  [
@@ -61,37 +60,7 @@ class LibScrapliSharedMapping:
61
60
  ]
62
61
  lib.ls_shared_free.restype = None
63
62
 
64
- self._read: Callable[
65
- [
66
- DriverPointer,
67
- StringPointer,
68
- IntPointer,
69
- ],
70
- int,
71
- ] = lib.ls_shared_read_session
72
- lib.ls_shared_read_session.argtypes = [
73
- DriverPointer,
74
- StringPointer,
75
- IntPointer,
76
- ]
77
- lib.ls_shared_read_session.restype = c_int
78
-
79
- self._write: Callable[
80
- [
81
- DriverPointer,
82
- c_char_p,
83
- c_bool,
84
- ],
85
- int,
86
- ] = lib.ls_shared_write_session
87
- lib.ls_shared_write_session.argtypes = [
88
- DriverPointer,
89
- c_char_p,
90
- c_bool,
91
- ]
92
- lib.ls_shared_write_session.restype = c_uint8
93
-
94
- def get_poll_fd(self, ptr: DriverPointer) -> c_uint32:
63
+ def get_poll_fd(self, ptr: DriverPointer) -> c_int:
95
64
  """
96
65
  Get the operation poll fd from the driver at ptr.
97
66
 
@@ -127,6 +96,70 @@ class LibScrapliSharedMapping:
127
96
  """
128
97
  return self._free(ptr)
129
98
 
99
+
100
+ class LibScrapliSessionMapping:
101
+ """
102
+ Mapping to libscrapli shared (between cli/netconf) object functions mapping.
103
+
104
+ Should not be used/called directly.
105
+
106
+ Args:
107
+ N/A
108
+
109
+ Returns:
110
+ None
111
+
112
+ Raises:
113
+ N/A
114
+
115
+ """
116
+
117
+ def __init__(self, lib: CDLL) -> None:
118
+ self._read: Callable[
119
+ [
120
+ DriverPointer,
121
+ StringPointer,
122
+ IntPointer,
123
+ ],
124
+ int,
125
+ ] = lib.ls_session_read
126
+ lib.ls_session_read.argtypes = [
127
+ DriverPointer,
128
+ StringPointer,
129
+ IntPointer,
130
+ ]
131
+ lib.ls_session_read.restype = c_int
132
+
133
+ self._write: Callable[
134
+ [
135
+ DriverPointer,
136
+ c_char_p,
137
+ c_bool,
138
+ ],
139
+ int,
140
+ ] = lib.ls_session_write
141
+ lib.ls_session_write.argtypes = [
142
+ DriverPointer,
143
+ c_char_p,
144
+ c_bool,
145
+ ]
146
+ lib.ls_session_write.restype = c_uint8
147
+
148
+ self._write_and_return: Callable[
149
+ [
150
+ DriverPointer,
151
+ c_char_p,
152
+ c_bool,
153
+ ],
154
+ int,
155
+ ] = lib.ls_session_write_and_return
156
+ lib.ls_session_write_and_return.argtypes = [
157
+ DriverPointer,
158
+ c_char_p,
159
+ c_bool,
160
+ ]
161
+ lib.ls_session_write_and_return.restype = c_uint8
162
+
130
163
  def read(self, ptr: DriverPointer, buf: StringPointer, read_size: IntPointer) -> int:
131
164
  """
132
165
  Read from the session of driver at ptr.
@@ -148,7 +181,7 @@ class LibScrapliSharedMapping:
148
181
  """
149
182
  return self._read(ptr, buf, read_size)
150
183
 
151
- def write(self, ptr: DriverPointer, buf: c_char_p, redacted: c_bool) -> int:
184
+ def write(self, ptr: DriverPointer, input_: c_char_p, redacted: c_bool) -> int:
152
185
  """
153
186
  Write to the session of driver at ptr.
154
187
 
@@ -156,7 +189,28 @@ class LibScrapliSharedMapping:
156
189
 
157
190
  Args:
158
191
  ptr: the ptr to the libscrapli cli/netconf object.
159
- buf: buffer contents to write during the write operation..
192
+ input_: buffer contents to write during the write operation..
193
+ redacted: bool indicated if the write contents should be redacted from logs.
194
+
195
+ Returns:
196
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
197
+ ctypes.
198
+
199
+ Raises:
200
+ N/A
201
+
202
+ """
203
+ return self._write(ptr, input_, redacted)
204
+
205
+ def write_and_return(self, ptr: DriverPointer, input_: c_char_p, redacted: c_bool) -> int:
206
+ """
207
+ Write and then send a return to the session of driver at ptr.
208
+
209
+ Should (generally) not be called directly/by users.
210
+
211
+ Args:
212
+ ptr: the ptr to the libscrapli cli/netconf object.
213
+ input_: buffer contents to write during the write operation..
160
214
  redacted: bool indicated if the write contents should be redacted from logs.
161
215
 
162
216
  Returns:
@@ -167,7 +221,7 @@ class LibScrapliSharedMapping:
167
221
  N/A
168
222
 
169
223
  """
170
- return self._write(ptr, buf, redacted)
224
+ return self._write_and_return(ptr, input_, redacted)
171
225
 
172
226
 
173
227
  class LibScrapliMapping:
@@ -197,6 +251,7 @@ class LibScrapliMapping:
197
251
  def __init__(self) -> None:
198
252
  self.lib = CDLL(get_libscrapli_path())
199
253
  self.shared_mapping = LibScrapliSharedMapping(self.lib)
254
+ self.session_mapping = LibScrapliSessionMapping(self.lib)
200
255
  self.cli_mapping = LibScrapliCliMapping(self.lib)
201
256
  self.netconf_mapping = LibScrapliNetconfMapping(self.lib)
202
257
  self.options_mapping = LibScrapliOptionsMapping(self.lib)
@@ -12,6 +12,8 @@ from ctypes import (
12
12
  from _ctypes import POINTER
13
13
 
14
14
  from scrapli.ffi_types import (
15
+ CANCEL,
16
+ BoolPointer,
15
17
  CancelPointer,
16
18
  DriverPointer,
17
19
  IntPointer,
@@ -171,7 +173,13 @@ class LibScrapliCliMapping:
171
173
  lib.ls_cli_fetch_operation.restype = c_uint8
172
174
 
173
175
  self._enter_mode: Callable[
174
- [DriverPointer, OperationIdPointer, CancelPointer, c_char_p], int
176
+ [
177
+ DriverPointer,
178
+ OperationIdPointer,
179
+ CancelPointer,
180
+ c_char_p,
181
+ ],
182
+ int,
175
183
  ] = lib.ls_cli_enter_mode
176
184
  lib.ls_cli_enter_mode.argtypes = [
177
185
  DriverPointer,
@@ -181,9 +189,14 @@ class LibScrapliCliMapping:
181
189
  ]
182
190
  lib.ls_cli_enter_mode.restype = c_uint8
183
191
 
184
- self._get_prompt: Callable[[DriverPointer, OperationIdPointer, CancelPointer], int] = (
185
- lib.ls_cli_get_prompt
186
- )
192
+ self._get_prompt: Callable[
193
+ [
194
+ DriverPointer,
195
+ OperationIdPointer,
196
+ CancelPointer,
197
+ ],
198
+ int,
199
+ ] = lib.ls_cli_get_prompt
187
200
  lib.ls_cli_get_prompt.argtypes = [
188
201
  DriverPointer,
189
202
  OperationIdPointer,
@@ -249,6 +262,42 @@ class LibScrapliCliMapping:
249
262
  ]
250
263
  lib.ls_cli_send_prompted_input.restype = c_uint8
251
264
 
265
+ self._read_any: Callable[
266
+ [
267
+ DriverPointer,
268
+ OperationIdPointer,
269
+ CancelPointer,
270
+ ],
271
+ int,
272
+ ] = lib.ls_cli_read_any
273
+ lib.ls_cli_read_any.argtypes = [
274
+ DriverPointer,
275
+ OperationIdPointer,
276
+ CancelPointer,
277
+ ]
278
+ lib.ls_cli_read_any.restype = c_uint8
279
+
280
+ self._read_callback_should_execute: Callable[
281
+ [
282
+ c_char_p,
283
+ c_char_p,
284
+ c_char_p,
285
+ c_char_p,
286
+ c_char_p,
287
+ BoolPointer,
288
+ ],
289
+ int,
290
+ ] = lib.ls_cli_read_callback_should_execute
291
+ lib.ls_cli_read_callback_should_execute.argtypes = [
292
+ c_char_p,
293
+ c_char_p,
294
+ c_char_p,
295
+ c_char_p,
296
+ c_char_p,
297
+ POINTER(c_bool),
298
+ ]
299
+ lib.ls_cli_read_callback_should_execute.restype = c_uint8
300
+
252
301
  def alloc(
253
302
  self,
254
303
  *,
@@ -337,7 +386,9 @@ class LibScrapliCliMapping:
337
386
  )
338
387
 
339
388
  def open(
340
- self, ptr: DriverPointer, operation_id: OperationIdPointer, cancel: CancelPointer
389
+ self,
390
+ ptr: DriverPointer,
391
+ operation_id: OperationIdPointer,
341
392
  ) -> int:
342
393
  """
343
394
  Open the driver at ptr.
@@ -347,7 +398,6 @@ class LibScrapliCliMapping:
347
398
  Args:
348
399
  ptr: the ptr to the libscrapli cli object.
349
400
  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
401
 
352
402
  Returns:
353
403
  int: return code, non-zero value indicates an error. technically a c_uint8 converted by
@@ -357,13 +407,16 @@ class LibScrapliCliMapping:
357
407
  N/A
358
408
 
359
409
  """
360
- return self._open(ptr, operation_id, cancel)
410
+ return self._open(
411
+ ptr,
412
+ operation_id,
413
+ CANCEL,
414
+ )
361
415
 
362
416
  def close(
363
417
  self,
364
418
  ptr: DriverPointer,
365
419
  operation_id: OperationIdPointer,
366
- cancel: CancelPointer,
367
420
  ) -> int:
368
421
  """
369
422
  Close the driver at ptr.
@@ -373,7 +426,6 @@ class LibScrapliCliMapping:
373
426
  Args:
374
427
  ptr: the ptr to the libscrapli cli object.
375
428
  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
429
 
378
430
  Returns:
379
431
  int: return code, non-zero value indicates an error. technically a c_uint8 converted by
@@ -386,7 +438,7 @@ class LibScrapliCliMapping:
386
438
  return self._close(
387
439
  ptr,
388
440
  operation_id,
389
- cancel,
441
+ CANCEL,
390
442
  )
391
443
 
392
444
  def fetch_sizes(
@@ -491,7 +543,6 @@ class LibScrapliCliMapping:
491
543
  *,
492
544
  ptr: DriverPointer,
493
545
  operation_id: OperationIdPointer,
494
- cancel: CancelPointer,
495
546
  requested_mode: c_char_p,
496
547
  ) -> int:
497
548
  """
@@ -502,7 +553,6 @@ class LibScrapliCliMapping:
502
553
  Args:
503
554
  ptr: ptr to the cli object
504
555
  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
556
  requested_mode: string name of the mode to enter
507
557
 
508
558
  Returns:
@@ -513,10 +563,18 @@ class LibScrapliCliMapping:
513
563
  N/A
514
564
 
515
565
  """
516
- return self._enter_mode(ptr, operation_id, cancel, requested_mode)
566
+ return self._enter_mode(
567
+ ptr,
568
+ operation_id,
569
+ CANCEL,
570
+ requested_mode,
571
+ )
517
572
 
518
573
  def get_prompt(
519
- self, *, ptr: DriverPointer, operation_id: OperationIdPointer, cancel: CancelPointer
574
+ self,
575
+ *,
576
+ ptr: DriverPointer,
577
+ operation_id: OperationIdPointer,
520
578
  ) -> int:
521
579
  """
522
580
  Get the current prompt for the cli object.
@@ -526,7 +584,6 @@ class LibScrapliCliMapping:
526
584
  Args:
527
585
  ptr: ptr to the cli object
528
586
  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
587
 
531
588
  Returns:
532
589
  int: return code, non-zero value indicates an error. technically a c_uint8 converted by
@@ -536,14 +593,17 @@ class LibScrapliCliMapping:
536
593
  N/A
537
594
 
538
595
  """
539
- return self._get_prompt(ptr, operation_id, cancel)
596
+ return self._get_prompt(
597
+ ptr,
598
+ operation_id,
599
+ CANCEL,
600
+ )
540
601
 
541
602
  def send_input(
542
603
  self,
543
604
  *,
544
605
  ptr: DriverPointer,
545
606
  operation_id: OperationIdPointer,
546
- cancel: CancelPointer,
547
607
  input_: c_char_p,
548
608
  requested_mode: c_char_p,
549
609
  input_handling: c_char_p,
@@ -558,7 +618,6 @@ class LibScrapliCliMapping:
558
618
  Args:
559
619
  ptr: ptr to the cli object
560
620
  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
621
  input_: the input to send
563
622
  requested_mode: string name of the mode to send the input in
564
623
  input_handling: string mapping to input handling enum that governs how the input is
@@ -577,7 +636,7 @@ class LibScrapliCliMapping:
577
636
  return self._send_input(
578
637
  ptr,
579
638
  operation_id,
580
- cancel,
639
+ CANCEL,
581
640
  input_,
582
641
  requested_mode,
583
642
  input_handling,
@@ -590,7 +649,6 @@ class LibScrapliCliMapping:
590
649
  *,
591
650
  ptr: DriverPointer,
592
651
  operation_id: OperationIdPointer,
593
- cancel: CancelPointer,
594
652
  input_: c_char_p,
595
653
  prompt: c_char_p,
596
654
  prompt_pattern: c_char_p,
@@ -609,7 +667,6 @@ class LibScrapliCliMapping:
609
667
  Args:
610
668
  ptr: ptr to the cli object
611
669
  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
670
  input_: the input to send
614
671
  prompt: the prompt to expect
615
672
  prompt_pattern: the prompt pattern to expect
@@ -633,7 +690,7 @@ class LibScrapliCliMapping:
633
690
  return self._send_prompted_input(
634
691
  ptr,
635
692
  operation_id,
636
- cancel,
693
+ CANCEL,
637
694
  input_,
638
695
  prompt,
639
696
  prompt_pattern,
@@ -644,3 +701,70 @@ class LibScrapliCliMapping:
644
701
  hidden_response,
645
702
  retain_trailing_prompt,
646
703
  )
704
+
705
+ def read_any(self, ptr: DriverPointer, operation_id: OperationIdPointer) -> int:
706
+ """
707
+ Read any available data from the session, up to the normal timeout behavior.
708
+
709
+ Should (generally) not be called directly/by users.
710
+
711
+ Args:
712
+ ptr: the ptr to the libscrapli cli/netconf object.
713
+ operation_id: int pointer to fill with the id of the submitted operation
714
+
715
+ Returns:
716
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
717
+ ctypes.
718
+
719
+ Raises:
720
+ N/A
721
+
722
+ """
723
+ return self._read_any(
724
+ ptr,
725
+ operation_id,
726
+ CANCEL,
727
+ )
728
+
729
+ def read_callback_should_execute(
730
+ self,
731
+ buf: c_char_p,
732
+ name: c_char_p,
733
+ contains: c_char_p,
734
+ contains_pattern: c_char_p,
735
+ not_contains: c_char_p,
736
+ execute: BoolPointer,
737
+ ) -> int:
738
+ """
739
+ Decide if a callback should execute for read_with_callbacks operations.
740
+
741
+ Should (generally) not be called directly/by users.
742
+
743
+ Done in zig due to regex checks and wanting to ensure we always use pcre2 (vs go re, py re).
744
+
745
+ Args:
746
+ buf: the buf to use to check if the callback should execute
747
+ name: the name of the callback
748
+ contains: the contains string to check for in the buf -- if found, the callback should
749
+ execute
750
+ contains_pattern: a string pattern that, if found, indicates the callback should execute
751
+ not_contains: string that contains data that should not be in the buf for hte callback
752
+ to execute
753
+ execute: bool pointer to update w/ execution state
754
+
755
+ Returns:
756
+ int: return code, non-zero value indicates an error. technically a c_uint8 converted by
757
+ ctypes.
758
+
759
+ Raises:
760
+ N/A
761
+
762
+ """
763
+ return self._read_callback_should_execute(
764
+ buf,
765
+ name,
766
+ contains,
767
+ contains_pattern,
768
+ not_contains,
769
+ execute,
770
+ )