-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathvfolder.py
More file actions
265 lines (240 loc) · 7.7 KB
/
vfolder.py
File metadata and controls
265 lines (240 loc) · 7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
"""V2 REST SDK client for the VFolder resource."""
from __future__ import annotations
from uuid import UUID
from ai.backend.client.v2.base_domain import BaseDomainClient
from ai.backend.common.dto.manager.v2.vfolder.request import (
BulkDeleteVFoldersInput,
BulkPurgeVFoldersInput,
CloneVFolderInput,
CreateDownloadSessionInput,
CreateUploadSessionInput,
CreateVFolderInput,
CreateVFolderInScopeInput,
DeleteFilesInput,
DeployVFolderInput,
ListFilesInput,
MkdirInput,
MoveFileInput,
SearchVFoldersInput,
)
from ai.backend.common.dto.manager.v2.vfolder.response import (
BulkDeleteVFoldersPayload,
BulkPurgeVFoldersPayload,
CloneVFolderPayload,
CreateDownloadSessionPayload,
CreateUploadSessionPayload,
CreateVFolderPayload,
DeleteFilesPayload,
DeleteVFolderPayload,
DeployVFolderPayload,
ListFilesPayload,
MkdirPayload,
MoveFilePayload,
PurgeVFolderPayload,
RestoreVFolderPayload,
SearchVFoldersPayload,
VFolderNode,
)
_PATH = "/v2/vfolders"
class V2VFolderClient(BaseDomainClient):
"""SDK client for ``/v2/vfolders`` endpoints."""
async def my_search(
self,
request: SearchVFoldersInput,
) -> SearchVFoldersPayload:
"""Search vfolders owned by the current user."""
return await self._client.typed_request(
"POST",
f"{_PATH}/my/search",
request=request,
response_model=SearchVFoldersPayload,
)
async def project_search(
self,
project_id: UUID,
request: SearchVFoldersInput,
) -> SearchVFoldersPayload:
"""Search vfolders within a project."""
return await self._client.typed_request(
"POST",
f"{_PATH}/projects/{project_id}/search",
request=request,
response_model=SearchVFoldersPayload,
)
async def create(self, request: CreateVFolderInput) -> CreateVFolderPayload:
"""Create a new vfolder."""
return await self._client.typed_request(
"POST",
_PATH,
request=request,
response_model=CreateVFolderPayload,
)
async def create_in_project(
self,
project_id: UUID,
request: CreateVFolderInScopeInput,
) -> CreateVFolderPayload:
"""Create a vfolder owned by ``project_id``."""
return await self._client.typed_request(
"POST",
f"{_PATH}/projects/{project_id}/create",
request=request,
response_model=CreateVFolderPayload,
)
async def create_upload_session(
self,
vfolder_id: UUID,
request: CreateUploadSessionInput,
) -> CreateUploadSessionPayload:
"""Create an upload session for a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/upload-session",
request=request,
response_model=CreateUploadSessionPayload,
)
async def admin_search(
self,
request: SearchVFoldersInput,
) -> SearchVFoldersPayload:
"""Search all vfolders (superadmin only)."""
return await self._client.typed_request(
"POST",
f"{_PATH}/search",
request=request,
response_model=SearchVFoldersPayload,
)
async def get(self, vfolder_id: UUID) -> VFolderNode:
"""Get a vfolder by ID."""
return await self._client.typed_request(
"GET",
f"{_PATH}/{vfolder_id}",
response_model=VFolderNode,
)
async def delete(self, vfolder_id: UUID) -> DeleteVFolderPayload:
"""Soft-delete a vfolder."""
return await self._client.typed_request(
"DELETE",
f"{_PATH}/{vfolder_id}",
response_model=DeleteVFolderPayload,
)
async def purge(self, vfolder_id: UUID) -> PurgeVFolderPayload:
"""Permanently delete a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/purge",
response_model=PurgeVFolderPayload,
)
async def restore(self, vfolder_id: UUID) -> RestoreVFolderPayload:
"""Restore a trashed vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/restore",
response_model=RestoreVFolderPayload,
)
async def deploy(
self,
vfolder_id: UUID,
request: DeployVFolderInput,
) -> DeployVFolderPayload:
"""Deploy a deployment directly from a model VFolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/deploy",
request=request,
response_model=DeployVFolderPayload,
)
async def list_files(
self,
vfolder_id: UUID,
request: ListFilesInput,
) -> ListFilesPayload:
"""List files in a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/files/list",
request=request,
response_model=ListFilesPayload,
)
async def mkdir(
self,
vfolder_id: UUID,
request: MkdirInput,
) -> MkdirPayload:
"""Create a directory in a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/files/mkdir",
request=request,
response_model=MkdirPayload,
)
async def move_file(
self,
vfolder_id: UUID,
request: MoveFileInput,
) -> MoveFilePayload:
"""Move a file within a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/files/move",
request=request,
response_model=MoveFilePayload,
)
async def delete_files(
self,
vfolder_id: UUID,
request: DeleteFilesInput,
) -> DeleteFilesPayload:
"""Delete files in a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/files/delete",
request=request,
response_model=DeleteFilesPayload,
)
async def create_download_session(
self,
vfolder_id: UUID,
request: CreateDownloadSessionInput,
) -> CreateDownloadSessionPayload:
"""Create a download session for a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/download-session",
request=request,
response_model=CreateDownloadSessionPayload,
)
async def clone(
self,
vfolder_id: UUID,
request: CloneVFolderInput,
) -> CloneVFolderPayload:
"""Clone a vfolder."""
return await self._client.typed_request(
"POST",
f"{_PATH}/{vfolder_id}/clone",
request=request,
response_model=CloneVFolderPayload,
)
async def bulk_delete(
self,
request: BulkDeleteVFoldersInput,
) -> BulkDeleteVFoldersPayload:
"""Soft-delete multiple vfolders."""
return await self._client.typed_request(
"POST",
f"{_PATH}/delete",
request=request,
response_model=BulkDeleteVFoldersPayload,
)
async def bulk_purge(
self,
request: BulkPurgeVFoldersInput,
) -> BulkPurgeVFoldersPayload:
"""Permanently purge multiple vfolders."""
return await self._client.typed_request(
"POST",
f"{_PATH}/purge",
request=request,
response_model=BulkPurgeVFoldersPayload,
)