codecraftai-restclient-lambdalabs 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 (30) hide show
  1. ccai/restclient/lambdalabs/__init__.py +11 -0
  2. ccai/restclient/lambdalabs/apigroups/__init__.py +12 -0
  3. ccai/restclient/lambdalabs/apigroups/clustersgroup.py +151 -0
  4. ccai/restclient/lambdalabs/apigroups/filesystemsgroup.py +133 -0
  5. ccai/restclient/lambdalabs/apigroups/groupsupport.py +216 -0
  6. ccai/restclient/lambdalabs/apigroups/imagesgroup.py +69 -0
  7. ccai/restclient/lambdalabs/apigroups/instancesgroup.py +181 -0
  8. ccai/restclient/lambdalabs/apigroups/instancetypesgroup.py +96 -0
  9. ccai/restclient/lambdalabs/apigroups/pagingsupport.py +59 -0
  10. ccai/restclient/lambdalabs/apigroups/sshkeysgroup.py +133 -0
  11. ccai/restclient/lambdalabs/aspectslambdalabs.py +109 -0
  12. ccai/restclient/lambdalabs/exceptions/__init__.py +12 -0
  13. ccai/restclient/lambdalabs/exceptions/lambdalabserrors.py +46 -0
  14. ccai/restclient/lambdalabs/lambdalabsclient.py +598 -0
  15. ccai/restclient/lambdalabs/model/__init__.py +12 -0
  16. ccai/restclient/lambdalabs/model/lambdalabscluster.py +179 -0
  17. ccai/restclient/lambdalabs/model/lambdalabsfilesystem.py +151 -0
  18. ccai/restclient/lambdalabs/model/lambdalabsimage.py +149 -0
  19. ccai/restclient/lambdalabs/model/lambdalabsinstance.py +272 -0
  20. ccai/restclient/lambdalabs/model/lambdalabsinstancetype.py +226 -0
  21. ccai/restclient/lambdalabs/model/lambdalabssshkey.py +114 -0
  22. ccai/restclient/lambdalabs/model/lambdalabsterminationresult.py +128 -0
  23. ccai/restclient/lambdalabs/py.typed +0 -0
  24. ccai/restclient/lambdalabs/specs/__init__.py +12 -0
  25. ccai/restclient/lambdalabs/specs/lambdalabsclusterspec.py +142 -0
  26. ccai/restclient/lambdalabs/specs/lambdalabslaunchspec.py +144 -0
  27. codecraftai_restclient_lambdalabs-1.2.0.dist-info/METADATA +86 -0
  28. codecraftai_restclient_lambdalabs-1.2.0.dist-info/RECORD +30 -0
  29. codecraftai_restclient_lambdalabs-1.2.0.dist-info/WHEEL +4 -0
  30. codecraftai_restclient_lambdalabs-1.2.0.dist-info/licenses/LICENSE.md +204 -0
