codecraftai-restclient-nebius 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.
- ccai/restclient/nebius/__init__.py +0 -0
- ccai/restclient/nebius/apigroups/__init__.py +0 -0
- ccai/restclient/nebius/apigroups/disksgroup.py +250 -0
- ccai/restclient/nebius/apigroups/filesystemsgroup.py +199 -0
- ccai/restclient/nebius/apigroups/groupsupport.py +145 -0
- ccai/restclient/nebius/apigroups/imagesgroup.py +65 -0
- ccai/restclient/nebius/apigroups/mounttargetsgroup.py +144 -0
- ccai/restclient/nebius/apigroups/operationsgroup.py +129 -0
- ccai/restclient/nebius/apigroups/placementgroupsgroup.py +169 -0
- ccai/restclient/nebius/apigroups/projectsgroup.py +65 -0
- ccai/restclient/nebius/apigroups/regionsgroup.py +64 -0
- ccai/restclient/nebius/apigroups/securitygroupsgroup.py +202 -0
- ccai/restclient/nebius/apigroups/sshkeysgroup.py +143 -0
- ccai/restclient/nebius/apigroups/subnetsgroup.py +228 -0
- ccai/restclient/nebius/apigroups/tagsgroup.py +121 -0
- ccai/restclient/nebius/apigroups/vmsgroup.py +324 -0
- ccai/restclient/nebius/apigroups/vpcsgroup.py +157 -0
- ccai/restclient/nebius/aspectsnebius.py +110 -0
- ccai/restclient/nebius/exceptions/__init__.py +0 -0
- ccai/restclient/nebius/exceptions/nebiusexceptions.py +34 -0
- ccai/restclient/nebius/model/__init__.py +0 -0
- ccai/restclient/nebius/model/nebiusdisk.py +35 -0
- ccai/restclient/nebius/model/nebiusfilesystem.py +33 -0
- ccai/restclient/nebius/model/nebiusimage.py +33 -0
- ccai/restclient/nebius/model/nebiusmounttarget.py +32 -0
- ccai/restclient/nebius/model/nebiusoperationresult.py +33 -0
- ccai/restclient/nebius/model/nebiusplacementgroup.py +33 -0
- ccai/restclient/nebius/model/nebiusproject.py +32 -0
- ccai/restclient/nebius/model/nebiusregion.py +30 -0
- ccai/restclient/nebius/model/nebiussecuritygroup.py +33 -0
- ccai/restclient/nebius/model/nebiussshkey.py +31 -0
- ccai/restclient/nebius/model/nebiussubnet.py +34 -0
- ccai/restclient/nebius/model/nebiustaskhandle.py +164 -0
- ccai/restclient/nebius/model/nebiusvm.py +37 -0
- ccai/restclient/nebius/model/nebiusvpc.py +33 -0
- ccai/restclient/nebius/nebiusclient.py +527 -0
- ccai/restclient/nebius/nebiusurl.py +61 -0
- ccai/restclient/nebius/py.typed +0 -0
- ccai/restclient/nebius/specs/__init__.py +0 -0
- ccai/restclient/nebius/specs/nebiusdiskspec.py +29 -0
- ccai/restclient/nebius/specs/nebiusfilesystemspec.py +28 -0
- ccai/restclient/nebius/specs/nebiusmounttargetspec.py +27 -0
- ccai/restclient/nebius/specs/nebiusplacementgroupspec.py +28 -0
- ccai/restclient/nebius/specs/nebiussecuritygroupspec.py +29 -0
- ccai/restclient/nebius/specs/nebiussubnetspec.py +29 -0
- ccai/restclient/nebius/specs/nebiusvmspec.py +35 -0
- ccai/restclient/nebius/specs/nebiusvpcspec.py +28 -0
- codecraftai_restclient_nebius-1.2.0.dist-info/METADATA +86 -0
- codecraftai_restclient_nebius-1.2.0.dist-info/RECORD +51 -0
- codecraftai_restclient_nebius-1.2.0.dist-info/WHEEL +4 -0
- codecraftai_restclient_nebius-1.2.0.dist-info/licenses/LICENSE.md +204 -0
|
File without changes
|
|
File without changes
|
|
@@ -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 Nebius disk lifecycle 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.nebius.aspectsnebius import (
|
|
22
|
+
AspectsNebius, DEFAULT_NEBIUS_ASPECTS
|
|
23
|
+
)
|
|
24
|
+
from ccai.restclient.nebius.nebiusurl import compose_leaf
|
|
25
|
+
from ccai.restclient.nebius.apigroups.groupsupport import (
|
|
26
|
+
collect_pages, is_not_found, raise_for_status
|
|
27
|
+
)
|
|
28
|
+
from ccai.restclient.nebius.model.nebiusdisk import NebiusDisk
|
|
29
|
+
from ccai.restclient.nebius.model.nebiustaskhandle import NebiusTaskHandle
|
|
30
|
+
from ccai.restclient.nebius.specs.nebiusdiskspec import NebiusDiskSpec
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _operation_id_of(*, payload: Dict[str, Any]) -> str:
|
|
34
|
+
"""
|
|
35
|
+
Extract the operation id from an async-call response payload.
|
|
36
|
+
|
|
37
|
+
Nebius async calls return an operation envelope carrying an
|
|
38
|
+
``operation_id`` (or ``id``); a synchronous resource payload
|
|
39
|
+
carries its own ``id``.
|
|
40
|
+
|
|
41
|
+
:param payload: The response JSON payload.
|
|
42
|
+
|
|
43
|
+
:returns: The operation identifier string.
|
|
44
|
+
|
|
45
|
+
:raises: :class:`SemanticError` when no operation id is present.
|
|
46
|
+
"""
|
|
47
|
+
op_id = payload.get("operation_id", None)
|
|
48
|
+
if op_id is None:
|
|
49
|
+
operation = payload.get("operation", None)
|
|
50
|
+
if isinstance(operation, dict):
|
|
51
|
+
op_id = operation.get("id", None)
|
|
52
|
+
if op_id is None:
|
|
53
|
+
op_id = payload.get("id", None)
|
|
54
|
+
if op_id is None or len(str(op_id)) == 0:
|
|
55
|
+
raise SemanticError(
|
|
56
|
+
"Nebius async response did not carry an operation id."
|
|
57
|
+
)
|
|
58
|
+
rtnval = str(op_id)
|
|
59
|
+
return rtnval
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class DisksGroup(RestApiGroup):
|
|
63
|
+
"""
|
|
64
|
+
:class:`DisksGroup` exposes the Nebius block-storage disk lifecycle.
|
|
65
|
+
Create / attach / detach are async — each returns a
|
|
66
|
+
:class:`NebiusTaskHandle` alongside the typed model. Delete is a
|
|
67
|
+
no-op on an unknown id.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
BASE_LEAF = "/v1"
|
|
71
|
+
|
|
72
|
+
def list(self, *, project_id: str,
|
|
73
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
74
|
+
) -> List[NebiusDisk]:
|
|
75
|
+
"""
|
|
76
|
+
List every disk anchored to a project.
|
|
77
|
+
|
|
78
|
+
:param project_id: The Nebius project identifier.
|
|
79
|
+
:param aspects: Behaviour control for the call.
|
|
80
|
+
|
|
81
|
+
:returns: A list of :class:`NebiusDisk` models.
|
|
82
|
+
|
|
83
|
+
:raises: :class:`SemanticError` when ``project_id`` is empty.
|
|
84
|
+
"""
|
|
85
|
+
if project_id is None or len(project_id) == 0:
|
|
86
|
+
raise SemanticError("'project_id' must be a non-empty string.")
|
|
87
|
+
|
|
88
|
+
client = self.client
|
|
89
|
+
leaf = "/v1/disks"
|
|
90
|
+
|
|
91
|
+
def _fetch(cursor: Optional[str]) -> Dict[str, Any]:
|
|
92
|
+
params: Dict[str, str] = {
|
|
93
|
+
"parent_id": project_id,
|
|
94
|
+
"page_size": str(aspects.page_size),
|
|
95
|
+
}
|
|
96
|
+
if cursor is not None:
|
|
97
|
+
params["page_token"] = cursor
|
|
98
|
+
response = client.request(method="GET", leaf=leaf,
|
|
99
|
+
params=params, aspects=aspects)
|
|
100
|
+
raise_for_status(response=response, action="list disks")
|
|
101
|
+
rtnval = response.json()
|
|
102
|
+
return rtnval
|
|
103
|
+
|
|
104
|
+
raw_items = collect_pages(fetch_page=_fetch)
|
|
105
|
+
out: List[NebiusDisk] = []
|
|
106
|
+
for entry in raw_items:
|
|
107
|
+
out.append(NebiusDisk.from_dict(entry))
|
|
108
|
+
rtnval = out
|
|
109
|
+
return rtnval
|
|
110
|
+
|
|
111
|
+
def find_by_name(self, *, project_id: str, name: str,
|
|
112
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
113
|
+
) -> Optional[NebiusDisk]:
|
|
114
|
+
"""
|
|
115
|
+
Find a disk by name within a project.
|
|
116
|
+
|
|
117
|
+
:param project_id: The Nebius project identifier.
|
|
118
|
+
:param name: The disk name to match.
|
|
119
|
+
:param aspects: Behaviour control for the call.
|
|
120
|
+
|
|
121
|
+
:returns: The matching :class:`NebiusDisk`, or ``None``.
|
|
122
|
+
"""
|
|
123
|
+
existing = self.list(project_id=project_id, aspects=aspects)
|
|
124
|
+
rtnval: Optional[NebiusDisk] = None
|
|
125
|
+
for disk in existing:
|
|
126
|
+
if disk.name == name:
|
|
127
|
+
rtnval = disk
|
|
128
|
+
break
|
|
129
|
+
return rtnval
|
|
130
|
+
|
|
131
|
+
def create(self, *, spec: NebiusDiskSpec,
|
|
132
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
133
|
+
) -> Tuple[NebiusDisk, NebiusTaskHandle]:
|
|
134
|
+
"""
|
|
135
|
+
Create a disk.
|
|
136
|
+
|
|
137
|
+
:param spec: The :class:`NebiusDiskSpec` request payload.
|
|
138
|
+
:param aspects: Behaviour control for the call.
|
|
139
|
+
|
|
140
|
+
:returns: A tuple of the :class:`NebiusDisk` record and the
|
|
141
|
+
:class:`NebiusTaskHandle` tracking creation.
|
|
142
|
+
"""
|
|
143
|
+
client = self.client
|
|
144
|
+
body: Dict[str, Any] = {
|
|
145
|
+
"parent_id": spec.parent_id,
|
|
146
|
+
"name": spec.name,
|
|
147
|
+
"size_bytes": spec.size_bytes,
|
|
148
|
+
"type": spec.type,
|
|
149
|
+
}
|
|
150
|
+
if spec.labels is not None:
|
|
151
|
+
body["labels"] = spec.labels
|
|
152
|
+
|
|
153
|
+
response = client.request(method="POST", leaf="/v1/disks",
|
|
154
|
+
json_body=body, aspects=aspects)
|
|
155
|
+
raise_for_status(response=response, action="create disk")
|
|
156
|
+
payload = response.json()
|
|
157
|
+
|
|
158
|
+
disk = NebiusDisk.from_dict(payload.get("resource", payload))
|
|
159
|
+
handle = NebiusTaskHandle(operation_id=_operation_id_of(payload=payload),
|
|
160
|
+
client=client)
|
|
161
|
+
rtnval = (disk, handle)
|
|
162
|
+
return rtnval
|
|
163
|
+
|
|
164
|
+
def attach(self, *, disk_id: str, instance_id: str,
|
|
165
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
166
|
+
) -> NebiusTaskHandle:
|
|
167
|
+
"""
|
|
168
|
+
Attach a disk to an instance.
|
|
169
|
+
|
|
170
|
+
:param disk_id: The Nebius disk identifier.
|
|
171
|
+
:param instance_id: The Nebius VM identifier.
|
|
172
|
+
:param aspects: Behaviour control for the call.
|
|
173
|
+
|
|
174
|
+
:returns: A :class:`NebiusTaskHandle` tracking the attach.
|
|
175
|
+
|
|
176
|
+
:raises: :class:`SemanticError` when an identifier is empty.
|
|
177
|
+
"""
|
|
178
|
+
if disk_id is None or len(disk_id) == 0:
|
|
179
|
+
raise SemanticError("'disk_id' must be a non-empty string.")
|
|
180
|
+
if instance_id is None or len(instance_id) == 0:
|
|
181
|
+
raise SemanticError("'instance_id' must be a non-empty string.")
|
|
182
|
+
|
|
183
|
+
client = self.client
|
|
184
|
+
leaf = compose_leaf(parts=["v1", "disks", disk_id, "attach"])
|
|
185
|
+
body: Dict[str, Any] = {"instance_id": instance_id}
|
|
186
|
+
response = client.request(method="POST", leaf=leaf, json_body=body,
|
|
187
|
+
aspects=aspects)
|
|
188
|
+
raise_for_status(response=response, action="attach disk")
|
|
189
|
+
handle = NebiusTaskHandle(
|
|
190
|
+
operation_id=_operation_id_of(payload=response.json()),
|
|
191
|
+
client=client,
|
|
192
|
+
)
|
|
193
|
+
rtnval = handle
|
|
194
|
+
return rtnval
|
|
195
|
+
|
|
196
|
+
def detach(self, *, disk_id: str, instance_id: str,
|
|
197
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
198
|
+
) -> NebiusTaskHandle:
|
|
199
|
+
"""
|
|
200
|
+
Detach a disk from an instance.
|
|
201
|
+
|
|
202
|
+
:param disk_id: The Nebius disk identifier.
|
|
203
|
+
:param instance_id: The Nebius VM identifier.
|
|
204
|
+
:param aspects: Behaviour control for the call.
|
|
205
|
+
|
|
206
|
+
:returns: A :class:`NebiusTaskHandle` tracking the detach.
|
|
207
|
+
|
|
208
|
+
:raises: :class:`SemanticError` when an identifier is empty.
|
|
209
|
+
"""
|
|
210
|
+
if disk_id is None or len(disk_id) == 0:
|
|
211
|
+
raise SemanticError("'disk_id' must be a non-empty string.")
|
|
212
|
+
if instance_id is None or len(instance_id) == 0:
|
|
213
|
+
raise SemanticError("'instance_id' must be a non-empty string.")
|
|
214
|
+
|
|
215
|
+
client = self.client
|
|
216
|
+
leaf = compose_leaf(parts=["v1", "disks", disk_id, "detach"])
|
|
217
|
+
body: Dict[str, Any] = {"instance_id": instance_id}
|
|
218
|
+
response = client.request(method="POST", leaf=leaf, json_body=body,
|
|
219
|
+
aspects=aspects)
|
|
220
|
+
raise_for_status(response=response, action="detach disk")
|
|
221
|
+
handle = NebiusTaskHandle(
|
|
222
|
+
operation_id=_operation_id_of(payload=response.json()),
|
|
223
|
+
client=client,
|
|
224
|
+
)
|
|
225
|
+
rtnval = handle
|
|
226
|
+
return rtnval
|
|
227
|
+
|
|
228
|
+
def delete(self, *, disk_id: str,
|
|
229
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS) -> None:
|
|
230
|
+
"""
|
|
231
|
+
Delete a disk. A 404 is treated as already-removed.
|
|
232
|
+
|
|
233
|
+
:param disk_id: The Nebius disk identifier.
|
|
234
|
+
:param aspects: Behaviour control for the call.
|
|
235
|
+
|
|
236
|
+
:returns: ``None``.
|
|
237
|
+
|
|
238
|
+
:raises: :class:`SemanticError` when ``disk_id`` is empty.
|
|
239
|
+
"""
|
|
240
|
+
if disk_id is None or len(disk_id) == 0:
|
|
241
|
+
raise SemanticError("'disk_id' must be a non-empty string.")
|
|
242
|
+
|
|
243
|
+
client = self.client
|
|
244
|
+
leaf = compose_leaf(parts=["v1", "disks", disk_id])
|
|
245
|
+
response = client.request(method="DELETE", leaf=leaf, aspects=aspects)
|
|
246
|
+
|
|
247
|
+
if is_not_found(response=response):
|
|
248
|
+
return
|
|
249
|
+
raise_for_status(response=response, action="delete disk")
|
|
250
|
+
return
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: filesystemsgroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`FilesystemsGroup` api
|
|
5
|
+
group exposing the Nebius native shared-filesystem
|
|
6
|
+
endpoints.
|
|
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
|
+
from typing import Any, Dict, List, Optional, Tuple
|
|
17
|
+
|
|
18
|
+
from ccai.errors.exceptions import SemanticError
|
|
19
|
+
|
|
20
|
+
from ccai.restclient.base.restapigroup import RestApiGroup
|
|
21
|
+
|
|
22
|
+
from ccai.restclient.nebius.aspectsnebius import (
|
|
23
|
+
AspectsNebius, DEFAULT_NEBIUS_ASPECTS
|
|
24
|
+
)
|
|
25
|
+
from ccai.restclient.nebius.nebiusurl import compose_leaf
|
|
26
|
+
from ccai.restclient.nebius.apigroups.disksgroup import _operation_id_of
|
|
27
|
+
from ccai.restclient.nebius.apigroups.groupsupport import (
|
|
28
|
+
collect_pages, is_not_found, raise_for_status
|
|
29
|
+
)
|
|
30
|
+
from ccai.restclient.nebius.model.nebiusfilesystem import NebiusFilesystem
|
|
31
|
+
from ccai.restclient.nebius.model.nebiustaskhandle import NebiusTaskHandle
|
|
32
|
+
from ccai.restclient.nebius.specs.nebiusfilesystemspec import (
|
|
33
|
+
NebiusFilesystemSpec
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class FilesystemsGroup(RestApiGroup):
|
|
38
|
+
"""
|
|
39
|
+
:class:`FilesystemsGroup` exposes the Nebius native shared-filesystem
|
|
40
|
+
lifecycle — create (idempotent by name, async), list, and delete
|
|
41
|
+
(no-op on an unknown id).
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
BASE_LEAF = "/v1"
|
|
45
|
+
|
|
46
|
+
def list(self, *, project_id: str,
|
|
47
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
48
|
+
) -> List[NebiusFilesystem]:
|
|
49
|
+
"""
|
|
50
|
+
List every shared filesystem anchored to a project.
|
|
51
|
+
|
|
52
|
+
:param project_id: The Nebius project identifier.
|
|
53
|
+
:param aspects: Behaviour control for the call.
|
|
54
|
+
|
|
55
|
+
:returns: A list of :class:`NebiusFilesystem` models.
|
|
56
|
+
|
|
57
|
+
:raises: :class:`SemanticError` when ``project_id`` is empty.
|
|
58
|
+
"""
|
|
59
|
+
if project_id is None or len(project_id) == 0:
|
|
60
|
+
raise SemanticError("'project_id' must be a non-empty string.")
|
|
61
|
+
|
|
62
|
+
client = self.client
|
|
63
|
+
leaf = "/v1/file-storages"
|
|
64
|
+
|
|
65
|
+
def _fetch(cursor: Optional[str]) -> Dict[str, Any]:
|
|
66
|
+
params: Dict[str, str] = {
|
|
67
|
+
"parent_id": project_id,
|
|
68
|
+
"page_size": str(aspects.page_size),
|
|
69
|
+
}
|
|
70
|
+
if cursor is not None:
|
|
71
|
+
params["page_token"] = cursor
|
|
72
|
+
response = client.request(method="GET", leaf=leaf,
|
|
73
|
+
params=params, aspects=aspects)
|
|
74
|
+
raise_for_status(response=response, action="list filesystems")
|
|
75
|
+
rtnval = response.json()
|
|
76
|
+
return rtnval
|
|
77
|
+
|
|
78
|
+
raw_items = collect_pages(fetch_page=_fetch)
|
|
79
|
+
out: List[NebiusFilesystem] = []
|
|
80
|
+
for entry in raw_items:
|
|
81
|
+
out.append(NebiusFilesystem.from_dict(entry))
|
|
82
|
+
rtnval = out
|
|
83
|
+
return rtnval
|
|
84
|
+
|
|
85
|
+
def find_by_name(self, *, project_id: str, name: str,
|
|
86
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
87
|
+
) -> Optional[NebiusFilesystem]:
|
|
88
|
+
"""
|
|
89
|
+
Find a shared filesystem by name within a project.
|
|
90
|
+
|
|
91
|
+
:param project_id: The Nebius project identifier.
|
|
92
|
+
:param name: The filesystem name to match.
|
|
93
|
+
:param aspects: Behaviour control for the call.
|
|
94
|
+
|
|
95
|
+
:returns: The matching :class:`NebiusFilesystem`, or ``None``.
|
|
96
|
+
"""
|
|
97
|
+
existing = self.list(project_id=project_id, aspects=aspects)
|
|
98
|
+
rtnval: Optional[NebiusFilesystem] = None
|
|
99
|
+
for fs in existing:
|
|
100
|
+
if fs.name == name:
|
|
101
|
+
rtnval = fs
|
|
102
|
+
break
|
|
103
|
+
return rtnval
|
|
104
|
+
|
|
105
|
+
def get(self, *, filesystem_id: str,
|
|
106
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
107
|
+
) -> NebiusFilesystem:
|
|
108
|
+
"""
|
|
109
|
+
Retrieve a single shared filesystem by identifier.
|
|
110
|
+
|
|
111
|
+
:param filesystem_id: The Nebius filesystem identifier.
|
|
112
|
+
:param aspects: Behaviour control for the call.
|
|
113
|
+
|
|
114
|
+
:returns: A :class:`NebiusFilesystem` model.
|
|
115
|
+
|
|
116
|
+
:raises: :class:`SemanticError` when the identifier is empty.
|
|
117
|
+
"""
|
|
118
|
+
if filesystem_id is None or len(filesystem_id) == 0:
|
|
119
|
+
raise SemanticError(
|
|
120
|
+
"'filesystem_id' must be a non-empty string."
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
client = self.client
|
|
124
|
+
leaf = compose_leaf(parts=["v1", "file-storages", filesystem_id])
|
|
125
|
+
response = client.request(method="GET", leaf=leaf, aspects=aspects)
|
|
126
|
+
raise_for_status(response=response, action="get filesystem")
|
|
127
|
+
rtnval = NebiusFilesystem.from_dict(response.json())
|
|
128
|
+
return rtnval
|
|
129
|
+
|
|
130
|
+
def create(self, *, spec: NebiusFilesystemSpec,
|
|
131
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
132
|
+
) -> Tuple[NebiusFilesystem, NebiusTaskHandle]:
|
|
133
|
+
"""
|
|
134
|
+
Create a shared filesystem idempotently.
|
|
135
|
+
|
|
136
|
+
An existing filesystem of the same name in the same project is
|
|
137
|
+
returned with a task handle that is already complete-pollable.
|
|
138
|
+
|
|
139
|
+
:param spec: The :class:`NebiusFilesystemSpec` payload.
|
|
140
|
+
:param aspects: Behaviour control for the call.
|
|
141
|
+
|
|
142
|
+
:returns: A tuple of the :class:`NebiusFilesystem` record and
|
|
143
|
+
a :class:`NebiusTaskHandle`.
|
|
144
|
+
"""
|
|
145
|
+
existing = self.find_by_name(project_id=spec.parent_id,
|
|
146
|
+
name=spec.name, aspects=aspects)
|
|
147
|
+
client = self.client
|
|
148
|
+
if existing is not None:
|
|
149
|
+
handle = NebiusTaskHandle(operation_id=existing.id,
|
|
150
|
+
client=client)
|
|
151
|
+
rtnval = (existing, handle)
|
|
152
|
+
return rtnval
|
|
153
|
+
|
|
154
|
+
body: Dict[str, Any] = {
|
|
155
|
+
"parent_id": spec.parent_id,
|
|
156
|
+
"name": spec.name,
|
|
157
|
+
"size_bytes": spec.size_bytes,
|
|
158
|
+
}
|
|
159
|
+
if spec.labels is not None:
|
|
160
|
+
body["labels"] = spec.labels
|
|
161
|
+
|
|
162
|
+
response = client.request(method="POST", leaf="/v1/file-storages",
|
|
163
|
+
json_body=body, aspects=aspects)
|
|
164
|
+
raise_for_status(response=response, action="create filesystem")
|
|
165
|
+
payload = response.json()
|
|
166
|
+
|
|
167
|
+
fs = NebiusFilesystem.from_dict(payload.get("resource", payload))
|
|
168
|
+
handle = NebiusTaskHandle(
|
|
169
|
+
operation_id=_operation_id_of(payload=payload), client=client,
|
|
170
|
+
)
|
|
171
|
+
rtnval = (fs, handle)
|
|
172
|
+
return rtnval
|
|
173
|
+
|
|
174
|
+
def delete(self, *, filesystem_id: str,
|
|
175
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS) -> None:
|
|
176
|
+
"""
|
|
177
|
+
Delete a shared filesystem. A 404 is treated as
|
|
178
|
+
already-removed.
|
|
179
|
+
|
|
180
|
+
:param filesystem_id: The Nebius filesystem identifier.
|
|
181
|
+
:param aspects: Behaviour control for the call.
|
|
182
|
+
|
|
183
|
+
:returns: ``None``.
|
|
184
|
+
|
|
185
|
+
:raises: :class:`SemanticError` when the identifier is empty.
|
|
186
|
+
"""
|
|
187
|
+
if filesystem_id is None or len(filesystem_id) == 0:
|
|
188
|
+
raise SemanticError(
|
|
189
|
+
"'filesystem_id' must be a non-empty string."
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
client = self.client
|
|
193
|
+
leaf = compose_leaf(parts=["v1", "file-storages", filesystem_id])
|
|
194
|
+
response = client.request(method="DELETE", leaf=leaf, aspects=aspects)
|
|
195
|
+
|
|
196
|
+
if is_not_found(response=response):
|
|
197
|
+
return
|
|
198
|
+
raise_for_status(response=response, action="delete filesystem")
|
|
199
|
+
return
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: groupsupport
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains shared helpers for the Nebius api
|
|
5
|
+
groups — HTTP status reclassification and cursor paging.
|
|
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
|
+
import os
|
|
16
|
+
|
|
17
|
+
from typing import Any, Callable, Dict, Iterator, List, Optional
|
|
18
|
+
|
|
19
|
+
from requests import Response
|
|
20
|
+
|
|
21
|
+
from ccai.errors.exceptions import SemanticError
|
|
22
|
+
|
|
23
|
+
from ccai.restclient.nebius.exceptions.nebiusexceptions import (
|
|
24
|
+
NebiusAuthenticationError
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def raise_for_status(*, response: Response, action: str) -> None:
|
|
29
|
+
"""
|
|
30
|
+
Reclassify a non-success Nebius HTTP response into a typed error.
|
|
31
|
+
|
|
32
|
+
A 2xx is a no-op. 401/403 reclassify into
|
|
33
|
+
:class:`NebiusAuthenticationError`. Any other non-2xx code raises
|
|
34
|
+
a :class:`SemanticError` with the response body for context.
|
|
35
|
+
|
|
36
|
+
:param response: The :class:`Response` to inspect.
|
|
37
|
+
:param action: Short description of the attempted action, used in
|
|
38
|
+
the error message.
|
|
39
|
+
|
|
40
|
+
:returns: ``None``.
|
|
41
|
+
|
|
42
|
+
:raises: :class:`NebiusAuthenticationError`, :class:`SemanticError`.
|
|
43
|
+
"""
|
|
44
|
+
status = response.status_code
|
|
45
|
+
if 200 <= status < 300:
|
|
46
|
+
return
|
|
47
|
+
|
|
48
|
+
if status in (401, 403):
|
|
49
|
+
err_msg_lines = ["Nebius rejected an authenticated request."]
|
|
50
|
+
err_msg_lines.append("ACTION: {}".format(action))
|
|
51
|
+
err_msg_lines.append("STATUS: {}".format(status))
|
|
52
|
+
err_msg_lines.append("RESPONSE:")
|
|
53
|
+
err_msg_lines.append(response.text)
|
|
54
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
55
|
+
raise NebiusAuthenticationError(err_msg)
|
|
56
|
+
|
|
57
|
+
err_msg_lines = ["Nebius API call failed."]
|
|
58
|
+
err_msg_lines.append("ACTION: {}".format(action))
|
|
59
|
+
err_msg_lines.append("STATUS: {}".format(status))
|
|
60
|
+
err_msg_lines.append("RESPONSE:")
|
|
61
|
+
err_msg_lines.append(response.text)
|
|
62
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
63
|
+
raise SemanticError(err_msg)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def is_not_found(*, response: Response) -> bool:
|
|
67
|
+
"""
|
|
68
|
+
Return whether a response indicates a missing resource.
|
|
69
|
+
|
|
70
|
+
:param response: The :class:`Response` to inspect.
|
|
71
|
+
|
|
72
|
+
:returns: ``True`` when the status code is 404.
|
|
73
|
+
"""
|
|
74
|
+
rtnval = response.status_code == 404
|
|
75
|
+
return rtnval
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def iter_pages(*, fetch_page: Callable[[Optional[str]], Dict[str, Any]],
|
|
79
|
+
items_field: str = "items",
|
|
80
|
+
cursor_field: str = "next_page_token") -> Iterator[Dict[str, Any]]:
|
|
81
|
+
"""
|
|
82
|
+
Traverse a cursor-paginated Nebius list endpoint.
|
|
83
|
+
|
|
84
|
+
:param fetch_page: Callable accepting the current page token
|
|
85
|
+
(``None`` on the first call) and returning a page dict.
|
|
86
|
+
:param items_field: Name of the field holding the item list.
|
|
87
|
+
:param cursor_field: Name of the field holding the next page token;
|
|
88
|
+
an empty or absent value terminates traversal.
|
|
89
|
+
|
|
90
|
+
:returns: An iterator over the items across every page.
|
|
91
|
+
|
|
92
|
+
:raises: :class:`SemanticError` when a page omits the items field,
|
|
93
|
+
or when the endpoint returns a cursor token that has already
|
|
94
|
+
been seen (cursor cycle).
|
|
95
|
+
"""
|
|
96
|
+
cursor: Optional[str] = None
|
|
97
|
+
seen_cursors: List[str] = []
|
|
98
|
+
while True:
|
|
99
|
+
page = fetch_page(cursor)
|
|
100
|
+
if items_field not in page:
|
|
101
|
+
err_msg_lines = ["Nebius list page missing the items field."]
|
|
102
|
+
err_msg_lines.append("FIELD: {}".format(items_field))
|
|
103
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
104
|
+
raise SemanticError(err_msg)
|
|
105
|
+
|
|
106
|
+
items = page[items_field]
|
|
107
|
+
if items is None:
|
|
108
|
+
items = []
|
|
109
|
+
for item in items:
|
|
110
|
+
yield item
|
|
111
|
+
|
|
112
|
+
next_cursor = page.get(cursor_field, None)
|
|
113
|
+
if next_cursor is None or len(next_cursor) == 0:
|
|
114
|
+
break
|
|
115
|
+
|
|
116
|
+
if next_cursor in seen_cursors:
|
|
117
|
+
err_msg_lines = ["Nebius cursor pagination detected a cursor cycle."]
|
|
118
|
+
err_msg_lines.append("REPEATED CURSOR: {}".format(next_cursor))
|
|
119
|
+
err_msg = os.linesep.join(err_msg_lines)
|
|
120
|
+
raise SemanticError(err_msg)
|
|
121
|
+
|
|
122
|
+
seen_cursors.append(next_cursor)
|
|
123
|
+
cursor = next_cursor
|
|
124
|
+
return
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def collect_pages(*, fetch_page: Callable[[Optional[str]], Dict[str, Any]],
|
|
128
|
+
items_field: str = "items",
|
|
129
|
+
cursor_field: str = "next_page_token"
|
|
130
|
+
) -> List[Dict[str, Any]]:
|
|
131
|
+
"""
|
|
132
|
+
Collect every item from a cursor-paginated Nebius list endpoint.
|
|
133
|
+
|
|
134
|
+
:param fetch_page: Callable accepting the current page token.
|
|
135
|
+
:param items_field: Name of the field holding the item list.
|
|
136
|
+
:param cursor_field: Name of the field holding the next page token.
|
|
137
|
+
|
|
138
|
+
:returns: A list of all item dicts across every page.
|
|
139
|
+
"""
|
|
140
|
+
out: List[Dict[str, Any]] = []
|
|
141
|
+
for item in iter_pages(fetch_page=fetch_page, items_field=items_field,
|
|
142
|
+
cursor_field=cursor_field):
|
|
143
|
+
out.append(item)
|
|
144
|
+
rtnval = out
|
|
145
|
+
return rtnval
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""
|
|
2
|
+
.. module:: imagesgroup
|
|
3
|
+
:platform: Darwin, Linux, Unix, Windows
|
|
4
|
+
:synopsis: Module that contains the :class:`ImagesGroup` api group
|
|
5
|
+
exposing the Nebius image-catalog 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 Any, Dict, List, Optional
|
|
16
|
+
|
|
17
|
+
from ccai.restclient.base.restapigroup import RestApiGroup
|
|
18
|
+
|
|
19
|
+
from ccai.restclient.nebius.aspectsnebius import (
|
|
20
|
+
AspectsNebius, DEFAULT_NEBIUS_ASPECTS
|
|
21
|
+
)
|
|
22
|
+
from ccai.restclient.nebius.apigroups.groupsupport import (
|
|
23
|
+
collect_pages, raise_for_status
|
|
24
|
+
)
|
|
25
|
+
from ccai.restclient.nebius.model.nebiusimage import NebiusImage
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ImagesGroup(RestApiGroup):
|
|
29
|
+
"""
|
|
30
|
+
:class:`ImagesGroup` exposes the Nebius boot-image catalog
|
|
31
|
+
enumeration endpoint.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
BASE_LEAF = "/v1"
|
|
35
|
+
|
|
36
|
+
def list(self, *,
|
|
37
|
+
aspects: AspectsNebius = DEFAULT_NEBIUS_ASPECTS
|
|
38
|
+
) -> List[NebiusImage]:
|
|
39
|
+
"""
|
|
40
|
+
List every Nebius boot image.
|
|
41
|
+
|
|
42
|
+
:param aspects: Behaviour control for the call.
|
|
43
|
+
|
|
44
|
+
:returns: A list of :class:`NebiusImage` models carrying name,
|
|
45
|
+
family, version, and architecture.
|
|
46
|
+
"""
|
|
47
|
+
client = self.client
|
|
48
|
+
leaf = "/v1/images"
|
|
49
|
+
|
|
50
|
+
def _fetch(cursor: Optional[str]) -> Dict[str, Any]:
|
|
51
|
+
params: Dict[str, str] = {"page_size": str(aspects.page_size)}
|
|
52
|
+
if cursor is not None:
|
|
53
|
+
params["page_token"] = cursor
|
|
54
|
+
response = client.request(method="GET", leaf=leaf,
|
|
55
|
+
params=params, aspects=aspects)
|
|
56
|
+
raise_for_status(response=response, action="list images")
|
|
57
|
+
rtnval = response.json()
|
|
58
|
+
return rtnval
|
|
59
|
+
|
|
60
|
+
raw_items = collect_pages(fetch_page=_fetch)
|
|
61
|
+
out: List[NebiusImage] = []
|
|
62
|
+
for entry in raw_items:
|
|
63
|
+
out.append(NebiusImage.from_dict(entry))
|
|
64
|
+
rtnval = out
|
|
65
|
+
return rtnval
|