codecraftai-restclient-crusoe 1.2.0__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 (40) hide show
  1. ccai/restclient/crusoe/__init__.py +3 -0
  2. ccai/restclient/crusoe/apigroups/__init__.py +3 -0
  3. ccai/restclient/crusoe/apigroups/disksgroup.py +250 -0
  4. ccai/restclient/crusoe/apigroups/groupsupport.py +180 -0
  5. ccai/restclient/crusoe/apigroups/imagesgroup.py +66 -0
  6. ccai/restclient/crusoe/apigroups/operationsgroup.py +56 -0
  7. ccai/restclient/crusoe/apigroups/placementgroupsgroup.py +157 -0
  8. ccai/restclient/crusoe/apigroups/securitygroupsgroup.py +192 -0
  9. ccai/restclient/crusoe/apigroups/sshkeysgroup.py +149 -0
  10. ccai/restclient/crusoe/apigroups/subnetsgroup.py +168 -0
  11. ccai/restclient/crusoe/apigroups/tagsgroup.py +100 -0
  12. ccai/restclient/crusoe/apigroups/vmsgroup.py +280 -0
  13. ccai/restclient/crusoe/apigroups/vpcsgroup.py +144 -0
  14. ccai/restclient/crusoe/aspectscrusoe.py +104 -0
  15. ccai/restclient/crusoe/crusoeclient.py +354 -0
  16. ccai/restclient/crusoe/exceptions/__init__.py +3 -0
  17. ccai/restclient/crusoe/exceptions/crusoeexceptions.py +46 -0
  18. ccai/restclient/crusoe/model/__init__.py +3 -0
  19. ccai/restclient/crusoe/model/crusoedisk.py +98 -0
  20. ccai/restclient/crusoe/model/crusoeimage.py +82 -0
  21. ccai/restclient/crusoe/model/crusoeoperationresult.py +85 -0
  22. ccai/restclient/crusoe/model/crusoeplacementgroup.py +94 -0
  23. ccai/restclient/crusoe/model/crusoesecuritygroup.py +99 -0
  24. ccai/restclient/crusoe/model/crusoesshkey.py +78 -0
  25. ccai/restclient/crusoe/model/crusoesubnet.py +92 -0
  26. ccai/restclient/crusoe/model/crusoetaskhandle.py +213 -0
  27. ccai/restclient/crusoe/model/crusoevm.py +114 -0
  28. ccai/restclient/crusoe/model/crusoevpc.py +87 -0
  29. ccai/restclient/crusoe/py.typed +0 -0
  30. ccai/restclient/crusoe/specs/__init__.py +3 -0
  31. ccai/restclient/crusoe/specs/crusoediskspec.py +58 -0
  32. ccai/restclient/crusoe/specs/crusoeplacementgroupspec.py +57 -0
  33. ccai/restclient/crusoe/specs/crusoesecuritygroupspec.py +63 -0
  34. ccai/restclient/crusoe/specs/crusoesubnetspec.py +60 -0
  35. ccai/restclient/crusoe/specs/crusoevmlaunchspec.py +103 -0
  36. ccai/restclient/crusoe/specs/crusoevpcspec.py +53 -0
  37. codecraftai_restclient_crusoe-1.2.0.dist-info/METADATA +85 -0
  38. codecraftai_restclient_crusoe-1.2.0.dist-info/RECORD +40 -0
  39. codecraftai_restclient_crusoe-1.2.0.dist-info/WHEEL +4 -0
  40. codecraftai_restclient_crusoe-1.2.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,3 @@
