Skip to content

Commit bf3982a

Browse files
authored
feat(instance): add endpoints to attach/detach server volumes (#1001)
1 parent 46619fb commit bf3982a

File tree

4 files changed

+373
-226
lines changed

4 files changed

+373
-226
lines changed

packages/clients/src/api/instance/v1/api.gen.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import type { Zone } from '../../../bridge'
1010
import {
1111
marshalApplyBlockMigrationRequest,
12+
marshalAttachServerVolumeRequest,
1213
marshalCreateImageRequest,
1314
marshalCreateIpRequest,
1415
marshalCreatePlacementGroupRequest,
@@ -18,6 +19,7 @@ import {
1819
marshalCreateServerRequest,
1920
marshalCreateSnapshotRequest,
2021
marshalCreateVolumeRequest,
22+
marshalDetachServerVolumeRequest,
2123
marshalExportSnapshotRequest,
2224
marshalPlanBlockMigrationRequest,
2325
marshalServerActionRequest,
@@ -35,6 +37,7 @@ import {
3537
marshalUpdatePrivateNICRequest,
3638
marshalUpdateServerRequest,
3739
marshalUpdateVolumeRequest,
40+
unmarshalAttachServerVolumeResponse,
3841
unmarshalCreateImageResponse,
3942
unmarshalCreateIpResponse,
4043
unmarshalCreatePlacementGroupResponse,
@@ -44,6 +47,7 @@ import {
4447
unmarshalCreateServerResponse,
4548
unmarshalCreateSnapshotResponse,
4649
unmarshalCreateVolumeResponse,
50+
unmarshalDetachServerVolumeResponse,
4751
unmarshalExportSnapshotResponse,
4852
unmarshalGetBootscriptResponse,
4953
unmarshalGetDashboardResponse,
@@ -91,6 +95,8 @@ import {
9195
} from './marshalling.gen'
9296
import type {
9397
ApplyBlockMigrationRequest,
98+
AttachServerVolumeRequest,
99+
AttachServerVolumeResponse,
94100
CreateImageRequest,
95101
CreateImageResponse,
96102
CreateIpRequest,
@@ -119,6 +125,8 @@ import type {
119125
DeleteServerUserDataRequest,
120126
DeleteSnapshotRequest,
121127
DeleteVolumeRequest,
128+
DetachServerVolumeRequest,
129+
DetachServerVolumeResponse,
122130
ExportSnapshotRequest,
123131
ExportSnapshotResponse,
124132
GetBootscriptRequest,
@@ -526,6 +534,56 @@ export class API extends ParentAPI {
526534
)}/user_data/${validatePathParam('key', request.key)}`,
527535
})
528536

537+
/**
538+
* Attach a volume to a server.
539+
*
540+
* @param request - The request {@link AttachServerVolumeRequest}
541+
* @returns A Promise of AttachServerVolumeResponse
542+
*/
543+
attachServerVolume = (request: Readonly<AttachServerVolumeRequest>) =>
544+
this.client.fetch<AttachServerVolumeResponse>(
545+
{
546+
body: JSON.stringify(
547+
marshalAttachServerVolumeRequest(request, this.client.settings),
548+
),
549+
headers: jsonContentHeaders,
550+
method: 'POST',
551+
path: `/instance/v1/zones/${validatePathParam(
552+
'zone',
553+
request.zone ?? this.client.settings.defaultZone,
554+
)}/servers/${validatePathParam(
555+
'serverId',
556+
request.serverId,
557+
)}/attach-volume`,
558+
},
559+
unmarshalAttachServerVolumeResponse,
560+
)
561+
562+
/**
563+
* Detach a volume from a server.
564+
*
565+
* @param request - The request {@link DetachServerVolumeRequest}
566+
* @returns A Promise of DetachServerVolumeResponse
567+
*/
568+
detachServerVolume = (request: Readonly<DetachServerVolumeRequest>) =>
569+
this.client.fetch<DetachServerVolumeResponse>(
570+
{
571+
body: JSON.stringify(
572+
marshalDetachServerVolumeRequest(request, this.client.settings),
573+
),
574+
headers: jsonContentHeaders,
575+
method: 'POST',
576+
path: `/instance/v1/zones/${validatePathParam(
577+
'zone',
578+
request.zone ?? this.client.settings.defaultZone,
579+
)}/servers/${validatePathParam(
580+
'serverId',
581+
request.serverId,
582+
)}/detach-volume`,
583+
},
584+
unmarshalDetachServerVolumeResponse,
585+
)
586+
529587
protected pageOfListImages = (request: Readonly<ListImagesRequest> = {}) =>
530588
this.client.fetch<ListImagesResponse>(
531589
{

packages/clients/src/api/instance/v1/index.gen.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export * from './content.gen'
55
export type {
66
ApplyBlockMigrationRequest,
77
Arch,
8+
AttachServerVolumeRequest,
9+
AttachServerVolumeRequestVolumeType,
10+
AttachServerVolumeResponse,
811
BootType,
912
Bootscript,
1013
CreateImageRequest,
@@ -36,6 +39,8 @@ export type {
3639
DeleteServerUserDataRequest,
3740
DeleteSnapshotRequest,
3841
DeleteVolumeRequest,
42+
DetachServerVolumeRequest,
43+
DetachServerVolumeResponse,
3944
ExportSnapshotRequest,
4045
ExportSnapshotResponse,
4146
GetBootscriptRequest,

0 commit comments

Comments
 (0)