diff --git a/packages/clients/src/api/block/index.gen.ts b/packages/clients/src/api/block/index.gen.ts index 6dec29b44..3c605af8e 100644 --- a/packages/clients/src/api/block/index.gen.ts +++ b/packages/clients/src/api/block/index.gen.ts @@ -3,4 +3,5 @@ * EDIT HERE */ +export * as v1 from './v1/index.gen' export * as v1alpha1 from './v1alpha1/index.gen' diff --git a/packages/clients/src/api/block/v1/api.gen.ts b/packages/clients/src/api/block/v1/api.gen.ts new file mode 100644 index 000000000..39acf0466 --- /dev/null +++ b/packages/clients/src/api/block/v1/api.gen.ts @@ -0,0 +1,401 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API as ParentAPI, + enrichForPagination, + urlParams, + validatePathParam, + waitForResource, +} from '../../../bridge' +import type { Zone as ScwZone, WaitForOptions } from '../../../bridge' +import { + SNAPSHOT_TRANSIENT_STATUSES, + VOLUME_TRANSIENT_STATUSES, +} from './content.gen' +import { + marshalCreateSnapshotRequest, + marshalCreateVolumeRequest, + marshalExportSnapshotToObjectStorageRequest, + marshalImportSnapshotFromObjectStorageRequest, + marshalUpdateSnapshotRequest, + marshalUpdateVolumeRequest, + unmarshalListSnapshotsResponse, + unmarshalListVolumeTypesResponse, + unmarshalListVolumesResponse, + unmarshalSnapshot, + unmarshalVolume, +} from './marshalling.gen' +import type { + CreateSnapshotRequest, + CreateVolumeRequest, + DeleteSnapshotRequest, + DeleteVolumeRequest, + ExportSnapshotToObjectStorageRequest, + GetSnapshotRequest, + GetVolumeRequest, + ImportSnapshotFromObjectStorageRequest, + ListSnapshotsRequest, + ListSnapshotsResponse, + ListVolumeTypesRequest, + ListVolumeTypesResponse, + ListVolumesRequest, + ListVolumesResponse, + Snapshot, + UpdateSnapshotRequest, + UpdateVolumeRequest, + Volume, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** + * Block Storage API. + * + * This API allows you to manage your Block Storage volumes. + */ +export class API extends ParentAPI { + /** Lists the available zones of the API. */ + public static readonly LOCALITIES: ScwZone[] = [ + 'fr-par-1', + 'fr-par-2', + 'fr-par-3', + 'nl-ams-1', + 'nl-ams-2', + 'nl-ams-3', + 'pl-waw-1', + 'pl-waw-2', + 'pl-waw-3', + ] + + protected pageOfListVolumeTypes = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/volume-types`, + urlParams: urlParams( + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListVolumeTypesResponse, + ) + + /** + * List volume types. List all available volume types in a specified zone. The + * volume types listed are ordered by name in ascending order. + * + * @param request - The request {@link ListVolumeTypesRequest} + * @returns A Promise of ListVolumeTypesResponse + */ + listVolumeTypes = (request: Readonly = {}) => + enrichForPagination('volumeTypes', this.pageOfListVolumeTypes, request) + + protected pageOfListVolumes = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/volumes`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['product_resource_id', request.productResourceId], + ['project_id', request.projectId], + ['tags', request.tags], + ), + }, + unmarshalListVolumesResponse, + ) + + /** + * List volumes. List all existing volumes in a specified zone. By default, + * the volumes listed are ordered by creation date in ascending order. This + * can be modified via the `order_by` field. + * + * @param request - The request {@link ListVolumesRequest} + * @returns A Promise of ListVolumesResponse + */ + listVolumes = (request: Readonly = {}) => + enrichForPagination('volumes', this.pageOfListVolumes, request) + + /** + * Create a volume. To create a new volume from scratch, you must specify + * `from_empty` and the `size`. To create a volume from an existing snapshot, + * specify `from_snapshot` and the `snapshot_id` in the request payload + * instead, size is optional and can be specified if you need to extend the + * original size. The volume will take on the same volume class and underlying + * IOPS limitations as the original snapshot. + * + * @param request - The request {@link CreateVolumeRequest} + * @returns A Promise of Volume + */ + createVolume = (request: Readonly = {}) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateVolumeRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/volumes`, + }, + unmarshalVolume, + ) + + /** + * Get a volume. Retrieve technical information about a specific volume. + * Details such as size, type, and status are returned in the response. + * + * @param request - The request {@link GetVolumeRequest} + * @returns A Promise of Volume + */ + getVolume = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/volumes/${validatePathParam('volumeId', request.volumeId)}`, + }, + unmarshalVolume, + ) + + /** + * Waits for {@link Volume} to be in a final state. + * + * @param request - The request {@link GetVolumeRequest} + * @param options - The waiting options + * @returns A Promise of Volume + */ + waitForVolume = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!VOLUME_TRANSIENT_STATUSES.includes(res.status))), + this.getVolume, + request, + options, + ) + + /** + * Delete a detached volume. You must specify the `volume_id` of the volume + * you want to delete. The volume must not be in the `in_use` status. + * + * @param request - The request {@link DeleteVolumeRequest} + */ + deleteVolume = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/volumes/${validatePathParam('volumeId', request.volumeId)}`, + }) + + /** + * Update a volume. Update the technical details of a volume, such as its + * name, tags, or its new size and `volume_type` (within the same Block + * Storage class). You can only resize a volume to a larger size. It is + * currently not possible to change your Block Storage Class. + * + * @param request - The request {@link UpdateVolumeRequest} + * @returns A Promise of Volume + */ + updateVolume = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateVolumeRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/volumes/${validatePathParam('volumeId', request.volumeId)}`, + }, + unmarshalVolume, + ) + + protected pageOfListSnapshots = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['project_id', request.projectId], + ['tags', request.tags], + ['volume_id', request.volumeId], + ), + }, + unmarshalListSnapshotsResponse, + ) + + /** + * List all snapshots. List all available snapshots in a specified zone. By + * default, the snapshots listed are ordered by creation date in ascending + * order. This can be modified via the `order_by` field. + * + * @param request - The request {@link ListSnapshotsRequest} + * @returns A Promise of ListSnapshotsResponse + */ + listSnapshots = (request: Readonly = {}) => + enrichForPagination('snapshots', this.pageOfListSnapshots, request) + + /** + * Get a snapshot. Retrieve technical information about a specific snapshot. + * Details such as size, volume type, and status are returned in the + * response. + * + * @param request - The request {@link GetSnapshotRequest} + * @returns A Promise of Snapshot + */ + getSnapshot = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, + }, + unmarshalSnapshot, + ) + + /** + * Waits for {@link Snapshot} to be in a final state. + * + * @param request - The request {@link GetSnapshotRequest} + * @param options - The waiting options + * @returns A Promise of Snapshot + */ + waitForSnapshot = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!SNAPSHOT_TRANSIENT_STATUSES.includes(res.status))), + this.getSnapshot, + request, + options, + ) + + /** + * Create a snapshot of a volume. To create a snapshot, the volume must be in + * the `in_use` or the `available` status. If your volume is in a transient + * state, you need to wait until the end of the current operation. + * + * @param request - The request {@link CreateSnapshotRequest} + * @returns A Promise of Snapshot + */ + createSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots`, + }, + unmarshalSnapshot, + ) + + /** + * Import a snapshot from a Scaleway Object Storage bucket. The bucket must + * contain a QCOW2 image. The bucket can be imported into any Availability + * Zone as long as it is in the same region as the bucket. + * + * @param request - The request {@link ImportSnapshotFromObjectStorageRequest} + * @returns A Promise of Snapshot + */ + importSnapshotFromObjectStorage = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalImportSnapshotFromObjectStorageRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/import-from-object-storage`, + }, + unmarshalSnapshot, + ) + + /** + * Export a snapshot to a Scaleway Object Storage bucket. The snapshot is + * exported in QCOW2 format. The snapshot must not be in transient state. + * + * @param request - The request {@link ExportSnapshotToObjectStorageRequest} + * @returns A Promise of Snapshot + */ + exportSnapshotToObjectStorage = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalExportSnapshotToObjectStorageRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}/export-to-object-storage`, + }, + unmarshalSnapshot, + ) + + /** + * Delete a snapshot. You must specify the `snapshot_id` of the snapshot you + * want to delete. The snapshot must not be in use. + * + * @param request - The request {@link DeleteSnapshotRequest} + */ + deleteSnapshot = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, + }) + + /** + * Update a snapshot. Update the name or tags of the snapshot. + * + * @param request - The request {@link UpdateSnapshotRequest} + * @returns A Promise of Snapshot + */ + updateSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/block/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, + }, + unmarshalSnapshot, + ) +} diff --git a/packages/clients/src/api/block/v1/content.gen.ts b/packages/clients/src/api/block/v1/content.gen.ts new file mode 100644 index 000000000..2e3e5f343 --- /dev/null +++ b/packages/clients/src/api/block/v1/content.gen.ts @@ -0,0 +1,26 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { ReferenceStatus, SnapshotStatus, VolumeStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link ReferenceStatus}. */ +export const REFERENCE_TRANSIENT_STATUSES: ReferenceStatus[] = [ + 'attaching', + 'detaching', + 'creating', +] + +/** Lists transient statutes of the enum {@link SnapshotStatus}. */ +export const SNAPSHOT_TRANSIENT_STATUSES: SnapshotStatus[] = [ + 'creating', + 'deleting', + 'exporting', +] + +/** Lists transient statutes of the enum {@link VolumeStatus}. */ +export const VOLUME_TRANSIENT_STATUSES: VolumeStatus[] = [ + 'creating', + 'deleting', + 'resizing', + 'snapshotting', + 'updating', +] diff --git a/packages/clients/src/api/block/v1/index.gen.ts b/packages/clients/src/api/block/v1/index.gen.ts new file mode 100644 index 000000000..e21aefad4 --- /dev/null +++ b/packages/clients/src/api/block/v1/index.gen.ts @@ -0,0 +1,38 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +export { API } from './api.gen' +export * from './content.gen' +export type { + CreateSnapshotRequest, + CreateVolumeRequest, + CreateVolumeRequestFromEmpty, + CreateVolumeRequestFromSnapshot, + DeleteSnapshotRequest, + DeleteVolumeRequest, + ExportSnapshotToObjectStorageRequest, + GetSnapshotRequest, + GetVolumeRequest, + ImportSnapshotFromObjectStorageRequest, + ListSnapshotsRequest, + ListSnapshotsRequestOrderBy, + ListSnapshotsResponse, + ListVolumeTypesRequest, + ListVolumeTypesResponse, + ListVolumesRequest, + ListVolumesRequestOrderBy, + ListVolumesResponse, + Reference, + ReferenceStatus, + ReferenceType, + Snapshot, + SnapshotParentVolume, + SnapshotStatus, + StorageClass, + UpdateSnapshotRequest, + UpdateVolumeRequest, + Volume, + VolumeSpecifications, + VolumeStatus, + VolumeType, +} from './types.gen' +export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/block/v1/marshalling.gen.ts b/packages/clients/src/api/block/v1/marshalling.gen.ts new file mode 100644 index 000000000..d9fc607e3 --- /dev/null +++ b/packages/clients/src/api/block/v1/marshalling.gen.ts @@ -0,0 +1,279 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import randomName from '@scaleway/random-name' +import { + isJSONObject, + resolveOneOf, + unmarshalArrayOfObject, + unmarshalDate, + unmarshalMoney, +} from '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + CreateSnapshotRequest, + CreateVolumeRequest, + CreateVolumeRequestFromEmpty, + CreateVolumeRequestFromSnapshot, + ExportSnapshotToObjectStorageRequest, + ImportSnapshotFromObjectStorageRequest, + ListSnapshotsResponse, + ListVolumeTypesResponse, + ListVolumesResponse, + Reference, + Snapshot, + SnapshotParentVolume, + UpdateSnapshotRequest, + UpdateVolumeRequest, + Volume, + VolumeSpecifications, + VolumeType, +} from './types.gen' + +export const unmarshalReference = (data: unknown): Reference => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Reference' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + productResourceId: data.product_resource_id, + productResourceType: data.product_resource_type, + status: data.status, + type: data.type, + } as Reference +} + +const unmarshalSnapshotParentVolume = (data: unknown): SnapshotParentVolume => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SnapshotParentVolume' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + name: data.name, + status: data.status, + type: data.type, + } as SnapshotParentVolume +} + +export const unmarshalSnapshot = (data: unknown): Snapshot => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Snapshot' failed as data isn't a dictionary.`, + ) + } + + return { + class: data.class, + createdAt: unmarshalDate(data.created_at), + id: data.id, + name: data.name, + parentVolume: data.parent_volume + ? unmarshalSnapshotParentVolume(data.parent_volume) + : undefined, + projectId: data.project_id, + references: unmarshalArrayOfObject(data.references, unmarshalReference), + size: data.size, + status: data.status, + tags: data.tags, + updatedAt: unmarshalDate(data.updated_at), + zone: data.zone, + } as Snapshot +} + +const unmarshalVolumeSpecifications = (data: unknown): VolumeSpecifications => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'VolumeSpecifications' failed as data isn't a dictionary.`, + ) + } + + return { + class: data.class, + perfIops: data.perf_iops, + } as VolumeSpecifications +} + +export const unmarshalVolume = (data: unknown): Volume => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Volume' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + lastDetachedAt: unmarshalDate(data.last_detached_at), + name: data.name, + parentSnapshotId: data.parent_snapshot_id, + projectId: data.project_id, + references: unmarshalArrayOfObject(data.references, unmarshalReference), + size: data.size, + specs: data.specs ? unmarshalVolumeSpecifications(data.specs) : undefined, + status: data.status, + tags: data.tags, + type: data.type, + updatedAt: unmarshalDate(data.updated_at), + zone: data.zone, + } as Volume +} + +export const unmarshalListSnapshotsResponse = ( + data: unknown, +): ListSnapshotsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListSnapshotsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + snapshots: unmarshalArrayOfObject(data.snapshots, unmarshalSnapshot), + totalCount: data.total_count, + } as ListSnapshotsResponse +} + +const unmarshalVolumeType = (data: unknown): VolumeType => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'VolumeType' failed as data isn't a dictionary.`, + ) + } + + return { + pricing: data.pricing ? unmarshalMoney(data.pricing) : undefined, + snapshotPricing: data.snapshot_pricing + ? unmarshalMoney(data.snapshot_pricing) + : undefined, + specs: data.specs ? unmarshalVolumeSpecifications(data.specs) : undefined, + type: data.type, + } as VolumeType +} + +export const unmarshalListVolumeTypesResponse = ( + data: unknown, +): ListVolumeTypesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListVolumeTypesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + volumeTypes: unmarshalArrayOfObject(data.volume_types, unmarshalVolumeType), + } as ListVolumeTypesResponse +} + +export const unmarshalListVolumesResponse = ( + data: unknown, +): ListVolumesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListVolumesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + volumes: unmarshalArrayOfObject(data.volumes, unmarshalVolume), + } as ListVolumesResponse +} + +export const marshalCreateSnapshotRequest = ( + request: CreateSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name || randomName('snp'), + project_id: request.projectId ?? defaults.defaultProjectId, + tags: request.tags, + volume_id: request.volumeId, +}) + +const marshalCreateVolumeRequestFromEmpty = ( + request: CreateVolumeRequestFromEmpty, + defaults: DefaultValues, +): Record => ({ + size: request.size, +}) + +const marshalCreateVolumeRequestFromSnapshot = ( + request: CreateVolumeRequestFromSnapshot, + defaults: DefaultValues, +): Record => ({ + size: request.size, + snapshot_id: request.snapshotId, +}) + +export const marshalCreateVolumeRequest = ( + request: CreateVolumeRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name || randomName('vol'), + project_id: request.projectId ?? defaults.defaultProjectId, + tags: request.tags, + ...resolveOneOf([ + { + param: 'from_empty', + value: + request.fromEmpty !== undefined + ? marshalCreateVolumeRequestFromEmpty(request.fromEmpty, defaults) + : undefined, + }, + { + param: 'from_snapshot', + value: + request.fromSnapshot !== undefined + ? marshalCreateVolumeRequestFromSnapshot( + request.fromSnapshot, + defaults, + ) + : undefined, + }, + ]), + ...resolveOneOf([{ param: 'perf_iops', value: request.perfIops }]), +}) + +export const marshalExportSnapshotToObjectStorageRequest = ( + request: ExportSnapshotToObjectStorageRequest, + defaults: DefaultValues, +): Record => ({ + bucket: request.bucket, + key: request.key, +}) + +export const marshalImportSnapshotFromObjectStorageRequest = ( + request: ImportSnapshotFromObjectStorageRequest, + defaults: DefaultValues, +): Record => ({ + bucket: request.bucket, + key: request.key, + name: request.name, + project_id: request.projectId ?? defaults.defaultProjectId, + size: request.size, + tags: request.tags, +}) + +export const marshalUpdateSnapshotRequest = ( + request: UpdateSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + tags: request.tags, +}) + +export const marshalUpdateVolumeRequest = ( + request: UpdateVolumeRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + perf_iops: request.perfIops, + size: request.size, + tags: request.tags, +}) diff --git a/packages/clients/src/api/block/v1/types.gen.ts b/packages/clients/src/api/block/v1/types.gen.ts new file mode 100644 index 000000000..8f9be03a0 --- /dev/null +++ b/packages/clients/src/api/block/v1/types.gen.ts @@ -0,0 +1,407 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { Money, Zone as ScwZone } from '../../../bridge' + +export type ListSnapshotsRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + +export type ListVolumesRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + +export type ReferenceStatus = + | 'unknown_status' + | 'attaching' + | 'attached' + | 'detaching' + | 'detached' + | 'creating' + | 'error' + +export type ReferenceType = 'unknown_type' | 'link' | 'exclusive' | 'read_only' + +export type SnapshotStatus = + | 'unknown_status' + | 'creating' + | 'available' + | 'error' + | 'deleting' + | 'deleted' + | 'in_use' + | 'locked' + | 'exporting' + +export type StorageClass = + | 'unknown_storage_class' + | 'unspecified' + | 'bssd' + | 'sbs' + +export type VolumeStatus = + | 'unknown_status' + | 'creating' + | 'available' + | 'in_use' + | 'deleting' + | 'deleted' + | 'resizing' + | 'error' + | 'snapshotting' + | 'locked' + | 'updating' + +export interface Reference { + /** UUID of the reference. */ + id: string + /** Type of resource to which the reference is associated. */ + productResourceType: string + /** + * UUID of the product resource it refers to (according to the + * product_resource_type). + */ + productResourceId: string + /** Creation date of the reference. */ + createdAt?: Date + /** Type of reference (link, exclusive, read_only). */ + type: ReferenceType + /** + * Status of the reference. Statuses include `attaching`, `attached`, and + * `detaching`. + */ + status: ReferenceStatus +} + +export interface SnapshotParentVolume { + /** Parent volume UUID (volume from which the snapshot originates). */ + id: string + /** Name of the parent volume. */ + name: string + /** Volume type of the parent volume. */ + type: string + /** Current status the parent volume. */ + status: VolumeStatus +} + +export interface VolumeSpecifications { + /** + * The maximum IO/s expected, according to the different options available in + * stock (`5000 | 15000`). + */ + perfIops?: number + /** The storage class of the volume. */ + class: StorageClass +} + +export interface CreateVolumeRequestFromEmpty { + /** Must be compliant with the minimum (1 GB) and maximum (10 TB) allowed size. */ + size: number +} + +export interface CreateVolumeRequestFromSnapshot { + /** + * Must be compliant with the minimum (1 GB) and maximum (10 TB) allowed size. + * Size is optional and is used only if a resize of the volume is requested, + * otherwise original snapshot size will be used. + */ + size?: number + /** Source snapshot from which volume will be created. */ + snapshotId: string +} + +export interface Snapshot { + /** UUID of the snapshot. */ + id: string + /** Name of the snapshot. */ + name: string + /** If the parent volume was deleted, value is null. */ + parentVolume?: SnapshotParentVolume + /** Size in bytes of the snapshot. */ + size: number + /** UUID of the project the snapshot belongs to. */ + projectId: string + /** Creation date of the snapshot. */ + createdAt?: Date + /** Last modification date of the properties of a snapshot. */ + updatedAt?: Date + /** List of the references to the snapshot. */ + references: Reference[] + /** Current status of the snapshot (available, in_use, ...). */ + status: SnapshotStatus + /** List of tags assigned to the volume. */ + tags: string[] + /** Snapshot zone. */ + zone: ScwZone + /** Storage class of the snapshot. */ + class: StorageClass +} + +export interface VolumeType { + /** Volume type. */ + type: string + /** Price of the volume billed in GB/hour. */ + pricing?: Money + /** Price of the snapshot billed in GB/hour. */ + snapshotPricing?: Money + /** Volume specifications of the volume type. */ + specs?: VolumeSpecifications +} + +export interface Volume { + /** UUID of the volume. */ + id: string + /** Name of the volume. */ + name: string + /** Volume type. */ + type: string + /** Volume size in bytes. */ + size: number + /** UUID of the project to which the volume belongs. */ + projectId: string + /** Creation date of the volume. */ + createdAt?: Date + /** Last update of the properties of a volume. */ + updatedAt?: Date + /** List of the references to the volume. */ + references: Reference[] + /** + * When a volume is created from a snapshot, is the UUID of the snapshot from + * which the volume has been created. + */ + parentSnapshotId?: string + /** Current status of the volume (available, in_use, ...). */ + status: VolumeStatus + /** List of tags assigned to the volume. */ + tags: string[] + /** Volume zone. */ + zone: ScwZone + /** Specifications of the volume. */ + specs?: VolumeSpecifications + /** Last time the volume was detached. */ + lastDetachedAt?: Date +} + +export type CreateSnapshotRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the volume to snapshot. */ + volumeId: string + /** Name of the snapshot. */ + name?: string + /** UUID of the project to which the volume and the snapshot belong. */ + projectId?: string + /** List of tags assigned to the snapshot. */ + tags?: string[] +} + +export type CreateVolumeRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** Name of the volume. */ + name?: string + /** + * The maximum IO/s expected, according to the different options available in + * stock (`5000 | 15000`). + * + * One-of ('requirements'): at most one of 'perfIops' could be set. + */ + perfIops?: number + /** UUID of the project the volume belongs to. */ + projectId?: string + /** + * Specify the size of the new volume if creating a new one from scratch. + * + * One-of ('from'): at most one of 'fromEmpty', 'fromSnapshot' could be set. + */ + fromEmpty?: CreateVolumeRequestFromEmpty + /** + * Specify the snapshot ID of the original snapshot. + * + * One-of ('from'): at most one of 'fromEmpty', 'fromSnapshot' could be set. + */ + fromSnapshot?: CreateVolumeRequestFromSnapshot + /** List of tags assigned to the volume. */ + tags?: string[] +} + +export type DeleteSnapshotRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the snapshot. */ + snapshotId: string +} + +export type DeleteVolumeRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the volume. */ + volumeId: string +} + +export type ExportSnapshotToObjectStorageRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the snapshot. */ + snapshotId: string + /** Scaleway Object Storage bucket where the object is stored. */ + bucket: string + /** The object key inside the given bucket. */ + key: string +} + +export type GetSnapshotRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the snapshot. */ + snapshotId: string +} + +export type GetVolumeRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the volume. */ + volumeId: string +} + +export type ImportSnapshotFromObjectStorageRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** Scaleway Object Storage bucket where the object is stored. */ + bucket: string + /** The object key inside the given bucket. */ + key: string + /** Name of the snapshot. */ + name: string + /** UUID of the Project to which the volume and the snapshot belong. */ + projectId?: string + /** List of tags assigned to the snapshot. */ + tags?: string[] + /** Size of the snapshot. */ + size?: number +} + +export type ListSnapshotsRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** Criteria to use when ordering the list. */ + orderBy?: ListSnapshotsRequestOrderBy + /** Filter by Project ID. */ + projectId?: string + /** Filter by Organization ID. */ + organizationId?: string + /** Page number. */ + page?: number + /** + * Page size, defines how many entries are returned in one page, must be lower + * or equal to 100. + */ + pageSize?: number + /** Filter snapshots by the ID of the original volume. */ + volumeId?: string + /** Filter snapshots by their names. */ + name?: string + /** + * Filter by tags. Only snapshots with one or more matching tags will be + * returned. + */ + tags?: string[] +} + +export interface ListSnapshotsResponse { + /** Paginated returned list of snapshots. */ + snapshots: Snapshot[] + /** Total number of snpashots in the project. */ + totalCount: number +} + +export type ListVolumeTypesRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** Page number. */ + page?: number + /** + * Page size, defines how many entries are returned in one page, must be lower + * or equal to 100. + */ + pageSize?: number +} + +export interface ListVolumeTypesResponse { + /** Returns paginated list of volume-types. */ + volumeTypes: VolumeType[] + /** Total number of volume-types currently available in stock. */ + totalCount: number +} + +export type ListVolumesRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** Criteria to use when ordering the list. */ + orderBy?: ListVolumesRequestOrderBy + /** Filter by Project ID. */ + projectId?: string + /** Filter by Organization ID. */ + organizationId?: string + /** Page number. */ + page?: number + /** + * Page size, defines how many entries are returned in one page, must be lower + * or equal to 100. + */ + pageSize?: number + /** Filter the return volumes by their names. */ + name?: string + /** + * Filter by a product resource ID linked to this volume (such as an Instance + * ID). + */ + productResourceId?: string + /** + * Filter by tags. Only volumes with one or more matching tags will be + * returned. + */ + tags?: string[] +} + +export interface ListVolumesResponse { + /** Paginated returned list of volumes. */ + volumes: Volume[] + /** Total number of volumes in the project. */ + totalCount: number +} + +export type UpdateSnapshotRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the snapshot. */ + snapshotId: string + /** When defined, is the name of the snapshot. */ + name?: string + /** List of tags assigned to the snapshot. */ + tags?: string[] +} + +export type UpdateVolumeRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: ScwZone + /** UUID of the volume. */ + volumeId: string + /** When defined, is the new name of the volume. */ + name?: string + /** + * Size in bytes of the volume, with a granularity of 1 GB (10^9 bytes). Must + * be compliant with the minimum (1GB) and maximum (10TB) allowed size. + */ + size?: number + /** List of tags assigned to the volume. */ + tags?: string[] + /** + * The selected value must be available for the volume's current storage + * class. + */ + perfIops?: number +} diff --git a/packages/clients/src/api/block/v1/validation-rules.gen.ts b/packages/clients/src/api/block/v1/validation-rules.gen.ts new file mode 100644 index 000000000..83ad905ae --- /dev/null +++ b/packages/clients/src/api/block/v1/validation-rules.gen.ts @@ -0,0 +1,56 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export const CreateSnapshotRequest = { + name: { + minLength: 1, + }, +} + +export const CreateVolumeRequest = { + name: { + minLength: 1, + }, +} + +export const ImportSnapshotFromObjectStorageRequest = { + name: { + minLength: 1, + }, +} + +export const ListSnapshotsRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + +export const ListVolumeTypesRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + +export const ListVolumesRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + +export const Reference = { + productResourceType: { + minLength: 1, + }, +}