Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/clients/src/api/instance/v1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
marshalCreateServerRequest,
marshalCreateSnapshotRequest,
marshalCreateVolumeRequest,
marshalExportSnapshotRequest,
marshalServerActionRequest,
marshalSetImageRequest,
marshalSetPlacementGroupRequest,
Expand All @@ -40,6 +41,7 @@ import {
unmarshalCreateServerResponse,
unmarshalCreateSnapshotResponse,
unmarshalCreateVolumeResponse,
unmarshalExportSnapshotResponse,
unmarshalGetBootscriptResponse,
unmarshalGetDashboardResponse,
unmarshalGetImageResponse,
Expand Down Expand Up @@ -110,6 +112,8 @@ import type {
DeleteServerUserDataRequest,
DeleteSnapshotRequest,
DeleteVolumeRequest,
ExportSnapshotRequest,
ExportSnapshotResponse,
GetBootscriptRequest,
GetBootscriptResponse,
GetDashboardRequest,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ExportSnapshotRequest>) =>
this.client.fetch<ExportSnapshotResponse>(
{
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<ListVolumesRequest> = {}) =>
this.client.fetch<ListVolumesResponse>(
{
Expand Down
26 changes: 26 additions & 0 deletions packages/clients/src/api/instance/v1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import type {
CreateVolumeRequest,
CreateVolumeResponse,
Dashboard,
ExportSnapshotRequest,
ExportSnapshotResponse,
GetBootscriptResponse,
GetDashboardResponse,
GetImageResponse,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -1753,7 +1768,10 @@ export const marshalCreateSnapshotRequest = (
request: CreateSnapshotRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
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,
Expand Down Expand Up @@ -1806,6 +1824,14 @@ export const marshalCreateVolumeRequest = (
]),
})

export const marshalExportSnapshotRequest = (
request: ExportSnapshotRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
bucket: request.bucket,
key: request.key,
})

export const marshalServerActionRequest = (
request: ServerActionRequest,
defaults: DefaultValues,
Expand Down
23 changes: 23 additions & 0 deletions packages/clients/src/api/instance/v1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ export interface Dashboard {
ipsUnused: number
}

export interface ExportSnapshotResponse {
task?: Task
}

export interface GetBootscriptResponse {
bootscript?: Bootscript
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
Expand Down