Skip to content

Commit 0c50515

Browse files
authored
feat(sbs): switch sbs to Private Beta (#893)
1 parent 9b08dd0 commit 0c50515

File tree

6 files changed

+1153
-0
lines changed

6 files changed

+1153
-0
lines changed
Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
API as ParentAPI,
5+
enrichForPagination,
6+
urlParams,
7+
validatePathParam,
8+
waitForResource,
9+
} from '../../../bridge'
10+
import type { WaitForOptions, Zone } from '../../../bridge'
11+
import {
12+
SNAPSHOT_TRANSIENT_STATUSES,
13+
VOLUME_TRANSIENT_STATUSES,
14+
} from './content.gen'
15+
import {
16+
marshalCreateSnapshotRequest,
17+
marshalCreateVolumeRequest,
18+
marshalUpdateSnapshotRequest,
19+
marshalUpdateVolumeRequest,
20+
unmarshalListSnapshotsResponse,
21+
unmarshalListVolumeTypesResponse,
22+
unmarshalListVolumesResponse,
23+
unmarshalSnapshot,
24+
unmarshalVolume,
25+
} from './marshalling.gen'
26+
import type {
27+
CreateSnapshotRequest,
28+
CreateVolumeRequest,
29+
DeleteSnapshotRequest,
30+
DeleteVolumeRequest,
31+
GetSnapshotRequest,
32+
GetVolumeRequest,
33+
ListSnapshotsRequest,
34+
ListSnapshotsResponse,
35+
ListVolumeTypesRequest,
36+
ListVolumeTypesResponse,
37+
ListVolumesRequest,
38+
ListVolumesResponse,
39+
Snapshot,
40+
UpdateSnapshotRequest,
41+
UpdateVolumeRequest,
42+
Volume,
43+
} from './types.gen'
44+
45+
const jsonContentHeaders = {
46+
'Content-Type': 'application/json; charset=utf-8',
47+
}
48+
49+
/**
50+
* Scaleway Block Storage (SBS) API.
51+
*
52+
* This API allows you to use and manage your Block Storage volumes. Scaleway
53+
* Block Storage (SBS) API.
54+
*/
55+
export class API extends ParentAPI {
56+
/** Lists the available zones of the API. */
57+
public static readonly LOCALITIES: Zone[] = ['fr-par-1', 'pl-waw-3']
58+
59+
protected pageOfListVolumeTypes = (
60+
request: Readonly<ListVolumeTypesRequest> = {},
61+
) =>
62+
this.client.fetch<ListVolumeTypesResponse>(
63+
{
64+
method: 'GET',
65+
path: `/block/v1alpha1/zones/${validatePathParam(
66+
'zone',
67+
request.zone ?? this.client.settings.defaultZone,
68+
)}/volume-types`,
69+
urlParams: urlParams(
70+
['page', request.page],
71+
[
72+
'page_size',
73+
request.pageSize ?? this.client.settings.defaultPageSize,
74+
],
75+
),
76+
},
77+
unmarshalListVolumeTypesResponse,
78+
)
79+
80+
/**
81+
* List volume types. List all available volume types in a specified zone. The
82+
* volume types listed are ordered by name in ascending order.
83+
*
84+
* @param request - The request {@link ListVolumeTypesRequest}
85+
* @returns A Promise of ListVolumeTypesResponse
86+
*/
87+
listVolumeTypes = (request: Readonly<ListVolumeTypesRequest> = {}) =>
88+
enrichForPagination('volumeTypes', this.pageOfListVolumeTypes, request)
89+
90+
protected pageOfListVolumes = (request: Readonly<ListVolumesRequest> = {}) =>
91+
this.client.fetch<ListVolumesResponse>(
92+
{
93+
method: 'GET',
94+
path: `/block/v1alpha1/zones/${validatePathParam(
95+
'zone',
96+
request.zone ?? this.client.settings.defaultZone,
97+
)}/volumes`,
98+
urlParams: urlParams(
99+
['name', request.name],
100+
['order_by', request.orderBy ?? 'created_at_asc'],
101+
['page', request.page],
102+
[
103+
'page_size',
104+
request.pageSize ?? this.client.settings.defaultPageSize,
105+
],
106+
['product_resource_id', request.productResourceId],
107+
['project_id', request.projectId],
108+
),
109+
},
110+
unmarshalListVolumesResponse,
111+
)
112+
113+
/**
114+
* List volumes. List all existing volumes in a specified zone. By default,
115+
* the volume listed are ordered by creation date in ascending order. This can
116+
* be modified via the `order_by` field.
117+
*
118+
* @param request - The request {@link ListVolumesRequest}
119+
* @returns A Promise of ListVolumesResponse
120+
*/
121+
listVolumes = (request: Readonly<ListVolumesRequest> = {}) =>
122+
enrichForPagination('volumes', this.pageOfListVolumes, request)
123+
124+
/**
125+
* Create a new empty volume by specifying the `size`. To create a volume from
126+
* an existing snapshot, specify the `snapshot_id` in the request payload
127+
* instead, size is optional and can be specified if you need to extend the
128+
* original size. In that case the created volume will have the same volume
129+
* class (and underlying IOPS limitations) as the originating snapshot. You
130+
* can specify the desired performance of the volume by setting `requirements`
131+
* accordingly.
132+
*
133+
* @param request - The request {@link CreateVolumeRequest}
134+
* @returns A Promise of Volume
135+
*/
136+
createVolume = (request: Readonly<CreateVolumeRequest>) =>
137+
this.client.fetch<Volume>(
138+
{
139+
body: JSON.stringify(
140+
marshalCreateVolumeRequest(request, this.client.settings),
141+
),
142+
headers: jsonContentHeaders,
143+
method: 'POST',
144+
path: `/block/v1alpha1/zones/${validatePathParam(
145+
'zone',
146+
request.zone ?? this.client.settings.defaultZone,
147+
)}/volumes`,
148+
},
149+
unmarshalVolume,
150+
)
151+
152+
/**
153+
* Get a volume. Retrieve technical information about a specific volume.
154+
* Details such as size, type, and status are returned in the response.
155+
*
156+
* @param request - The request {@link GetVolumeRequest}
157+
* @returns A Promise of Volume
158+
*/
159+
getVolume = (request: Readonly<GetVolumeRequest>) =>
160+
this.client.fetch<Volume>(
161+
{
162+
method: 'GET',
163+
path: `/block/v1alpha1/zones/${validatePathParam(
164+
'zone',
165+
request.zone ?? this.client.settings.defaultZone,
166+
)}/volumes/${validatePathParam('volumeId', request.volumeId)}`,
167+
},
168+
unmarshalVolume,
169+
)
170+
171+
/**
172+
* Waits for {@link Volume} to be in a final state.
173+
*
174+
* @param request - The request {@link GetVolumeRequest}
175+
* @param options - The waiting options
176+
* @returns A Promise of Volume
177+
*/
178+
waitForVolume = (
179+
request: Readonly<GetVolumeRequest>,
180+
options?: Readonly<WaitForOptions<Volume>>,
181+
) =>
182+
waitForResource(
183+
options?.stop ??
184+
(res =>
185+
Promise.resolve(!VOLUME_TRANSIENT_STATUSES.includes(res.status))),
186+
this.getVolume,
187+
request,
188+
options,
189+
)
190+
191+
/**
192+
* Delete a detached volume. You must specify the `volume_id` of the volume
193+
* you want to delete. The volume must not be in the `in_use` status.
194+
*
195+
* @param request - The request {@link DeleteVolumeRequest}
196+
*/
197+
deleteVolume = (request: Readonly<DeleteVolumeRequest>) =>
198+
this.client.fetch<void>({
199+
method: 'DELETE',
200+
path: `/block/v1alpha1/zones/${validatePathParam(
201+
'zone',
202+
request.zone ?? this.client.settings.defaultZone,
203+
)}/volumes/${validatePathParam('volumeId', request.volumeId)}`,
204+
})
205+
206+
/**
207+
* Update a volume. Update technical details about a volume, such as its name,
208+
* tags, or its new size and `volume_type` (within the same Block Storage
209+
* class). You can only resize a volume to a larger size. It is not possible
210+
* for now to change your Block Storage Class.
211+
*
212+
* @param request - The request {@link UpdateVolumeRequest}
213+
* @returns A Promise of Volume
214+
*/
215+
updateVolume = (request: Readonly<UpdateVolumeRequest>) =>
216+
this.client.fetch<Volume>(
217+
{
218+
body: JSON.stringify(
219+
marshalUpdateVolumeRequest(request, this.client.settings),
220+
),
221+
headers: jsonContentHeaders,
222+
method: 'PATCH',
223+
path: `/block/v1alpha1/zones/${validatePathParam(
224+
'zone',
225+
request.zone ?? this.client.settings.defaultZone,
226+
)}/volumes/${validatePathParam('volumeId', request.volumeId)}`,
227+
},
228+
unmarshalVolume,
229+
)
230+
231+
protected pageOfListSnapshots = (
232+
request: Readonly<ListSnapshotsRequest> = {},
233+
) =>
234+
this.client.fetch<ListSnapshotsResponse>(
235+
{
236+
method: 'GET',
237+
path: `/block/v1alpha1/zones/${validatePathParam(
238+
'zone',
239+
request.zone ?? this.client.settings.defaultZone,
240+
)}/snapshots`,
241+
urlParams: urlParams(
242+
['name', request.name],
243+
['order_by', request.orderBy ?? 'created_at_asc'],
244+
['page', request.page],
245+
[
246+
'page_size',
247+
request.pageSize ?? this.client.settings.defaultPageSize,
248+
],
249+
['project_id', request.projectId],
250+
['volume_id', request.volumeId],
251+
),
252+
},
253+
unmarshalListSnapshotsResponse,
254+
)
255+
256+
/**
257+
* List all snapshots. List all available snapshots in a specified zone. By
258+
* default, the snapshots listed are ordered by creation date in ascending
259+
* order. This can be modified via the `order_by` field.
260+
*
261+
* @param request - The request {@link ListSnapshotsRequest}
262+
* @returns A Promise of ListSnapshotsResponse
263+
*/
264+
listSnapshots = (request: Readonly<ListSnapshotsRequest> = {}) =>
265+
enrichForPagination('snapshots', this.pageOfListSnapshots, request)
266+
267+
/**
268+
* Get a snapshot. Retrieve technical information about a specific snapshot.
269+
* Details such as size, volume type, and status are returned in the
270+
* response.
271+
*
272+
* @param request - The request {@link GetSnapshotRequest}
273+
* @returns A Promise of Snapshot
274+
*/
275+
getSnapshot = (request: Readonly<GetSnapshotRequest>) =>
276+
this.client.fetch<Snapshot>(
277+
{
278+
method: 'GET',
279+
path: `/block/v1alpha1/zones/${validatePathParam(
280+
'zone',
281+
request.zone ?? this.client.settings.defaultZone,
282+
)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`,
283+
},
284+
unmarshalSnapshot,
285+
)
286+
287+
/**
288+
* Waits for {@link Snapshot} to be in a final state.
289+
*
290+
* @param request - The request {@link GetSnapshotRequest}
291+
* @param options - The waiting options
292+
* @returns A Promise of Snapshot
293+
*/
294+
waitForSnapshot = (
295+
request: Readonly<GetSnapshotRequest>,
296+
options?: Readonly<WaitForOptions<Snapshot>>,
297+
) =>
298+
waitForResource(
299+
options?.stop ??
300+
(res =>
301+
Promise.resolve(!SNAPSHOT_TRANSIENT_STATUSES.includes(res.status))),
302+
this.getSnapshot,
303+
request,
304+
options,
305+
)
306+
307+
/**
308+
* Create a snapshot of a volume. To create a snapshot, the volume must be in
309+
* the `in_use` or the `available` status. If your volume is in a transient
310+
* state, you need to wait until the end of the current operation.
311+
*
312+
* @param request - The request {@link CreateSnapshotRequest}
313+
* @returns A Promise of Snapshot
314+
*/
315+
createSnapshot = (request: Readonly<CreateSnapshotRequest>) =>
316+
this.client.fetch<Snapshot>(
317+
{
318+
body: JSON.stringify(
319+
marshalCreateSnapshotRequest(request, this.client.settings),
320+
),
321+
headers: jsonContentHeaders,
322+
method: 'POST',
323+
path: `/block/v1alpha1/zones/${validatePathParam(
324+
'zone',
325+
request.zone ?? this.client.settings.defaultZone,
326+
)}/snapshots`,
327+
},
328+
unmarshalSnapshot,
329+
)
330+
331+
/**
332+
* Delete a snapshot. You must specify the `snapshot_id` of the snapshot you
333+
* want to delete. The snapshot must not be in use.
334+
*
335+
* @param request - The request {@link DeleteSnapshotRequest}
336+
*/
337+
deleteSnapshot = (request: Readonly<DeleteSnapshotRequest>) =>
338+
this.client.fetch<void>({
339+
method: 'DELETE',
340+
path: `/block/v1alpha1/zones/${validatePathParam(
341+
'zone',
342+
request.zone ?? this.client.settings.defaultZone,
343+
)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`,
344+
})
345+
346+
/**
347+
* Update a snapshot. Update name or tags of the snapshot.
348+
*
349+
* @param request - The request {@link UpdateSnapshotRequest}
350+
* @returns A Promise of Snapshot
351+
*/
352+
updateSnapshot = (request: Readonly<UpdateSnapshotRequest>) =>
353+
this.client.fetch<Snapshot>(
354+
{
355+
body: JSON.stringify(
356+
marshalUpdateSnapshotRequest(request, this.client.settings),
357+
),
358+
headers: jsonContentHeaders,
359+
method: 'PATCH',
360+
path: `/block/v1alpha1/zones/${validatePathParam(
361+
'zone',
362+
request.zone ?? this.client.settings.defaultZone,
363+
)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`,
364+
},
365+
unmarshalSnapshot,
366+
)
367+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import type { ReferenceStatus, SnapshotStatus, VolumeStatus } from './types.gen'
4+
5+
/** Lists transient statutes of the enum {@link ReferenceStatus}. */
6+
export const REFERENCE_TRANSIENT_STATUSES: ReferenceStatus[] = [
7+
'attaching',
8+
'detaching',
9+
'snapshotting',
10+
]
11+
12+
/** Lists transient statutes of the enum {@link SnapshotStatus}. */
13+
export const SNAPSHOT_TRANSIENT_STATUSES: SnapshotStatus[] = [
14+
'creating',
15+
'deleting',
16+
]
17+
18+
/** Lists transient statutes of the enum {@link VolumeStatus}. */
19+
export const VOLUME_TRANSIENT_STATUSES: VolumeStatus[] = [
20+
'creating',
21+
'deleting',
22+
'resizing',
23+
'snapshotting',
24+
]

0 commit comments

Comments
 (0)