diff --git a/packages/clients/src/api/instance/v1/api.gen.ts b/packages/clients/src/api/instance/v1/api.gen.ts index db7b5a8bd..046064b2a 100644 --- a/packages/clients/src/api/instance/v1/api.gen.ts +++ b/packages/clients/src/api/instance/v1/api.gen.ts @@ -17,6 +17,7 @@ import { marshalCreateServerRequest, marshalCreateSnapshotRequest, marshalCreateVolumeRequest, + marshalExportSnapshotRequest, marshalServerActionRequest, marshalSetImageRequest, marshalSetPlacementGroupRequest, @@ -40,6 +41,7 @@ import { unmarshalCreateServerResponse, unmarshalCreateSnapshotResponse, unmarshalCreateVolumeResponse, + unmarshalExportSnapshotResponse, unmarshalGetBootscriptResponse, unmarshalGetDashboardResponse, unmarshalGetImageResponse, @@ -110,6 +112,8 @@ import type { DeleteServerUserDataRequest, DeleteSnapshotRequest, DeleteVolumeRequest, + ExportSnapshotRequest, + ExportSnapshotResponse, GetBootscriptRequest, GetBootscriptResponse, GetDashboardRequest, @@ -627,7 +631,7 @@ export class InstanceV1GenAPI extends API { enrichForPagination('snapshots', this.pageOfListSnapshots, request) /** - * Create a snapshot from a given volume + * Create a snapshot from a given volume or from a QCOW2 file * * @param request - The request {@link CreateSnapshotRequest} * @returns A Promise of CreateSnapshotResponse @@ -696,6 +700,31 @@ export class InstanceV1GenAPI extends API { )}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, }) + /** + * Export a snapshot to a given S3 bucket in the same region. + * + * @param request - The request {@link ExportSnapshotRequest} + * @returns A Promise of ExportSnapshotResponse + */ + exportSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalExportSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/snapshots/${validatePathParam( + 'snapshotId', + request.snapshotId, + )}/export`, + }, + unmarshalExportSnapshotResponse, + ) + protected pageOfListVolumes = (request: Readonly = {}) => this.client.fetch( { diff --git a/packages/clients/src/api/instance/v1/marshalling.gen.ts b/packages/clients/src/api/instance/v1/marshalling.gen.ts index f83b79579..82a7348bd 100644 --- a/packages/clients/src/api/instance/v1/marshalling.gen.ts +++ b/packages/clients/src/api/instance/v1/marshalling.gen.ts @@ -29,6 +29,8 @@ import type { CreateVolumeRequest, CreateVolumeResponse, Dashboard, + ExportSnapshotRequest, + ExportSnapshotResponse, GetBootscriptResponse, GetDashboardResponse, GetImageResponse, @@ -645,6 +647,7 @@ const unmarshalSnapshot = (data: unknown) => { ? unmarshalSnapshotBaseVolume(data.base_volume) : undefined, creationDate: unmarshalDate(data.creation_date), + errorReason: data.error_reason, id: data.id, modificationDate: unmarshalDate(data.modification_date), name: data.name, @@ -814,6 +817,18 @@ export const unmarshalCreateVolumeResponse = (data: unknown) => { } as CreateVolumeResponse } +export const unmarshalExportSnapshotResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ExportSnapshotResponse' failed as data isn't a dictionary.`, + ) + } + + return { + task: data.task ? unmarshalTask(data.task) : undefined, + } as ExportSnapshotResponse +} + export const unmarshalGetBootscriptResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -1753,7 +1768,10 @@ export const marshalCreateSnapshotRequest = ( request: CreateSnapshotRequest, defaults: DefaultValues, ): Record => ({ + bucket: request.bucket, + key: request.key, name: request.name || randomName('snp'), + size: request.size, tags: request.tags, volume_id: request.volumeId, volume_type: request.volumeType, @@ -1806,6 +1824,14 @@ export const marshalCreateVolumeRequest = ( ]), }) +export const marshalExportSnapshotRequest = ( + request: ExportSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + bucket: request.bucket, + key: request.key, +}) + export const marshalServerActionRequest = ( request: ServerActionRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/instance/v1/types.gen.ts b/packages/clients/src/api/instance/v1/types.gen.ts index d74ea4325..b88f6fdf8 100644 --- a/packages/clients/src/api/instance/v1/types.gen.ts +++ b/packages/clients/src/api/instance/v1/types.gen.ts @@ -167,6 +167,10 @@ export interface Dashboard { ipsUnused: number } +export interface ExportSnapshotResponse { + task?: Task +} + export interface GetBootscriptResponse { bootscript?: Bootscript } @@ -707,6 +711,8 @@ export interface Snapshot { modificationDate?: Date /** The snapshot zone */ zone: Zone + /** The reason for the failed snapshot import */ + errorReason?: string } /** Snapshot. base volume */ @@ -1074,6 +1080,12 @@ export type CreateSnapshotRequest = { * the original volume will be used. */ volumeType: SnapshotVolumeType + /** Bucket name for snapshot imports */ + bucket?: string + /** Object key for snapshot imports */ + key?: string + /** Imported snapshot size, must be a multiple of 512 */ + size?: number } export type GetSnapshotRequest = { @@ -1090,6 +1102,17 @@ export type DeleteSnapshotRequest = { snapshotId: string } +export type ExportSnapshotRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** The snapshot ID */ + snapshotId: string + /** S3 bucket name */ + bucket: string + /** S3 object key */ + key: string +} + export type ListVolumesRequest = { /** Zone to target. If none is passed will use default zone from the config */ zone?: Zone