From 22112cfc45cf94943bcf6223b9c665d394eb73ca Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Fri, 17 Nov 2023 15:28:51 +0000 Subject: [PATCH] feat: update generated APIs --- .../clients/src/api/instance/v1/api.gen.ts | 58 +++ .../clients/src/api/instance/v1/index.gen.ts | 5 + .../src/api/instance/v1/marshalling.gen.ts | 366 ++++++++++-------- .../clients/src/api/instance/v1/types.gen.ts | 170 ++++---- 4 files changed, 373 insertions(+), 226 deletions(-) diff --git a/packages/clients/src/api/instance/v1/api.gen.ts b/packages/clients/src/api/instance/v1/api.gen.ts index a6dec3490..59d97171e 100644 --- a/packages/clients/src/api/instance/v1/api.gen.ts +++ b/packages/clients/src/api/instance/v1/api.gen.ts @@ -9,6 +9,7 @@ import { import type { Zone } from '../../../bridge' import { marshalApplyBlockMigrationRequest, + marshalAttachServerVolumeRequest, marshalCreateImageRequest, marshalCreateIpRequest, marshalCreatePlacementGroupRequest, @@ -18,6 +19,7 @@ import { marshalCreateServerRequest, marshalCreateSnapshotRequest, marshalCreateVolumeRequest, + marshalDetachServerVolumeRequest, marshalExportSnapshotRequest, marshalPlanBlockMigrationRequest, marshalServerActionRequest, @@ -35,6 +37,7 @@ import { marshalUpdatePrivateNICRequest, marshalUpdateServerRequest, marshalUpdateVolumeRequest, + unmarshalAttachServerVolumeResponse, unmarshalCreateImageResponse, unmarshalCreateIpResponse, unmarshalCreatePlacementGroupResponse, @@ -44,6 +47,7 @@ import { unmarshalCreateServerResponse, unmarshalCreateSnapshotResponse, unmarshalCreateVolumeResponse, + unmarshalDetachServerVolumeResponse, unmarshalExportSnapshotResponse, unmarshalGetBootscriptResponse, unmarshalGetDashboardResponse, @@ -91,6 +95,8 @@ import { } from './marshalling.gen' import type { ApplyBlockMigrationRequest, + AttachServerVolumeRequest, + AttachServerVolumeResponse, CreateImageRequest, CreateImageResponse, CreateIpRequest, @@ -119,6 +125,8 @@ import type { DeleteServerUserDataRequest, DeleteSnapshotRequest, DeleteVolumeRequest, + DetachServerVolumeRequest, + DetachServerVolumeResponse, ExportSnapshotRequest, ExportSnapshotResponse, GetBootscriptRequest, @@ -526,6 +534,56 @@ export class API extends ParentAPI { )}/user_data/${validatePathParam('key', request.key)}`, }) + /** + * Attach a volume to a server. + * + * @param request - The request {@link AttachServerVolumeRequest} + * @returns A Promise of AttachServerVolumeResponse + */ + attachServerVolume = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalAttachServerVolumeRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/attach-volume`, + }, + unmarshalAttachServerVolumeResponse, + ) + + /** + * Detach a volume from a server. + * + * @param request - The request {@link DetachServerVolumeRequest} + * @returns A Promise of DetachServerVolumeResponse + */ + detachServerVolume = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalDetachServerVolumeRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/servers/${validatePathParam( + 'serverId', + request.serverId, + )}/detach-volume`, + }, + unmarshalDetachServerVolumeResponse, + ) + protected pageOfListImages = (request: Readonly = {}) => this.client.fetch( { diff --git a/packages/clients/src/api/instance/v1/index.gen.ts b/packages/clients/src/api/instance/v1/index.gen.ts index 44a39ae20..297adaa30 100644 --- a/packages/clients/src/api/instance/v1/index.gen.ts +++ b/packages/clients/src/api/instance/v1/index.gen.ts @@ -5,6 +5,9 @@ export * from './content.gen' export type { ApplyBlockMigrationRequest, Arch, + AttachServerVolumeRequest, + AttachServerVolumeRequestVolumeType, + AttachServerVolumeResponse, BootType, Bootscript, CreateImageRequest, @@ -36,6 +39,8 @@ export type { DeleteServerUserDataRequest, DeleteSnapshotRequest, DeleteVolumeRequest, + DetachServerVolumeRequest, + DetachServerVolumeResponse, ExportSnapshotRequest, ExportSnapshotResponse, GetBootscriptRequest, diff --git a/packages/clients/src/api/instance/v1/marshalling.gen.ts b/packages/clients/src/api/instance/v1/marshalling.gen.ts index 329b7eea7..56c6ea64a 100644 --- a/packages/clients/src/api/instance/v1/marshalling.gen.ts +++ b/packages/clients/src/api/instance/v1/marshalling.gen.ts @@ -11,6 +11,8 @@ import { import type { DefaultValues } from '../../../bridge' import type { ApplyBlockMigrationRequest, + AttachServerVolumeRequest, + AttachServerVolumeResponse, Bootscript, CreateImageRequest, CreateImageResponse, @@ -31,6 +33,8 @@ import type { CreateVolumeRequest, CreateVolumeResponse, Dashboard, + DetachServerVolumeRequest, + DetachServerVolumeResponse, ExportSnapshotRequest, ExportSnapshotResponse, GetBootscriptResponse, @@ -252,54 +256,6 @@ const unmarshalImage = (data: unknown): Image => { } as Image } -export const unmarshalCreateImageResponse = ( - data: unknown, -): CreateImageResponse => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'CreateImageResponse' failed as data isn't a dictionary.`, - ) - } - - return { - image: data.image ? unmarshalImage(data.image) : undefined, - } as CreateImageResponse -} - -const unmarshalIp = (data: unknown): Ip => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'Ip' failed as data isn't a dictionary.`, - ) - } - - return { - address: data.address, - id: data.id, - organization: data.organization, - prefix: data.prefix, - project: data.project, - reverse: data.reverse, - server: data.server ? unmarshalServerSummary(data.server) : undefined, - state: data.state, - tags: data.tags, - type: data.type, - zone: data.zone, - } as Ip -} - -export const unmarshalCreateIpResponse = (data: unknown): CreateIpResponse => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'CreateIpResponse' failed as data isn't a dictionary.`, - ) - } - - return { - ip: data.ip ? unmarshalIp(data.ip) : undefined, - } as CreateIpResponse -} - const unmarshalPlacementGroup = (data: unknown): PlacementGroup => { if (!isJSONObject(data)) { throw new TypeError( @@ -320,117 +276,6 @@ const unmarshalPlacementGroup = (data: unknown): PlacementGroup => { } as PlacementGroup } -export const unmarshalCreatePlacementGroupResponse = ( - data: unknown, -): CreatePlacementGroupResponse => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'CreatePlacementGroupResponse' failed as data isn't a dictionary.`, - ) - } - - return { - placementGroup: data.placement_group - ? unmarshalPlacementGroup(data.placement_group) - : undefined, - } as CreatePlacementGroupResponse -} - -export const unmarshalCreatePrivateNICResponse = ( - data: unknown, -): CreatePrivateNICResponse => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'CreatePrivateNICResponse' failed as data isn't a dictionary.`, - ) - } - - return { - privateNic: data.private_nic - ? unmarshalPrivateNIC(data.private_nic) - : undefined, - } as CreatePrivateNICResponse -} - -const unmarshalSecurityGroup = (data: unknown): SecurityGroup => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'SecurityGroup' failed as data isn't a dictionary.`, - ) - } - - return { - creationDate: unmarshalDate(data.creation_date), - description: data.description, - enableDefaultSecurity: data.enable_default_security, - id: data.id, - inboundDefaultPolicy: data.inbound_default_policy, - modificationDate: unmarshalDate(data.modification_date), - name: data.name, - organization: data.organization, - organizationDefault: data.organization_default, - outboundDefaultPolicy: data.outbound_default_policy, - project: data.project, - projectDefault: data.project_default, - servers: unmarshalArrayOfObject(data.servers, unmarshalServerSummary), - state: data.state, - stateful: data.stateful, - tags: data.tags, - zone: data.zone, - } as SecurityGroup -} - -export const unmarshalCreateSecurityGroupResponse = ( - data: unknown, -): CreateSecurityGroupResponse => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'CreateSecurityGroupResponse' failed as data isn't a dictionary.`, - ) - } - - return { - securityGroup: data.security_group - ? unmarshalSecurityGroup(data.security_group) - : undefined, - } as CreateSecurityGroupResponse -} - -const unmarshalSecurityGroupRule = (data: unknown): SecurityGroupRule => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'SecurityGroupRule' failed as data isn't a dictionary.`, - ) - } - - return { - action: data.action, - destPortFrom: data.dest_port_from, - destPortTo: data.dest_port_to, - direction: data.direction, - editable: data.editable, - id: data.id, - ipRange: data.ip_range, - position: data.position, - protocol: data.protocol, - zone: data.zone, - } as SecurityGroupRule -} - -export const unmarshalCreateSecurityGroupRuleResponse = ( - data: unknown, -): CreateSecurityGroupRuleResponse => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'CreateSecurityGroupRuleResponse' failed as data isn't a dictionary.`, - ) - } - - return { - rule: data.rule ? unmarshalSecurityGroupRule(data.rule) : undefined, - } as CreateSecurityGroupRuleResponse -} - const unmarshalSecurityGroupSummary = (data: unknown): SecurityGroupSummary => { if (!isJSONObject(data)) { throw new TypeError( @@ -584,6 +429,179 @@ const unmarshalServer = (data: unknown): Server => { } as Server } +export const unmarshalAttachServerVolumeResponse = ( + data: unknown, +): AttachServerVolumeResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AttachServerVolumeResponse' failed as data isn't a dictionary.`, + ) + } + + return { + server: data.server ? unmarshalServer(data.server) : undefined, + } as AttachServerVolumeResponse +} + +export const unmarshalCreateImageResponse = ( + data: unknown, +): CreateImageResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CreateImageResponse' failed as data isn't a dictionary.`, + ) + } + + return { + image: data.image ? unmarshalImage(data.image) : undefined, + } as CreateImageResponse +} + +const unmarshalIp = (data: unknown): Ip => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Ip' failed as data isn't a dictionary.`, + ) + } + + return { + address: data.address, + id: data.id, + organization: data.organization, + prefix: data.prefix, + project: data.project, + reverse: data.reverse, + server: data.server ? unmarshalServerSummary(data.server) : undefined, + state: data.state, + tags: data.tags, + type: data.type, + zone: data.zone, + } as Ip +} + +export const unmarshalCreateIpResponse = (data: unknown): CreateIpResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CreateIpResponse' failed as data isn't a dictionary.`, + ) + } + + return { + ip: data.ip ? unmarshalIp(data.ip) : undefined, + } as CreateIpResponse +} + +export const unmarshalCreatePlacementGroupResponse = ( + data: unknown, +): CreatePlacementGroupResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CreatePlacementGroupResponse' failed as data isn't a dictionary.`, + ) + } + + return { + placementGroup: data.placement_group + ? unmarshalPlacementGroup(data.placement_group) + : undefined, + } as CreatePlacementGroupResponse +} + +export const unmarshalCreatePrivateNICResponse = ( + data: unknown, +): CreatePrivateNICResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CreatePrivateNICResponse' failed as data isn't a dictionary.`, + ) + } + + return { + privateNic: data.private_nic + ? unmarshalPrivateNIC(data.private_nic) + : undefined, + } as CreatePrivateNICResponse +} + +const unmarshalSecurityGroup = (data: unknown): SecurityGroup => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SecurityGroup' failed as data isn't a dictionary.`, + ) + } + + return { + creationDate: unmarshalDate(data.creation_date), + description: data.description, + enableDefaultSecurity: data.enable_default_security, + id: data.id, + inboundDefaultPolicy: data.inbound_default_policy, + modificationDate: unmarshalDate(data.modification_date), + name: data.name, + organization: data.organization, + organizationDefault: data.organization_default, + outboundDefaultPolicy: data.outbound_default_policy, + project: data.project, + projectDefault: data.project_default, + servers: unmarshalArrayOfObject(data.servers, unmarshalServerSummary), + state: data.state, + stateful: data.stateful, + tags: data.tags, + zone: data.zone, + } as SecurityGroup +} + +export const unmarshalCreateSecurityGroupResponse = ( + data: unknown, +): CreateSecurityGroupResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CreateSecurityGroupResponse' failed as data isn't a dictionary.`, + ) + } + + return { + securityGroup: data.security_group + ? unmarshalSecurityGroup(data.security_group) + : undefined, + } as CreateSecurityGroupResponse +} + +const unmarshalSecurityGroupRule = (data: unknown): SecurityGroupRule => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SecurityGroupRule' failed as data isn't a dictionary.`, + ) + } + + return { + action: data.action, + destPortFrom: data.dest_port_from, + destPortTo: data.dest_port_to, + direction: data.direction, + editable: data.editable, + id: data.id, + ipRange: data.ip_range, + position: data.position, + protocol: data.protocol, + zone: data.zone, + } as SecurityGroupRule +} + +export const unmarshalCreateSecurityGroupRuleResponse = ( + data: unknown, +): CreateSecurityGroupRuleResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'CreateSecurityGroupRuleResponse' failed as data isn't a dictionary.`, + ) + } + + return { + rule: data.rule ? unmarshalSecurityGroupRule(data.rule) : undefined, + } as CreateSecurityGroupRuleResponse +} + export const unmarshalCreateServerResponse = ( data: unknown, ): CreateServerResponse => { @@ -686,6 +704,20 @@ export const unmarshalCreateVolumeResponse = ( } as CreateVolumeResponse } +export const unmarshalDetachServerVolumeResponse = ( + data: unknown, +): DetachServerVolumeResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DetachServerVolumeResponse' failed as data isn't a dictionary.`, + ) + } + + return { + server: data.server ? unmarshalServer(data.server) : undefined, + } as DetachServerVolumeResponse +} + export const unmarshalExportSnapshotResponse = ( data: unknown, ): ExportSnapshotResponse => { @@ -1546,6 +1578,15 @@ export const marshalApplyBlockMigrationRequest = ( ]), }) +export const marshalAttachServerVolumeRequest = ( + request: AttachServerVolumeRequest, + defaults: DefaultValues, +): Record => ({ + boot: request.boot, + volume_id: request.volumeId, + volume_type: request.volumeType, +}) + const marshalVolumeTemplate = ( request: VolumeTemplate, defaults: DefaultValues, @@ -1795,6 +1836,13 @@ export const marshalCreateVolumeRequest = ( ]), }) +export const marshalDetachServerVolumeRequest = ( + request: DetachServerVolumeRequest, + defaults: DefaultValues, +): Record => ({ + volume_id: request.volumeId, +}) + export const marshalExportSnapshotRequest = ( request: ExportSnapshotRequest, 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 0868751b1..f71c8ce26 100644 --- a/packages/clients/src/api/instance/v1/types.gen.ts +++ b/packages/clients/src/api/instance/v1/types.gen.ts @@ -4,6 +4,12 @@ import type { Zone } from '../../../bridge' export type Arch = 'x86_64' | 'arm' | 'arm64' +export type AttachServerVolumeRequestVolumeType = + | 'unknown_volume_type' + | 'l_ssd' + | 'b_ssd' + | 'sbs_volume' + export type BootType = 'local' | 'bootscript' | 'rescue' export type ImageState = 'available' | 'creating' | 'error' @@ -369,6 +375,73 @@ export interface VolumeTypeConstraints { max: number } +export interface Server { + /** Instance unique ID. */ + id: string + /** Instance name. */ + name: string + /** Instance Organization ID. */ + organization: string + /** Instance Project ID. */ + project: string + /** List of allowed actions on the Instance. */ + allowedActions: ServerAction[] + /** Tags associated with the Instance. */ + tags: string[] + /** Instance commercial type (eg. GP1-M). */ + commercialType: string + /** Instance creation date. */ + creationDate?: Date + /** True if a dynamic IPv4 is required. */ + dynamicIpRequired: boolean + /** True to configure the instance so it uses the new routed IP mode. */ + routedIpEnabled: boolean + /** True if IPv6 is enabled. */ + enableIpv6: boolean + /** Instance host name. */ + hostname: string + /** Information about the Instance image. */ + image?: Image + /** Defines whether the Instance protection option is activated. */ + protected: boolean + /** Private IP address of the Instance. */ + privateIp?: string + /** Information about the public IP. */ + publicIp?: ServerIp + /** Information about all the public IPs attached to the server. */ + publicIps: ServerIp[] + /** The server's MAC address. */ + macAddress: string + /** Instance modification date. */ + modificationDate?: Date + /** Instance state. */ + state: ServerState + /** Instance location. */ + location?: ServerLocation + /** Instance IPv6 address. */ + ipv6?: ServerIpv6 + /** @deprecated Instance bootscript. */ + bootscript?: Bootscript + /** Instance boot type. */ + bootType: BootType + /** Instance volumes. */ + volumes: Record + /** Instance security group. */ + securityGroup?: SecurityGroupSummary + /** Instance planned maintenance. */ + maintenances: ServerMaintenance[] + /** Detailed information about the Instance state. */ + stateDetail: string + /** Instance architecture. */ + arch: Arch + /** Instance placement group. */ + placementGroup?: PlacementGroup + /** Instance private NICs. */ + privateNics: PrivateNIC[] + /** Zone in which the Instance is located. */ + zone: Zone +} + export interface VolumeTemplate { /** UUID of the volume. */ id: string @@ -485,73 +558,6 @@ export interface VolumeServerTemplate { project?: string } -export interface Server { - /** Instance unique ID. */ - id: string - /** Instance name. */ - name: string - /** Instance Organization ID. */ - organization: string - /** Instance Project ID. */ - project: string - /** List of allowed actions on the Instance. */ - allowedActions: ServerAction[] - /** Tags associated with the Instance. */ - tags: string[] - /** Instance commercial type (eg. GP1-M). */ - commercialType: string - /** Instance creation date. */ - creationDate?: Date - /** True if a dynamic IPv4 is required. */ - dynamicIpRequired: boolean - /** True to configure the instance so it uses the new routed IP mode. */ - routedIpEnabled: boolean - /** True if IPv6 is enabled. */ - enableIpv6: boolean - /** Instance host name. */ - hostname: string - /** Information about the Instance image. */ - image?: Image - /** Defines whether the Instance protection option is activated. */ - protected: boolean - /** Private IP address of the Instance. */ - privateIp?: string - /** Information about the public IP. */ - publicIp?: ServerIp - /** Information about all the public IPs attached to the server. */ - publicIps: ServerIp[] - /** The server's MAC address. */ - macAddress: string - /** Instance modification date. */ - modificationDate?: Date - /** Instance state. */ - state: ServerState - /** Instance location. */ - location?: ServerLocation - /** Instance IPv6 address. */ - ipv6?: ServerIpv6 - /** @deprecated Instance bootscript. */ - bootscript?: Bootscript - /** Instance boot type. */ - bootType: BootType - /** Instance volumes. */ - volumes: Record - /** Instance security group. */ - securityGroup?: SecurityGroupSummary - /** Instance planned maintenance. */ - maintenances: ServerMaintenance[] - /** Detailed information about the Instance state. */ - stateDetail: string - /** Instance architecture. */ - arch: Arch - /** Instance placement group. */ - placementGroup?: PlacementGroup - /** Instance private NICs. */ - privateNics: PrivateNIC[] - /** Zone in which the Instance is located. */ - zone: Zone -} - export interface Snapshot { /** Snapshot ID. */ id: string @@ -742,6 +748,23 @@ export type ApplyBlockMigrationRequest = { validationKey: string } +export type AttachServerVolumeRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the Instance. */ + serverId: string + /** UUID of the Volume to attach. */ + volumeId: string + /** Type of the volume to attach. */ + volumeType?: AttachServerVolumeRequestVolumeType + /** Force the Instance to boot on this volume. */ + boot?: boolean +} + +export interface AttachServerVolumeResponse { + server?: Server +} + export type CreateImageRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone @@ -1150,6 +1173,19 @@ export type DeleteVolumeRequest = { volumeId: string } +export type DetachServerVolumeRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the Instance. */ + serverId: string + /** UUID of the Volume to detach. */ + volumeId: string +} + +export interface DetachServerVolumeResponse { + server?: Server +} + export type ExportSnapshotRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone