mantatech-sdk 0.5b0.dev65__py3-none-any.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 (54) hide show
  1. manta/__init__.light.py +22 -0
  2. manta/__init__.py +83 -0
  3. manta/__main__.py +21 -0
  4. manta/apis/__init__.py +7 -0
  5. manta/apis/async_user_api.py +6458 -0
  6. manta/apis/graph.py +498 -0
  7. manta/apis/module.py +316 -0
  8. manta/apis/results.py +251 -0
  9. manta/apis/swarm.py +206 -0
  10. manta/apis/user_api.py +1016 -0
  11. manta/cli/__init__.py +1 -0
  12. manta/cli/commands/__init__.py +1 -0
  13. manta/cli/commands/base_handler.py +229 -0
  14. manta/cli/commands/doc.py +192 -0
  15. manta/cli/commands/install.py +346 -0
  16. manta/cli/commands/sdk.py +9 -0
  17. manta/cli/commands/sdk_cluster.py +211 -0
  18. manta/cli/commands/sdk_config.py +347 -0
  19. manta/cli/commands/sdk_globals.py +280 -0
  20. manta/cli/commands/sdk_logs.py +174 -0
  21. manta/cli/commands/sdk_main.py +167 -0
  22. manta/cli/commands/sdk_module.py +516 -0
  23. manta/cli/commands/sdk_nodes.py +168 -0
  24. manta/cli/commands/sdk_original.py +3873 -0
  25. manta/cli/commands/sdk_results.py +265 -0
  26. manta/cli/commands/sdk_swarm.py +454 -0
  27. manta/cli/commands/sdk_user.py +234 -0
  28. manta/cli/commands/status.py +292 -0
  29. manta/cli/component_detector.py +112 -0
  30. manta/cli/config_manager.py +445 -0
  31. manta/cli/main.py +265 -0
  32. manta/cli/utils/__init__.py +27 -0
  33. manta/cli/utils/converters.py +140 -0
  34. manta/clients/cluster_management_client.py +486 -0
  35. manta/clients/local_client.py +149 -0
  36. manta/clients/module_management_client.py +217 -0
  37. manta/clients/swarm_management_client.py +562 -0
  38. manta/clients/user_management_client.py +395 -0
  39. manta/clients/world_client.py +195 -0
  40. manta/light/__init__.py +31 -0
  41. manta/light/globals.py +245 -0
  42. manta/light/local.py +407 -0
  43. manta/light/logging_config.py +39 -0
  44. manta/light/path.py +116 -0
  45. manta/light/results.py +236 -0
  46. manta/light/task.py +100 -0
  47. manta/light/utils.py +217 -0
  48. manta/light/world.py +177 -0
  49. mantatech_sdk-0.5b0.dev65.dist-info/METADATA +1039 -0
  50. mantatech_sdk-0.5b0.dev65.dist-info/RECORD +54 -0
  51. mantatech_sdk-0.5b0.dev65.dist-info/WHEEL +5 -0
  52. mantatech_sdk-0.5b0.dev65.dist-info/entry_points.txt +2 -0
  53. mantatech_sdk-0.5b0.dev65.dist-info/licenses/LICENSE +683 -0
  54. mantatech_sdk-0.5b0.dev65.dist-info/top_level.txt +1 -0
@@ -0,0 +1,562 @@
1
+ """
2
+ Swarm Management Client implementation.
3
+
4
+ This module provides the SwarmManagementClient class for interacting with the SwarmManagement service.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from datetime import datetime
10
+ from logging import Logger
11
+ from pathlib import Path
12
+ from typing import Any, AsyncIterator, Dict, List, Optional, Type, TypeVar
13
+
14
+ from manta_common.base_client import GrpcClientBase, MetadataDict
15
+ from manta_common.build.common.results import Global
16
+ from manta_common.build.common.swarms import Swarm
17
+ from manta_common.build.common.system import (
18
+ CollectionIds,
19
+ Empty,
20
+ Networks,
21
+ Response,
22
+ StopSwarmRequest,
23
+ StrId,
24
+ )
25
+ from manta_common.build.core.user_services import ( # Request/Response messages; Service stub
26
+ DeleteResultsRequest,
27
+ GlobalRequest,
28
+ LogQuery,
29
+ LogResponse,
30
+ ResultsRequest,
31
+ ResultsResponse,
32
+ SelectGlobalResponse,
33
+ SendSwarmRequest,
34
+ SwarmManagementStub,
35
+ Tags,
36
+ TaskResponse,
37
+ )
38
+ from manta_common.retry import RetryPolicy
39
+
40
+ T = TypeVar("T")
41
+
42
+
43
+ class SwarmManagementClient(GrpcClientBase):
44
+ """
45
+ Client for interacting with the SwarmManagement Service.
46
+
47
+ This client provides a high-level interface for making gRPC calls to the SwarmManagement service,
48
+ handling swarm operations, data management, and log collection.
49
+ """
50
+
51
+ __slots__ = ("_secure", "cafile", "certfile", "keyfile")
52
+
53
+ def __init__(
54
+ self,
55
+ host: str,
56
+ port: int,
57
+ jwt_token: str,
58
+ secure: bool = False,
59
+ cafile: Optional[str] = None,
60
+ certfile: Optional[str] = None,
61
+ keyfile: Optional[str] = None,
62
+ channel_options: Optional[Dict[str, Any]] = None,
63
+ logger: Optional[Logger] = None,
64
+ retry_policy: Optional[RetryPolicy] = None,
65
+ streaming_retry_policy: Optional[RetryPolicy] = None,
66
+ ):
67
+ """
68
+ Initialize the SwarmManagementClient.
69
+
70
+ Parameters
71
+ ----------
72
+ host : str
73
+ The host of the SwarmManagement service
74
+ port : int
75
+ The port of the SwarmManagement service
76
+ jwt_token : str
77
+ JWT token for authentication
78
+ secure : bool
79
+ Whether to use a secure connection
80
+ cafile : Optional[str]
81
+ Path to the CA certificate file for verifying the server
82
+ certfile : Optional[str]
83
+ Path to the client certificate file
84
+ keyfile : Optional[str]
85
+ Path to the client private key file
86
+ channel_options : Optional[Dict[str, Any]]
87
+ The channel options
88
+ logger : Optional[Logger]
89
+ The logger
90
+ retry_policy : Optional[RetryPolicy]
91
+ The retry policy
92
+ streaming_retry_policy : Optional[RetryPolicy]
93
+ The streaming retry policy
94
+ """
95
+ super().__init__(
96
+ host=host,
97
+ port=port,
98
+ secure=secure,
99
+ channel_options=channel_options,
100
+ tracer=logger,
101
+ retry_policy=retry_policy,
102
+ streaming_retry_policy=streaming_retry_policy,
103
+ )
104
+ self.jwt_token = jwt_token
105
+ self._secure = secure
106
+ self.cafile = Path(cafile) if cafile is not None else None
107
+ self.certfile = Path(certfile) if certfile is not None else None
108
+ self.keyfile = Path(keyfile) if keyfile is not None else None
109
+
110
+ @property
111
+ def metadata(self) -> MetadataDict:
112
+ return {"authorization": self.jwt_token}
113
+
114
+ def _get_stub_class(self) -> Type[SwarmManagementStub]:
115
+ """Get the stub class for the SwarmManagement service."""
116
+ return SwarmManagementStub
117
+
118
+ async def is_available(self) -> Response:
119
+ """
120
+ Check if the SwarmManagement service is available.
121
+
122
+ Returns
123
+ -------
124
+ Response
125
+ Service availability status
126
+ """
127
+ return await self.call_service_method(
128
+ "is_available",
129
+ Empty(),
130
+ )
131
+
132
+ async def send_swarm(self, request: SendSwarmRequest) -> Swarm:
133
+ """
134
+ Send a swarm graph to the service.
135
+
136
+ Parameters
137
+ ----------
138
+ request : SendSwarmRequest
139
+ The swarm request containing graph, name, and cluster_id
140
+
141
+ Returns
142
+ -------
143
+ Swarm
144
+ Overview of the registered swarm
145
+ """
146
+ return await self.call_service_method(
147
+ "send_swarm",
148
+ request,
149
+ )
150
+
151
+ async def list_swarm_ids(self) -> CollectionIds:
152
+ """
153
+ List all swarm IDs for the authenticated user.
154
+
155
+ Returns
156
+ -------
157
+ CollectionIds
158
+ Collection of swarm IDs
159
+ """
160
+ return await self.call_service_method(
161
+ "list_swarm_ids",
162
+ Empty(),
163
+ )
164
+
165
+ async def stream_swarms(self) -> AsyncIterator[Swarm]:
166
+ """
167
+ Stream all swarms for the authenticated user.
168
+
169
+ Yields
170
+ ------
171
+ Swarm
172
+ Swarm details
173
+ """
174
+ async for swarm in self.stream_service_method(
175
+ "stream_swarms",
176
+ Empty(),
177
+ ):
178
+ yield swarm
179
+
180
+ async def get_swarm(self, swarm_id: str) -> Swarm:
181
+ """
182
+ Get a swarm by its ID.
183
+
184
+ Parameters
185
+ ----------
186
+ swarm_id : str
187
+ ID of the swarm
188
+
189
+ Returns
190
+ -------
191
+ Swarm
192
+ Swarm details
193
+ """
194
+ return await self.call_service_method(
195
+ "get_swarm",
196
+ StrId(id=swarm_id),
197
+ )
198
+
199
+ async def stream_swarm_tasks(self, swarm_id: str) -> AsyncIterator[TaskResponse]:
200
+ """
201
+ Stream tasks for a specific swarm.
202
+
203
+ Parameters
204
+ ----------
205
+ swarm_id : str
206
+ ID of the swarm
207
+
208
+ Yields
209
+ ------
210
+ TaskResponse
211
+ Stream of task information
212
+ """
213
+ async for task in self.stream_service_method(
214
+ "stream_swarm_tasks",
215
+ StrId(id=swarm_id),
216
+ ):
217
+ yield task
218
+
219
+ async def start_swarm(self, swarm_id: str) -> Response:
220
+ """
221
+ Start a swarm.
222
+
223
+ Parameters
224
+ ----------
225
+ swarm_id : str
226
+ ID of the swarm to start
227
+
228
+ Returns
229
+ -------
230
+ Response
231
+ Start operation response
232
+ """
233
+ return await self.call_service_method(
234
+ "start_swarm",
235
+ StrId(id=swarm_id),
236
+ )
237
+
238
+ async def stop_swarm(
239
+ self, swarm_id: str, force: bool = False, remove: bool = False
240
+ ) -> Response:
241
+ """
242
+ Stop a running swarm.
243
+
244
+ Parameters
245
+ ----------
246
+ swarm_id : str
247
+ ID of the swarm to stop
248
+ force : bool
249
+ Whether to force stop the swarm
250
+ remove : bool
251
+ Whether to remove the swarm after stopping
252
+
253
+ Returns
254
+ -------
255
+ Response
256
+ Stop operation response
257
+ """
258
+ return await self.call_service_method(
259
+ "stop_swarm",
260
+ StopSwarmRequest(
261
+ swarm_id=swarm_id,
262
+ force=force,
263
+ remove=remove,
264
+ ),
265
+ )
266
+
267
+ async def remove_swarm(self, swarm_id: str) -> Response:
268
+ """
269
+ Remove a swarm from the system.
270
+
271
+ Parameters
272
+ ----------
273
+ swarm_id : str
274
+ ID of the swarm to remove
275
+
276
+ Returns
277
+ -------
278
+ Response
279
+ Removal confirmation response
280
+ """
281
+ return await self.call_service_method(
282
+ "remove_swarm",
283
+ StrId(id=swarm_id),
284
+ )
285
+
286
+ async def select_results(
287
+ self, swarm_id: str, tag: str
288
+ ) -> AsyncIterator[ResultsResponse]:
289
+ """
290
+ Select results based on query criteria.
291
+
292
+ Parameters
293
+ ----------
294
+ swarm_id : str
295
+ ID of the swarm
296
+ tag : str
297
+ The result tag
298
+
299
+ Yields
300
+ ------
301
+ ResultsResponse
302
+ Stream of results
303
+ """
304
+ async for result in self.stream_service_method(
305
+ "select_results",
306
+ ResultsRequest(swarm_id=swarm_id, tag=tag),
307
+ ):
308
+ yield result
309
+
310
+ async def stream_results(
311
+ self, swarm_id: str, tag: str
312
+ ) -> AsyncIterator[ResultsResponse]:
313
+ """
314
+ Stream results for a specific swarm and tag.
315
+
316
+ Parameters
317
+ ----------
318
+ swarm_id : str
319
+ ID of the swarm
320
+ tag : str
321
+ The result tag
322
+
323
+ Yields
324
+ ------
325
+ ResultsResponse
326
+ Stream of results
327
+ """
328
+ async for result in self.stream_service_method(
329
+ "stream_results",
330
+ ResultsRequest(swarm_id=swarm_id, tag=tag),
331
+ ):
332
+ yield result
333
+
334
+ async def delete_results(
335
+ self,
336
+ swarm_id: str,
337
+ tag: str,
338
+ node_id: Optional[str] = None,
339
+ task_id: Optional[str] = None,
340
+ iteration: Optional[int] = None,
341
+ ) -> Response:
342
+ """
343
+ Delete results for a specific swarm and tag.
344
+
345
+ Parameters
346
+ ----------
347
+ swarm_id : str
348
+ ID of the swarm
349
+ tag : str
350
+ The tag of the results to delete
351
+ node_id : Optional[str]
352
+ Filter by node ID
353
+ task_id : Optional[str]
354
+ Filter by task ID
355
+ iteration : Optional[int]
356
+ Filter by iteration number
357
+
358
+ Returns
359
+ -------
360
+ Response
361
+ Deletion confirmation response
362
+ """
363
+ request = DeleteResultsRequest(swarm_id=swarm_id, tag=tag)
364
+ if node_id:
365
+ request.node_id = node_id
366
+ if task_id:
367
+ request.task_id = task_id
368
+ if iteration is not None:
369
+ request.iteration = iteration
370
+ return await self.call_service_method(
371
+ "delete_results",
372
+ request,
373
+ )
374
+
375
+ async def list_result_tags(self, swarm_id: str) -> Tags:
376
+ """
377
+ List result tags for a specific swarm.
378
+
379
+ Parameters
380
+ ----------
381
+ swarm_id : str
382
+ ID of the swarm
383
+
384
+ Returns
385
+ -------
386
+ Tags
387
+ Tags with usage information
388
+ """
389
+ return await self.call_service_method(
390
+ "list_result_tags",
391
+ StrId(id=swarm_id),
392
+ )
393
+
394
+ async def collect_logs(
395
+ self,
396
+ swarm_id: str,
397
+ node_ids: Optional[List[str]] = None,
398
+ task_ids: Optional[List[str]] = None,
399
+ severity: Optional[List[str]] = None,
400
+ start_time: Optional[datetime] = None,
401
+ end_time: Optional[datetime] = None,
402
+ limit: Optional[int] = None,
403
+ sort_order: Optional[str] = None,
404
+ iteration: Optional[int] = None,
405
+ circular: Optional[int] = None,
406
+ ) -> AsyncIterator[LogResponse]:
407
+ """
408
+ Collect logs based on a query.
409
+
410
+ Parameters
411
+ ----------
412
+ swarm_id : str
413
+ ID of the swarm
414
+ node_ids : Optional[List[str]]
415
+ Filter by node IDs
416
+ task_ids : Optional[List[str]]
417
+ Filter by task IDs
418
+ severity : Optional[List[str]]
419
+ Filter by severity levels
420
+ start_time : Optional[datetime]
421
+ Start time for filtering logs
422
+ end_time : Optional[datetime]
423
+ End time for filtering logs
424
+ limit : Optional[int]
425
+ Maximum number of logs to return
426
+ sort_order : Optional[str]
427
+ Sort order ("asc" or "desc")
428
+ iteration : Optional[int]
429
+ Filter by specific iteration
430
+ circular : Optional[int]
431
+ Filter by specific circular
432
+
433
+ Yields
434
+ ------
435
+ LogResponse
436
+ Stream of log entries
437
+ """
438
+ request = LogQuery(swarm_id=swarm_id)
439
+ if node_ids:
440
+ request.node_ids.extend(node_ids)
441
+ if task_ids:
442
+ request.task_ids.extend(task_ids)
443
+ if severity:
444
+ request.severity.extend(severity)
445
+ if start_time:
446
+ request.start_time = start_time
447
+ if end_time:
448
+ request.end_time = end_time
449
+ if limit:
450
+ request.limit = limit
451
+ if sort_order:
452
+ request.sort_order = sort_order
453
+ if iteration is not None:
454
+ request.iteration = iteration
455
+ if circular is not None:
456
+ request.circular = circular
457
+ async for log in self.stream_service_method(
458
+ "collect_logs",
459
+ request,
460
+ ):
461
+ yield log
462
+
463
+ async def stream_logs(self, swarm_id: str) -> AsyncIterator[LogResponse]:
464
+ """
465
+ Stream logs for a specific swarm.
466
+
467
+ Parameters
468
+ ----------
469
+ swarm_id : str
470
+ ID of the swarm
471
+
472
+ Yields
473
+ ------
474
+ LogResponse
475
+ Stream of log entries
476
+ """
477
+ async for log in self.stream_service_method(
478
+ "stream_logs",
479
+ StrId(id=swarm_id),
480
+ ):
481
+ yield log
482
+
483
+ async def initialize_global(self, globals: AsyncIterator[Global]) -> Response:
484
+ """
485
+ Initialize global values for a swarm.
486
+
487
+ Parameters
488
+ ----------
489
+ globals : AsyncIterator[Global]
490
+ Stream of global values
491
+
492
+ Returns
493
+ -------
494
+ Response
495
+ Initialization response
496
+ """
497
+ return await self.call_service_method(
498
+ "initialize_global",
499
+ globals,
500
+ )
501
+
502
+ async def select_global(
503
+ self, swarm_id: str, tag: str
504
+ ) -> AsyncIterator[SelectGlobalResponse]:
505
+ """
506
+ Select global data for a specific swarm and tag.
507
+
508
+ Parameters
509
+ ----------
510
+ swarm_id : str
511
+ ID of the swarm
512
+ tag : str
513
+ The tag
514
+
515
+ Yields
516
+ ------
517
+ SelectGlobalResponse
518
+ Stream of global data
519
+ """
520
+ async for result in self.stream_service_method(
521
+ "select_global",
522
+ GlobalRequest(swarm_id=swarm_id, tag=tag),
523
+ ):
524
+ yield result
525
+
526
+ async def list_global_tags(self, swarm_id: str) -> Tags:
527
+ """
528
+ List global tags for a specific swarm.
529
+
530
+ Parameters
531
+ ----------
532
+ swarm_id : str
533
+ ID of the swarm
534
+
535
+ Returns
536
+ -------
537
+ Tags
538
+ Tags with usage information
539
+ """
540
+ return await self.call_service_method(
541
+ "list_global_tags",
542
+ StrId(id=swarm_id),
543
+ )
544
+
545
+ async def initialize_networks(self, networks: Networks) -> Response:
546
+ """
547
+ Initialize networks for a swarm.
548
+
549
+ Parameters
550
+ ----------
551
+ networks : Networks
552
+ Network configuration
553
+
554
+ Returns
555
+ -------
556
+ Response
557
+ Initialization response
558
+ """
559
+ return await self.call_service_method(
560
+ "initialize_networks",
561
+ networks,
562
+ )