1
+ __author__ = "Myron Walker"
2
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
3
+ __credits__ = []
@@ -0,0 +1,3 @@
1
+ __author__ = "Myron Walker"
2
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
3
+ __credits__ = []
@@ -0,0 +1,250 @@
1
+ """
2
+ .. module:: disksgroup
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`DisksGroup` api group
5
+ exposing the Crusoe Cloud disk endpoints.
6
+
7
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
8
+ """
9
+
10
+ __author__ = "Myron Walker"
11
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
12
+ __credits__ = []
13
+
14
+
15
+ from typing import Any, Dict, List, Optional, Tuple
16
+
17
+ from ccai.errors.exceptions import SemanticError
18
+
19
+ from ccai.restclient.base.restapigroup import RestApiGroup
20
+
21
+ from ccai.restclient.crusoe.aspectscrusoe import (
22
+ AspectsCrusoe, DEFAULT_CRUSOE_ASPECTS
23
+ )
24
+ from ccai.restclient.crusoe.apigroups.groupsupport import (
25
+ compose_leaf, iter_paged_items, raise_for_status, safe_json
26
+ )
27
+ from ccai.restclient.crusoe.model.crusoedisk import CrusoeDisk
28
+ from ccai.restclient.crusoe.model.crusoetaskhandle import CrusoeTaskHandle
29
+ from ccai.restclient.crusoe.specs.crusoediskspec import CrusoeDiskSpec
30
+
31
+
32
+ def extract_operation_id(*, payload: Dict[str, Any]) -> Optional[str]:
33
+ """
34
+ Extract a Crusoe operation identifier from a response payload.
35
+
36
+ :param payload: The decoded API payload.
37
+
38
+ :returns: The operation id, or ``None`` when the call was synchronous.
39
+ """
40
+ operation = payload.get("operation", None)
41
+ if isinstance(operation, dict):
42
+ op_id = operation.get("id", None)
43
+ if op_id is not None and len(str(op_id)) > 0:
44
+ rtnval: Optional[str] = str(op_id)
45
+ return rtnval
46
+
47
+ op_id = payload.get("operation_id", None)
48
+ if op_id is not None and len(str(op_id)) > 0:
49
+ rtnval = str(op_id)
50
+ return rtnval
51
+
52
+ rtnval = None
53
+ return rtnval
54
+
55
+
56
+ class DisksGroup(RestApiGroup):
57
+ """
58
+ :class:`DisksGroup` exposes the Crusoe Cloud disk endpoints — create,
59
+ attach, detach, list, and no-op delete. Async operations return a
60
+ :class:`CrusoeTaskHandle` alongside the disk record.
61
+ """
62
+
63
+ def create(self, *, project_id: str, spec: CrusoeDiskSpec,
64
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS
65
+ ) -> Tuple[CrusoeDisk, Optional[CrusoeTaskHandle]]:
66
+ """
67
+ Create a disk, returning the record and an optional task handle.
68
+
69
+ :param project_id: The owning project identifier.
70
+ :param spec: The :class:`CrusoeDiskSpec` describing the disk.
71
+ :param aspects: Behaviour control for the call.
72
+
73
+ :returns: A tuple of (:class:`CrusoeDisk`, optional
74
+ :class:`CrusoeTaskHandle`).
75
+ """
76
+ if spec is None:
77
+ raise SemanticError("'spec' must be a CrusoeDiskSpec.")
78
+
79
+ client = self.client
80
+ leaf = compose_leaf(base=client.base_leaf,
81
+ segments=["projects", project_id, "disks"])
82
+ response = client.request(method="POST", leaf=leaf,
83
+ json_body=spec.to_payload(), aspects=aspects)
84
+ raise_for_status(response=response, action="create disk")
85
+
86
+ payload = safe_json(response=response)
87
+ disk = CrusoeDisk.from_dict(payload)
88
+ handle = self._handle_for(payload=payload)
89
+
90
+ rtnval = (disk, handle)
91
+ return rtnval
92
+
93
+ def attach(self, *, project_id: str, disk_id: str, instance_id: str,
94
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS) -> CrusoeTaskHandle:
95
+ """
96
+ Attach a disk to a VM.
97
+
98
+ :param project_id: The owning project identifier.
99
+ :param disk_id: The disk identifier to attach.
100
+ :param instance_id: The VM identifier to attach the disk to.
101
+ :param aspects: Behaviour control for the call.
102
+
103
+ :returns: A :class:`CrusoeTaskHandle` for the attach operation.
104
+ """
105
+ rtnval = self._attach_detach(project_id=project_id, disk_id=disk_id,
106
+ instance_id=instance_id, attach=True,
107
+ aspects=aspects)
108
+ return rtnval
109
+
110
+ def detach(self, *, project_id: str, disk_id: str, instance_id: str,
111
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS) -> CrusoeTaskHandle:
112
+ """
113
+ Detach a disk from a VM.
114
+
115
+ :param project_id: The owning project identifier.
116
+ :param disk_id: The disk identifier to detach.
117
+ :param instance_id: The VM identifier to detach the disk from.
118
+ :param aspects: Behaviour control for the call.
119
+
120
+ :returns: A :class:`CrusoeTaskHandle` for the detach operation.
121
+ """
122
+ rtnval = self._attach_detach(project_id=project_id, disk_id=disk_id,
123
+ instance_id=instance_id, attach=False,
124
+ aspects=aspects)
125
+ return rtnval
126
+
127
+ def list(self, *, project_id: str,
128
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS) -> List[CrusoeDisk]:
129
+ """
130
+ List every disk in a project, following paging cursors.
131
+
132
+ :param project_id: The owning project identifier.
133
+ :param aspects: Behaviour control for the call.
134
+
135
+ :returns: A list of :class:`CrusoeDisk` records.
136
+ """
137
+ if project_id is None or len(project_id) == 0:
138
+ raise SemanticError("'project_id' must be a non-empty string.")
139
+
140
+ client = self.client
141
+ leaf = compose_leaf(base=client.base_leaf,
142
+ segments=["projects", project_id, "disks"])
143
+
144
+ def _fetch(cursor: Optional[str]) -> Dict:
145
+ params: Dict[str, str] = {"page_size": str(aspects.page_size)}
146
+ if cursor is not None:
147
+ params["page_token"] = cursor
148
+ response = client.request(method="GET", leaf=leaf,
149
+ params=params, aspects=aspects)
150
+ raise_for_status(response=response, action="list disks")
151
+ page = safe_json(response=response)
152
+ return page
153
+
154
+ rtnval: List[CrusoeDisk] = []
155
+ for entry in iter_paged_items(fetch_page=_fetch, items_field="items"):
156
+ rtnval.append(CrusoeDisk.from_dict(entry))
157
+ return rtnval
158
+
159
+ def delete(self, *, project_id: str, disk_id: str,
160
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS) -> None:
161
+ """
162
+ Delete a disk. An unknown id is treated as already removed.
163
+
164
+ :param project_id: The owning project identifier.
165
+ :param disk_id: The disk identifier to delete.
166
+ :param aspects: Behaviour control for the call.
167
+
168
+ :returns: ``None``.
169
+ """
170
+ if disk_id is None or len(disk_id) == 0:
171
+ raise SemanticError("'disk_id' must be a non-empty string.")
172
+
173
+ client = self.client
174
+ leaf = compose_leaf(base=client.base_leaf,
175
+ segments=["projects", project_id, "disks",
176
+ disk_id])
177
+ response = client.request(method="DELETE", leaf=leaf, aspects=aspects)
178
+
179
+ status = response.status_code
180
+ if 200 <= status < 300:
181
+ return
182
+ if status == 404:
183
+ return
184
+
185
+ raise_for_status(response=response, action="delete disk")
186
+ return
187
+
188
+ def _attach_detach(self, *, project_id: str, disk_id: str,
189
+ instance_id: str, attach: bool,
190
+ aspects: AspectsCrusoe) -> CrusoeTaskHandle:
191
+ """
192
+ Shared implementation for attach and detach.
193
+
194
+ :param project_id: The owning project identifier.
195
+ :param disk_id: The disk identifier.
196
+ :param instance_id: The VM identifier.
197
+ :param attach: ``True`` for attach, ``False`` for detach.
198
+ :param aspects: Behaviour control for the call.
199
+
200
+ :returns: A :class:`CrusoeTaskHandle` for the operation.
201
+ """
202
+ if disk_id is None or len(disk_id) == 0:
203
+ raise SemanticError("'disk_id' must be a non-empty string.")
204
+ if instance_id is None or len(instance_id) == 0:
205
+ raise SemanticError("'instance_id' must be a non-empty string.")
206
+
207
+ verb = "attach"
208
+ if attach is False:
209
+ verb = "detach"
210
+
211
+ client = self.client
212
+ leaf = compose_leaf(base=client.base_leaf,
213
+ segments=["projects", project_id, "disks",
214
+ disk_id, verb])
215
+ body: Dict[str, Any] = {"instance_id": instance_id}
216
+ response = client.request(method="POST", leaf=leaf,
217
+ json_body=body, aspects=aspects)
218
+ raise_for_status(response=response,
219
+ action="{} disk".format(verb))
220
+
221
+ payload = safe_json(response=response)
222
+ handle = self._handle_for(payload=payload)
223
+ if handle is None:
224
+ err_msg = (
225
+ "Crusoe disk {0} response did not include an operation "
226
+ "id.".format(verb)
227
+ )
228
+ raise SemanticError(err_msg)
229
+
230
+ rtnval = handle
231
+ return rtnval
232
+
233
+ def _handle_for(self, *,
234
+ payload: Dict[str, Any]) -> Optional[CrusoeTaskHandle]:
235
+ """
236
+ Build a :class:`CrusoeTaskHandle` from a response payload.
237
+
238
+ :param payload: The decoded API payload.
239
+
240
+ :returns: A :class:`CrusoeTaskHandle`, or ``None`` when the call
241
+ was synchronous.
242
+ """
243
+ operation_id = extract_operation_id(payload=payload)
244
+ rtnval: Optional[CrusoeTaskHandle] = None
245
+ if operation_id is not None:
246
+ rtnval = CrusoeTaskHandle(
247
+ operation_id=operation_id,
248
+ operations_group=self.client.operations
249
+ )
250
+ return rtnval
@@ -0,0 +1,180 @@
1
+ """
2
+ .. module:: groupsupport
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains shared helpers used by the Crusoe
5
+ api-group classes — URL composition, paging, and HTTP
6
+ error reclassification.
7
+
8
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
9
+ """
10
+
11
+ __author__ = "Myron Walker"
12
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
13
+ __credits__ = []
14
+
15
+
16
+ import os
17
+
18
+ from typing import Any, Callable, Dict, Iterator, List, Optional
19
+ from urllib.parse import quote
20
+
21
+ from requests import Response
22
+
23
+ from ccai.errors.exceptions import SemanticError
24
+
25
+ from ccai.restclient.crusoe.exceptions.crusoeexceptions import (
26
+ CrusoeApiError, CrusoeAuthenticationError
27
+ )
28
+
29
+
30
+ def encode_segment(*, segment: str) -> str:
31
+ """
32
+ Percent-encode a single URL path segment.
33
+
34
+ Each segment is encoded independently with no characters left
35
+ unescaped beyond the unreserved set, so embedded slashes and other
36
+ reserved characters cannot break out of the segment.
37
+
38
+ :param segment: The path segment to encode.
39
+
40
+ :returns: The percent-encoded segment.
41
+
42
+ :raises: :class:`SemanticError` when the segment is ``None`` or empty.
43
+ """
44
+ if segment is None:
45
+ raise SemanticError("URL path segment must not be None.")
46
+ if not isinstance(segment, str):
47
+ raise SemanticError("URL path segment must be a string.")
48
+ if len(segment) == 0:
49
+ raise SemanticError("URL path segment must not be empty.")
50
+
51
+ rtnval = quote(segment, safe="")
52
+ return rtnval
53
+
54
+
55
+ def compose_leaf(*, base: str, segments: List[str]) -> str:
56
+ """
57
+ Compose a leaf path by percent-encoding each segment independently
58
+ and joining them under ``base``.
59
+
60
+ :param base: The API base path (e.g. ``/v1alpha5``).
61
+ :param segments: The ordered list of path segments to encode.
62
+
63
+ :returns: The composed leaf path beginning with ``/``.
64
+
65
+ :raises: :class:`SemanticError` when any segment is empty / ``None``.
66
+ """
67
+ if segments is None:
68
+ raise SemanticError("compose_leaf requires a non-None segments list.")
69
+
70
+ encoded: List[str] = []
71
+ for segment in segments:
72
+ encoded.append(encode_segment(segment=segment))
73
+
74
+ trimmed_base = base
75
+ if trimmed_base.endswith("/"):
76
+ trimmed_base = trimmed_base[:-1]
77
+
78
+ joined = "/".join(encoded)
79
+ rtnval = "{0}/{1}".format(trimmed_base, joined)
80
+ return rtnval
81
+
82
+
83
+ def raise_for_status(*, response: Response, action: str) -> None:
84
+ """
85
+ Reclassify a non-2xx Crusoe response into a typed exception.
86
+
87
+ HTTP 401 and 403 reclassify into :class:`CrusoeAuthenticationError`;
88
+ every other non-2xx status reclassifies into :class:`CrusoeApiError`.
89
+
90
+ :param response: The :class:`Response` to inspect.
91
+ :param action: A short description of the attempted action.
92
+
93
+ :returns: ``None``.
94
+
95
+ :raises: :class:`CrusoeAuthenticationError`, :class:`CrusoeApiError`.
96
+ """
97
+ status = response.status_code
98
+ if 200 <= status < 300:
99
+ return
100
+
101
+ err_msg_lines = ["Crusoe API call failed: {}.".format(action)]
102
+ err_msg_lines.append("STATUS: {}".format(status))
103
+ err_msg_lines.append("RESPONSE:")
104
+ err_msg_lines.append(response.text)
105
+ err_msg = os.linesep.join(err_msg_lines)
106
+
107
+ if status == 401 or status == 403:
108
+ raise CrusoeAuthenticationError(err_msg)
109
+
110
+ raise CrusoeApiError(err_msg)
111
+
112
+
113
+ def safe_json(*, response: Response) -> Dict[str, Any]:
114
+ """
115
+ Parse a response body as a JSON object, degrading to an empty dict.
116
+
117
+ :param response: The :class:`Response` to parse.
118
+
119
+ :returns: The decoded object, or an empty dict.
120
+ """
121
+ try:
122
+ payload = response.json()
123
+ except ValueError:
124
+ rtnval: Dict[str, Any] = {}
125
+ return rtnval
126
+
127
+ if not isinstance(payload, dict):
128
+ rtnval = {}
129
+ return rtnval
130
+
131
+ rtnval = payload
132
+ return rtnval
133
+
134
+
135
+ def iter_paged_items(*, fetch_page: Callable[[Optional[str]], Dict[str, Any]],
136
+ items_field: str = "items",
137
+ cursor_field: str = "next_page_token"
138
+ ) -> Iterator[Dict[str, Any]]:
139
+ """
140
+ Iterate a cursor-paginated Crusoe list endpoint.
141
+
142
+ The traversal yields every item across every page; it terminates
143
+ when the page payload reports no further cursor token.
144
+
145
+ :param fetch_page: Callable accepting the current cursor token
146
+ (``None`` on the first call) and returning a page dict.
147
+ :param items_field: Name of the items field on each page payload.
148
+ :param cursor_field: Name of the next-cursor field on each page.
149
+
150
+ :returns: An iterator over the item dictionaries.
151
+
152
+ :raises: :class:`CrusoeApiError` when the endpoint returns a cursor
153
+ token that has already been seen (cursor cycle).
154
+ """
155
+ cursor: Optional[str] = None
156
+ seen_cursors: List[str] = []
157
+ while True:
158
+ page = fetch_page(cursor)
159
+
160
+ items = page.get(items_field, None)
161
+ if items is None:
162
+ items = []
163
+
164
+ for item in items:
165
+ yield item
166
+
167
+ next_cursor = page.get(cursor_field, None)
168
+ if next_cursor is None or len(str(next_cursor)) == 0:
169
+ break
170
+
171
+ next_cursor_str = str(next_cursor)
172
+ if next_cursor_str in seen_cursors:
173
+ err_msg_lines = ["Crusoe cursor pagination detected a cursor cycle."]
174
+ err_msg_lines.append("REPEATED CURSOR: {}".format(next_cursor_str))
175
+ err_msg = os.linesep.join(err_msg_lines)
176
+ raise CrusoeApiError(err_msg)
177
+
178
+ seen_cursors.append(next_cursor_str)
179
+ cursor = next_cursor
180
+ return
@@ -0,0 +1,66 @@
1
+ """
2
+ .. module:: imagesgroup
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`ImagesGroup` api group
5
+ exposing the Crusoe Cloud machine image endpoints.
6
+
7
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
8
+ """
9
+
10
+ __author__ = "Myron Walker"
11
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
12
+ __credits__ = []
13
+
14
+
15
+ from typing import Dict, List, Optional
16
+
17
+ from ccai.errors.exceptions import SemanticError
18
+
19
+ from ccai.restclient.base.restapigroup import RestApiGroup
20
+
21
+ from ccai.restclient.crusoe.aspectscrusoe import (
22
+ AspectsCrusoe, DEFAULT_CRUSOE_ASPECTS
23
+ )
24
+ from ccai.restclient.crusoe.apigroups.groupsupport import (
25
+ compose_leaf, iter_paged_items, raise_for_status, safe_json
26
+ )
27
+ from ccai.restclient.crusoe.model.crusoeimage import CrusoeImage
28
+
29
+
30
+ class ImagesGroup(RestApiGroup):
31
+ """
32
+ :class:`ImagesGroup` exposes the Crusoe Cloud machine image lookup
33
+ endpoint, with transparent cursor-paged traversal.
34
+ """
35
+
36
+ def list(self, *, project_id: str,
37
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS) -> List[CrusoeImage]:
38
+ """
39
+ List every available machine image, following paging cursors.
40
+
41
+ :param project_id: The owning project identifier.
42
+ :param aspects: Behaviour control for the call.
43
+
44
+ :returns: A list of :class:`CrusoeImage` records.
45
+ """
46
+ if project_id is None or len(project_id) == 0:
47
+ raise SemanticError("'project_id' must be a non-empty string.")
48
+
49
+ client = self.client
50
+ leaf = compose_leaf(base=client.base_leaf,
51
+ segments=["projects", project_id, "images"])
52
+
53
+ def _fetch(cursor: Optional[str]) -> Dict:
54
+ params: Dict[str, str] = {"page_size": str(aspects.page_size)}
55
+ if cursor is not None:
56
+ params["page_token"] = cursor
57
+ response = client.request(method="GET", leaf=leaf,
58
+ params=params, aspects=aspects)
59
+ raise_for_status(response=response, action="list images")
60
+ page = safe_json(response=response)
61
+ return page
62
+
63
+ rtnval: List[CrusoeImage] = []
64
+ for entry in iter_paged_items(fetch_page=_fetch, items_field="items"):
65
+ rtnval.append(CrusoeImage.from_dict(entry))
66
+ return rtnval
@@ -0,0 +1,56 @@
1
+ """
2
+ .. module:: operationsgroup
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`OperationsGroup` api group
5
+ exposing the Crusoe Cloud long-running operation endpoints.
6
+
7
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
8
+ """
9
+
10
+ __author__ = "Myron Walker"
11
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
12
+ __credits__ = []
13
+
14
+
15
+ from ccai.errors.exceptions import SemanticError
16
+
17
+ from ccai.restclient.base.restapigroup import RestApiGroup
18
+
19
+ from ccai.restclient.crusoe.aspectscrusoe import (
20
+ AspectsCrusoe, DEFAULT_CRUSOE_ASPECTS
21
+ )
22
+ from ccai.restclient.crusoe.apigroups.groupsupport import (
23
+ compose_leaf, raise_for_status, safe_json
24
+ )
25
+ from ccai.restclient.crusoe.model.crusoeoperationresult import (
26
+ CrusoeOperationResult
27
+ )
28
+
29
+
30
+ class OperationsGroup(RestApiGroup):
31
+ """
32
+ :class:`OperationsGroup` exposes the Crusoe Cloud operations endpoint
33
+ consumed by :class:`CrusoeTaskHandle.wait` to poll async operations.
34
+ """
35
+
36
+ def get(self, *, operation_id: str,
37
+ aspects: AspectsCrusoe = DEFAULT_CRUSOE_ASPECTS) -> CrusoeOperationResult:
38
+ """
39
+ Retrieve the status of a single Crusoe operation.
40
+
41
+ :param operation_id: The Crusoe operation identifier.
42
+ :param aspects: Behaviour control for the call.
43
+
44
+ :returns: A :class:`CrusoeOperationResult` record.
45
+ """
46
+ if operation_id is None or len(operation_id) == 0:
47
+ raise SemanticError("'operation_id' must be a non-empty string.")
48
+
49
+ client = self.client
50
+ leaf = compose_leaf(base=client.base_leaf,
51
+ segments=["operations", operation_id])
52
+ response = client.request(method="GET", leaf=leaf, aspects=aspects)
53
+ raise_for_status(response=response, action="get operation")
54
+
55
+ rtnval = CrusoeOperationResult.from_dict(safe_json(response=response))
56
+ return rtnval