@@ -0,0 +1,11 @@
1
+ """
2
+ .. module:: lambdalabs
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Code Craft AI namespace package.
5
+
6
+ .. moduleauthor:: Myron Walker <myron.walker@gmail.com>
7
+ """
8
+
9
+ __author__ = "Myron Walker"
10
+ __copyright__ = "Copyright 2026, Code Craft AI LLC"
11
+ __credits__ = []
@@ -0,0 +1,12 @@
1
+ """
2
+ .. module:: apigroups
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Package that contains the Lambda Labs REST client api
5
+ groups.
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__ = []
@@ -0,0 +1,151 @@
1
+ """
2
+ .. module:: clustersgroup
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`ClustersGroup` api group
5
+ exposing the Lambda Labs 1-click-clusters 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 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.lambdalabs.aspectslambdalabs import (
22
+ AspectsLambdalabs, DEFAULT_LAMBDALABS_ASPECTS
23
+ )
24
+ from ccai.restclient.lambdalabs.apigroups.groupsupport import (
25
+ compose_leaf, extract_data, raise_for_status, require_identifier,
26
+ safe_json
27
+ )
28
+ from ccai.restclient.lambdalabs.apigroups.pagingsupport import (
29
+ collect_all_pages
30
+ )
31
+ from ccai.restclient.lambdalabs.model.lambdalabscluster import (
32
+ LambdalabsCluster
33
+ )
34
+ from ccai.restclient.lambdalabs.specs.lambdalabsclusterspec import (
35
+ LambdalabsClusterSpec
36
+ )
37
+
38
+
39
+ class ClustersGroup(RestApiGroup):
40
+ """
41
+ :class:`ClustersGroup` exposes the Lambda Labs 1-click-clusters
42
+ endpoints — list, create, get, and delete (idempotent).
43
+ """
44
+
45
+ def list(self, *,
46
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
47
+ ) -> List[LambdalabsCluster]:
48
+ """
49
+ List every 1-click cluster, following paging cursors.
50
+
51
+ :param aspects: Behaviour control for the call.
52
+
53
+ :returns: A list of :class:`LambdalabsCluster` records.
54
+ """
55
+ client = self.client
56
+
57
+ def _fetch_page(cursor: Optional[str]) -> Tuple[List[LambdalabsCluster], Optional[str]]:
58
+ leaf = compose_leaf(parts=["1-click-clusters"])
59
+ params = None
60
+ if cursor is not None:
61
+ params = {"cursor": cursor}
62
+ response = client.request(method="GET", leaf=leaf, params=params,
63
+ aspects=aspects)
64
+ raise_for_status(response=response, action="list clusters")
65
+
66
+ data = extract_data(response=response, action="list clusters")
67
+ page_items: List[LambdalabsCluster] = []
68
+ for entry in data:
69
+ page_items.append(LambdalabsCluster.from_dict(entry))
70
+
71
+ envelope = safe_json(response=response)
72
+ next_cursor = envelope.get("next_cursor", None)
73
+ return page_items, next_cursor
74
+
75
+ rtnval = collect_all_pages(fetch_page=_fetch_page)
76
+ return rtnval
77
+
78
+ def create(self, *, spec: LambdalabsClusterSpec,
79
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
80
+ ) -> LambdalabsCluster:
81
+ """
82
+ Create a 1-click cluster from a cluster spec.
83
+
84
+ :param spec: The :class:`LambdalabsClusterSpec` to create.
85
+ :param aspects: Behaviour control for the call.
86
+
87
+ :returns: A :class:`LambdalabsCluster` record.
88
+
89
+ :raises: :class:`SemanticError` when ``spec`` is ``None``.
90
+ """
91
+ if spec is None:
92
+ raise SemanticError("'spec' must be a LambdalabsClusterSpec.")
93
+
94
+ client = self.client
95
+ leaf = compose_leaf(parts=["1-click-clusters"])
96
+ response = client.request(method="POST", leaf=leaf,
97
+ json_body=spec.to_dict(), aspects=aspects)
98
+ raise_for_status(response=response, action="create cluster")
99
+
100
+ data = extract_data(response=response, action="create cluster")
101
+ rtnval = LambdalabsCluster.from_dict(data)
102
+ return rtnval
103
+
104
+ def get(self, *, cluster_id: str,
105
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
106
+ ) -> LambdalabsCluster:
107
+ """
108
+ Retrieve a single 1-click cluster by id.
109
+
110
+ :param cluster_id: The Lambda Labs cluster identifier.
111
+ :param aspects: Behaviour control for the call.
112
+
113
+ :returns: A :class:`LambdalabsCluster` record.
114
+ """
115
+ require_identifier(value=cluster_id, name="cluster_id")
116
+
117
+ client = self.client
118
+ leaf = compose_leaf(parts=["1-click-clusters", cluster_id])
119
+ response = client.request(method="GET", leaf=leaf, aspects=aspects)
120
+ raise_for_status(response=response, action="get cluster")
121
+
122
+ data = extract_data(response=response, action="get cluster")
123
+ rtnval = LambdalabsCluster.from_dict(data)
124
+ return rtnval
125
+
126
+ def delete(self, *, cluster_id: str,
127
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
128
+ ) -> None:
129
+ """
130
+ Delete a 1-click cluster by id. A 404 is treated as
131
+ already-removed so the delete is idempotent.
132
+
133
+ :param cluster_id: The Lambda Labs cluster identifier.
134
+ :param aspects: Behaviour control for the call.
135
+
136
+ :returns: ``None``.
137
+ """
138
+ require_identifier(value=cluster_id, name="cluster_id")
139
+
140
+ client = self.client
141
+ leaf = compose_leaf(parts=["1-click-clusters", cluster_id])
142
+ response = client.request(method="DELETE", leaf=leaf, aspects=aspects)
143
+
144
+ status = response.status_code
145
+ if 200 <= status < 300:
146
+ return
147
+ if status == 404:
148
+ return
149
+
150
+ raise_for_status(response=response, action="delete cluster")
151
+ return
@@ -0,0 +1,133 @@
1
+ """
2
+ .. module:: filesystemsgroup
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`FilesystemsGroup` api
5
+ group exposing the Lambda Labs file-systems 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.restclient.base.restapigroup import RestApiGroup
18
+
19
+ from ccai.restclient.lambdalabs.aspectslambdalabs import (
20
+ AspectsLambdalabs, DEFAULT_LAMBDALABS_ASPECTS
21
+ )
22
+ from ccai.restclient.lambdalabs.apigroups.groupsupport import (
23
+ compose_leaf, extract_data, raise_for_status, require_identifier,
24
+ safe_json
25
+ )
26
+ from ccai.restclient.lambdalabs.apigroups.pagingsupport import (
27
+ collect_all_pages
28
+ )
29
+ from ccai.restclient.lambdalabs.model.lambdalabsfilesystem import (
30
+ LambdalabsFilesystem
31
+ )
32
+
33
+
34
+ class FilesystemsGroup(RestApiGroup):
35
+ """
36
+ :class:`FilesystemsGroup` exposes the Lambda Labs file-systems
37
+ endpoints — list, create (read-before-create), and delete
38
+ (idempotent).
39
+ """
40
+
41
+ def list(self, *,
42
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
43
+ ) -> List[LambdalabsFilesystem]:
44
+ """
45
+ List every persistent file system, following paging cursors.
46
+
47
+ :param aspects: Behaviour control for the call.
48
+
49
+ :returns: A list of :class:`LambdalabsFilesystem` records.
50
+ """
51
+ client = self.client
52
+
53
+ def _fetch_page(cursor: Optional[str]) -> Tuple[List[LambdalabsFilesystem], Optional[str]]:
54
+ leaf = compose_leaf(parts=["file-systems"])
55
+ params = None
56
+ if cursor is not None:
57
+ params = {"cursor": cursor}
58
+ response = client.request(method="GET", leaf=leaf, params=params,
59
+ aspects=aspects)
60
+ raise_for_status(response=response, action="list file systems")
61
+
62
+ data = extract_data(response=response, action="list file systems")
63
+ page_items: List[LambdalabsFilesystem] = []
64
+ for entry in data:
65
+ page_items.append(LambdalabsFilesystem.from_dict(entry))
66
+
67
+ envelope = safe_json(response=response)
68
+ next_cursor = envelope.get("next_cursor", None)
69
+ return page_items, next_cursor
70
+
71
+ rtnval = collect_all_pages(fetch_page=_fetch_page)
72
+ return rtnval
73
+
74
+ def create(self, *, name: str, region: str,
75
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
76
+ ) -> LambdalabsFilesystem:
77
+ """
78
+ Create a persistent file system, reusing an existing file system
79
+ of the same name in the same region.
80
+
81
+ :param name: The file-system name.
82
+ :param region: The region to create the file system in.
83
+ :param aspects: Behaviour control for the call.
84
+
85
+ :returns: The created or pre-existing
86
+ :class:`LambdalabsFilesystem`.
87
+ """
88
+ require_identifier(value=name, name="name")
89
+ require_identifier(value=region, name="region")
90
+
91
+ existing = self.list(aspects=aspects)
92
+ for filesystem in existing:
93
+ if filesystem.name == name and filesystem.region == region:
94
+ rtnval = filesystem
95
+ return rtnval
96
+
97
+ client = self.client
98
+ leaf = compose_leaf(parts=["file-systems"])
99
+ body: Dict[str, Any] = {"name": name, "region": region}
100
+ response = client.request(method="POST", leaf=leaf, json_body=body,
101
+ aspects=aspects)
102
+ raise_for_status(response=response, action="create file system")
103
+
104
+ data = extract_data(response=response, action="create file system")
105
+ rtnval = LambdalabsFilesystem.from_dict(data)
106
+ return rtnval
107
+
108
+ def delete(self, *, filesystem_id: str,
109
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
110
+ ) -> None:
111
+ """
112
+ Delete a file system by id. A 404 is treated as already-removed
113
+ so the delete is idempotent.
114
+
115
+ :param filesystem_id: The Lambda Labs file-system identifier.
116
+ :param aspects: Behaviour control for the call.
117
+
118
+ :returns: ``None``.
119
+ """
120
+ require_identifier(value=filesystem_id, name="filesystem_id")
121
+
122
+ client = self.client
123
+ leaf = compose_leaf(parts=["file-systems", filesystem_id])
124
+ response = client.request(method="DELETE", leaf=leaf, aspects=aspects)
125
+
126
+ status = response.status_code
127
+ if 200 <= status < 300:
128
+ return
129
+ if status == 404:
130
+ return
131
+
132
+ raise_for_status(response=response, action="delete file system")
133
+ return
@@ -0,0 +1,216 @@
1
+ """
2
+ .. module:: groupsupport
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains shared helpers used by the Lambda
5
+ Labs api-group classes — URL composition, status checks,
6
+ and JSON-payload extraction.
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, Dict, List
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.lambdalabs.exceptions.lambdalabserrors import (
26
+ LambdalabsAuthenticationError, LambdalabsError,
27
+ LambdalabsQuotaExceededError
28
+ )
29
+
30
+
31
+ # Lambda Labs versioned API base path.
32
+ API_V1_BASE = "/api/v1"
33
+
34
+
35
+ def encode_segment(*, segment: str) -> str:
36
+ """
37
+ Percent-encode a single path segment.
38
+
39
+ The ``/`` character is treated as a reserved character and is
40
+ therefore encoded so a single identifier can never silently expand
41
+ the URL path.
42
+
43
+ :param segment: The raw path segment.
44
+
45
+ :returns: The percent-encoded segment.
46
+
47
+ :raises: :class:`SemanticError` when the segment is ``None`` or
48
+ empty.
49
+ """
50
+ if segment is None:
51
+ raise SemanticError("URL path segment must be a non-empty string.")
52
+ if len(segment) == 0:
53
+ raise SemanticError("URL path segment must be a non-empty string.")
54
+
55
+ rtnval = quote(segment, safe="")
56
+ return rtnval
57
+
58
+
59
+ def compose_leaf(*, parts: List[str]) -> str:
60
+ """
61
+ Compose an API leaf path from the versioned base and per-segment
62
+ percent-encoded parts.
63
+
64
+ :param parts: The ordered path segments after the versioned base.
65
+
66
+ :returns: The composed leaf path beginning with ``/``.
67
+
68
+ :raises: :class:`SemanticError` when ``parts`` is ``None`` or empty,
69
+ or when any segment is empty.
70
+ """
71
+ if parts is None:
72
+ raise SemanticError("compose_leaf requires a non-None parts list.")
73
+ if len(parts) == 0:
74
+ raise SemanticError("compose_leaf requires at least one part.")
75
+
76
+ encoded: List[str] = []
77
+ for part in parts:
78
+ encoded.append(encode_segment(segment=part))
79
+
80
+ rtnval = API_V1_BASE + "/" + "/".join(encoded)
81
+ return rtnval
82
+
83
+
84
+ def require_identifier(*, value: str, name: str) -> None:
85
+ """
86
+ Validate that an identifier argument is a non-empty string.
87
+
88
+ :param value: The identifier value.
89
+ :param name: The argument name, used in the error message.
90
+
91
+ :returns: ``None``.
92
+
93
+ :raises: :class:`SemanticError` when the identifier is ``None`` or
94
+ empty.
95
+ """
96
+ if value is None:
97
+ raise SemanticError("'{}' must be a non-empty string.".format(name))
98
+ if len(value) == 0:
99
+ raise SemanticError("'{}' must be a non-empty string.".format(name))
100
+ return
101
+
102
+
103
+ def raise_for_status(*, response: Response, action: str) -> None:
104
+ """
105
+ Raise a descriptive Lambda Labs error for a non-2xx response.
106
+
107
+ HTTP 401/403 reclassifies into :class:`LambdalabsAuthenticationError`.
108
+ HTTP 400/403 carrying a quota/capacity error code reclassifies into
109
+ :class:`LambdalabsQuotaExceededError`. Every other non-2xx status
110
+ reclassifies into :class:`LambdalabsError`.
111
+
112
+ :param response: The :class:`Response` to inspect.
113
+ :param action: A short description of the attempted action.
114
+
115
+ :returns: ``None``.
116
+
117
+ :raises: :class:`LambdalabsAuthenticationError`,
118
+ :class:`LambdalabsQuotaExceededError`, :class:`LambdalabsError`.
119
+ """
120
+ status = response.status_code
121
+ if 200 <= status < 300:
122
+ return
123
+
124
+ error_code = _error_code_of(response=response)
125
+
126
+ err_msg_lines = ["Lambda Labs API call failed: {}.".format(action)]
127
+ err_msg_lines.append("STATUS: {}".format(status))
128
+ if error_code is not None:
129
+ err_msg_lines.append("ERROR CODE: {}".format(error_code))
130
+ err_msg_lines.append("RESPONSE:")
131
+ err_msg_lines.append(response.text)
132
+ err_msg = os.linesep.join(err_msg_lines)
133
+
134
+ if status in (401, 403) and error_code != "global/quota-exceeded":
135
+ raise LambdalabsAuthenticationError(err_msg)
136
+
137
+ quota_codes = frozenset({
138
+ "global/quota-exceeded", "instance-operations/launch/insufficient-capacity",
139
+ "global/account-inactive",
140
+ })
141
+ if error_code in quota_codes:
142
+ raise LambdalabsQuotaExceededError(err_msg)
143
+
144
+ raise LambdalabsError(err_msg)
145
+
146
+
147
+ def _error_code_of(*, response: Response) -> Any:
148
+ """
149
+ Extract the Lambda Labs ``error.code`` field from a response body.
150
+
151
+ :param response: The :class:`Response` to inspect.
152
+
153
+ :returns: The error code string, or ``None`` when absent.
154
+ """
155
+ payload = safe_json(response=response)
156
+ error_block = payload.get("error", None)
157
+ if error_block is None:
158
+ rtnval = None
159
+ return rtnval
160
+ if not isinstance(error_block, dict):
161
+ rtnval = None
162
+ return rtnval
163
+ rtnval = error_block.get("code", None)
164
+ return rtnval
165
+
166
+
167
+ def safe_json(*, response: Response) -> Dict[str, Any]:
168
+ """
169
+ Parse a response body as a JSON object, degrading to an empty dict.
170
+
171
+ :param response: The :class:`Response` to parse.
172
+
173
+ :returns: The decoded object, or an empty dict.
174
+ """
175
+ try:
176
+ payload = response.json()
177
+ except ValueError:
178
+ rtnval: Dict[str, Any] = {}
179
+ return rtnval
180
+
181
+ if not isinstance(payload, dict):
182
+ rtnval = {}
183
+ return rtnval
184
+
185
+ rtnval = payload
186
+ return rtnval
187
+
188
+
189
+ def extract_data(*, response: Response, action: str) -> Any:
190
+ """
191
+ Extract the ``data`` envelope from a Lambda Labs API response.
192
+
193
+ Lambda Labs wraps every successful response in a ``{"data": ...}``
194
+ envelope.
195
+
196
+ :param response: The :class:`Response` to parse.
197
+ :param action: A short description of the attempted action.
198
+
199
+ :returns: The contents of the ``data`` key.
200
+
201
+ :raises: :class:`LambdalabsError` when the envelope is missing.
202
+ """
203
+ payload = safe_json(response=response)
204
+ if "data" not in payload:
205
+ err_msg_lines = [
206
+ "Lambda Labs API response missing 'data' envelope: {}.".format(
207
+ action
208
+ )
209
+ ]
210
+ err_msg_lines.append("RESPONSE:")
211
+ err_msg_lines.append(response.text)
212
+ err_msg = os.linesep.join(err_msg_lines)
213
+ raise LambdalabsError(err_msg)
214
+
215
+ rtnval = payload["data"]
216
+ return rtnval
@@ -0,0 +1,69 @@
1
+ """
2
+ .. module:: imagesgroup
3
+ :platform: Darwin, Linux, Unix, Windows
4
+ :synopsis: Module that contains the :class:`ImagesGroup` api group
5
+ exposing the Lambda Labs images endpoint.
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 List, Optional, Tuple
16
+
17
+ from ccai.restclient.base.restapigroup import RestApiGroup
18
+
19
+ from ccai.restclient.lambdalabs.aspectslambdalabs import (
20
+ AspectsLambdalabs, DEFAULT_LAMBDALABS_ASPECTS
21
+ )
22
+ from ccai.restclient.lambdalabs.apigroups.groupsupport import (
23
+ compose_leaf, extract_data, raise_for_status, safe_json
24
+ )
25
+ from ccai.restclient.lambdalabs.apigroups.pagingsupport import (
26
+ collect_all_pages
27
+ )
28
+ from ccai.restclient.lambdalabs.model.lambdalabsimage import LambdalabsImage
29
+
30
+
31
+ class ImagesGroup(RestApiGroup):
32
+ """
33
+ :class:`ImagesGroup` exposes the Lambda Labs
34
+ ``GET /api/v1/images`` endpoint, which enumerates the supported
35
+ operating-system images.
36
+ """
37
+
38
+ def list(self, *,
39
+ aspects: AspectsLambdalabs = DEFAULT_LAMBDALABS_ASPECTS
40
+ ) -> List[LambdalabsImage]:
41
+ """
42
+ List every supported Lambda Labs operating-system image.
43
+
44
+ :param aspects: Behaviour control for the call.
45
+
46
+ :returns: A list of :class:`LambdalabsImage` records.
47
+ """
48
+ client = self.client
49
+
50
+ def _fetch_page(cursor: Optional[str]) -> Tuple[List[LambdalabsImage], Optional[str]]:
51
+ leaf = compose_leaf(parts=["images"])
52
+ params = None
53
+ if cursor is not None:
54
+ params = {"cursor": cursor}
55
+ response = client.request(method="GET", leaf=leaf, params=params,
56
+ aspects=aspects)
57
+ raise_for_status(response=response, action="list images")
58
+
59
+ data = extract_data(response=response, action="list images")
60
+ page_items: List[LambdalabsImage] = []
61
+ for entry in data:
62
+ page_items.append(LambdalabsImage.from_dict(entry))
63
+
64
+ envelope = safe_json(response=response)
65
+ next_cursor = envelope.get("next_cursor", None)
66
+ return page_items, next_cursor
67
+
68
+ rtnval = collect_all_pages(fetch_page=_fetch_page)
69
+ return rtnval