Skip to content

Commit 5a5009e

Browse files
authored
feat(block): add exporting snapshot to s3 (#1302)
1 parent 329b018 commit 5a5009e

File tree

6 files changed

+116
-0
lines changed

6 files changed

+116
-0
lines changed

packages/clients/src/api/block/v1alpha1/api.gen.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
import {
1616
marshalCreateSnapshotRequest,
1717
marshalCreateVolumeRequest,
18+
marshalExportSnapshotToObjectStorageRequest,
19+
marshalImportSnapshotFromObjectStorageRequest,
1820
marshalImportSnapshotFromS3Request,
1921
marshalUpdateSnapshotRequest,
2022
marshalUpdateVolumeRequest,
@@ -29,8 +31,10 @@ import type {
2931
CreateVolumeRequest,
3032
DeleteSnapshotRequest,
3133
DeleteVolumeRequest,
34+
ExportSnapshotToObjectStorageRequest,
3235
GetSnapshotRequest,
3336
GetVolumeRequest,
37+
ImportSnapshotFromObjectStorageRequest,
3438
ImportSnapshotFromS3Request,
3539
ListSnapshotsRequest,
3640
ListSnapshotsResponse,
@@ -314,6 +318,7 @@ export class API extends ParentAPI {
314318
* contain a QCOW2 image. The bucket can be imported into any Availability
315319
* Zone as long as it is in the same region as the bucket.
316320
*
321+
* @deprecated
317322
* @param request - The request {@link ImportSnapshotFromS3Request}
318323
* @returns A Promise of Snapshot
319324
*/
@@ -330,6 +335,57 @@ export class API extends ParentAPI {
330335
unmarshalSnapshot,
331336
)
332337

338+
/**
339+
* Import a snapshot from a Scaleway Object Storage bucket. The bucket must
340+
* contain a QCOW2 image. The bucket can be imported into any Availability
341+
* Zone as long as it is in the same region as the bucket.
342+
*
343+
* @param request - The request {@link ImportSnapshotFromObjectStorageRequest}
344+
* @returns A Promise of Snapshot
345+
*/
346+
importSnapshotFromObjectStorage = (
347+
request: Readonly<ImportSnapshotFromObjectStorageRequest>,
348+
) =>
349+
this.client.fetch<Snapshot>(
350+
{
351+
body: JSON.stringify(
352+
marshalImportSnapshotFromObjectStorageRequest(
353+
request,
354+
this.client.settings,
355+
),
356+
),
357+
headers: jsonContentHeaders,
358+
method: 'POST',
359+
path: `/block/v1alpha1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/import-from-object-storage`,
360+
},
361+
unmarshalSnapshot,
362+
)
363+
364+
/**
365+
* Export a snapshot to a Scaleway Object Storage bucket. The snapshot is
366+
* exported in QCOW2 format. The snapshot must not be in transient state.
367+
*
368+
* @param request - The request {@link ExportSnapshotToObjectStorageRequest}
369+
* @returns A Promise of Snapshot
370+
*/
371+
exportSnapshotToObjectStorage = (
372+
request: Readonly<ExportSnapshotToObjectStorageRequest>,
373+
) =>
374+
this.client.fetch<Snapshot>(
375+
{
376+
body: JSON.stringify(
377+
marshalExportSnapshotToObjectStorageRequest(
378+
request,
379+
this.client.settings,
380+
),
381+
),
382+
headers: jsonContentHeaders,
383+
method: 'POST',
384+
path: `/block/v1alpha1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}/export-to-object-storage`,
385+
},
386+
unmarshalSnapshot,
387+
)
388+
333389
/**
334390
* Delete a snapshot. You must specify the `snapshot_id` of the snapshot you
335391
* want to delete. The snapshot must not be in use.

packages/clients/src/api/block/v1alpha1/content.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const REFERENCE_TRANSIENT_STATUSES: ReferenceStatus[] = [
1313
export const SNAPSHOT_TRANSIENT_STATUSES: SnapshotStatus[] = [
1414
'creating',
1515
'deleting',
16+
'exporting',
1617
]
1718

1819
/** Lists transient statutes of the enum {@link VolumeStatus}. */

packages/clients/src/api/block/v1alpha1/index.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export type {
99
CreateVolumeRequestFromSnapshot,
1010
DeleteSnapshotRequest,
1111
DeleteVolumeRequest,
12+
ExportSnapshotToObjectStorageRequest,
1213
GetSnapshotRequest,
1314
GetVolumeRequest,
15+
ImportSnapshotFromObjectStorageRequest,
1416
ImportSnapshotFromS3Request,
1517
ListSnapshotsRequest,
1618
ListSnapshotsRequestOrderBy,

packages/clients/src/api/block/v1alpha1/marshalling.gen.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type {
1313
CreateVolumeRequest,
1414
CreateVolumeRequestFromEmpty,
1515
CreateVolumeRequestFromSnapshot,
16+
ExportSnapshotToObjectStorageRequest,
17+
ImportSnapshotFromObjectStorageRequest,
1618
ImportSnapshotFromS3Request,
1719
ListSnapshotsResponse,
1820
ListVolumeTypesResponse,
@@ -238,6 +240,26 @@ export const marshalCreateVolumeRequest = (
238240
...resolveOneOf([{ param: 'perf_iops', value: request.perfIops }]),
239241
})
240242

243+
export const marshalExportSnapshotToObjectStorageRequest = (
244+
request: ExportSnapshotToObjectStorageRequest,
245+
defaults: DefaultValues,
246+
): Record<string, unknown> => ({
247+
bucket: request.bucket,
248+
key: request.key,
249+
})
250+
251+
export const marshalImportSnapshotFromObjectStorageRequest = (
252+
request: ImportSnapshotFromObjectStorageRequest,
253+
defaults: DefaultValues,
254+
): Record<string, unknown> => ({
255+
bucket: request.bucket,
256+
key: request.key,
257+
name: request.name,
258+
project_id: request.projectId ?? defaults.defaultProjectId,
259+
size: request.size,
260+
tags: request.tags,
261+
})
262+
241263
export const marshalImportSnapshotFromS3Request = (
242264
request: ImportSnapshotFromS3Request,
243265
defaults: DefaultValues,

packages/clients/src/api/block/v1alpha1/types.gen.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type SnapshotStatus =
3434
| 'deleted'
3535
| 'in_use'
3636
| 'locked'
37+
| 'exporting'
3738

3839
export type StorageClass =
3940
| 'unknown_storage_class'
@@ -241,6 +242,17 @@ export type DeleteVolumeRequest = {
241242
volumeId: string
242243
}
243244

245+
export type ExportSnapshotToObjectStorageRequest = {
246+
/** Zone to target. If none is passed will use default zone from the config. */
247+
zone?: Zone
248+
/** UUID of the snapshot. */
249+
snapshotId: string
250+
/** Scaleway Object Storage bucket where the object is stored. */
251+
bucket: string
252+
/** The object key inside the given bucket. */
253+
key: string
254+
}
255+
244256
export type GetSnapshotRequest = {
245257
/** Zone to target. If none is passed will use default zone from the config. */
246258
zone?: Zone
@@ -255,6 +267,23 @@ export type GetVolumeRequest = {
255267
volumeId: string
256268
}
257269

270+
export type ImportSnapshotFromObjectStorageRequest = {
271+
/** Zone to target. If none is passed will use default zone from the config. */
272+
zone?: Zone
273+
/** Scaleway Object Storage bucket where the object is stored. */
274+
bucket: string
275+
/** The object key inside the given bucket. */
276+
key: string
277+
/** Name of the snapshot. */
278+
name: string
279+
/** UUID of the Project to which the volume and the snapshot belong. */
280+
projectId?: string
281+
/** List of tags assigned to the snapshot. */
282+
tags?: string[]
283+
/** Size of the snapshot. */
284+
size?: number
285+
}
286+
258287
export type ImportSnapshotFromS3Request = {
259288
/** Zone to target. If none is passed will use default zone from the config. */
260289
zone?: Zone

packages/clients/src/api/block/v1alpha1/validation-rules.gen.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ export const CreateVolumeRequest = {
1313
},
1414
}
1515

16+
export const ImportSnapshotFromObjectStorageRequest = {
17+
name: {
18+
minLength: 1,
19+
},
20+
}
21+
1622
export const ImportSnapshotFromS3Request = {
1723
name: {
1824
minLength: 1,

0 commit comments

Comments
 (0)