Skip to content

Commit f849b3e

Browse files
feat(instance): add compatible types endpoint and end_of_service flag in ServerType (#1835)
Co-authored-by: Rémy Léone <[email protected]>
1 parent e511673 commit f849b3e

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
unmarshalMigrationPlan,
8383
unmarshalPrivateNIC,
8484
unmarshalServerActionResponse,
85+
unmarshalServerCompatibleTypes,
8586
unmarshalSetImageResponse,
8687
unmarshalSetPlacementGroupResponse,
8788
unmarshalSetPlacementGroupServersResponse,
@@ -153,6 +154,7 @@ import type {
153154
GetSecurityGroupResponse,
154155
GetSecurityGroupRuleRequest,
155156
GetSecurityGroupRuleResponse,
157+
GetServerCompatibleTypesRequest,
156158
GetServerRequest,
157159
GetServerResponse,
158160
GetServerTypesAvailabilityRequest,
@@ -193,6 +195,7 @@ import type {
193195
PrivateNIC,
194196
ServerActionRequest,
195197
ServerActionResponse,
198+
ServerCompatibleTypes,
196199
SetImageRequest,
197200
SetPlacementGroupRequest,
198201
SetPlacementGroupResponse,
@@ -512,6 +515,28 @@ export class API extends ParentAPI {
512515
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/user_data/${validatePathParam('key', request.key)}`,
513516
})
514517

518+
/**
519+
* Get Instance compatible types. Get compatible commercial types that can be
520+
* used to update the Instance. The compatibility of an Instance offer is
521+
* based on: the CPU architecture the OS type the required l_ssd storage size
522+
* the required scratch storage size If the specified Instance offer is
523+
* flagged as end of service, the best compatible offer is the first
524+
* returned.
525+
*
526+
* @param request - The request {@link GetServerCompatibleTypesRequest}
527+
* @returns A Promise of ServerCompatibleTypes
528+
*/
529+
getServerCompatibleTypes = (
530+
request: Readonly<GetServerCompatibleTypesRequest>,
531+
) =>
532+
this.client.fetch<ServerCompatibleTypes>(
533+
{
534+
method: 'GET',
535+
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/compatible-types`,
536+
},
537+
unmarshalServerCompatibleTypes,
538+
)
539+
515540
attachServerVolume = (request: Readonly<AttachServerVolumeRequest>) =>
516541
this.client.fetch<AttachServerVolumeResponse>(
517542
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type {
6060
GetSecurityGroupResponse,
6161
GetSecurityGroupRuleRequest,
6262
GetSecurityGroupRuleResponse,
63+
GetServerCompatibleTypesRequest,
6364
GetServerRequest,
6465
GetServerResponse,
6566
GetServerTypesAvailabilityRequest,
@@ -124,6 +125,7 @@ export type {
124125
ServerActionRequest,
125126
ServerActionRequestVolumeBackupTemplate,
126127
ServerActionResponse,
128+
ServerCompatibleTypes,
127129
ServerIp,
128130
ServerIpIpFamily,
129131
ServerIpProvisioningMode,

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import type {
7979
ServerActionRequest,
8080
ServerActionRequestVolumeBackupTemplate,
8181
ServerActionResponse,
82+
ServerCompatibleTypes,
8283
ServerIp,
8384
ServerIpv6,
8485
ServerLocation,
@@ -1204,6 +1205,7 @@ const unmarshalServerType = (data: unknown): ServerType => {
12041205
capabilities: data.capabilities
12051206
? unmarshalServerTypeCapabilities(data.capabilities)
12061207
: undefined,
1208+
endOfService: data.end_of_service,
12071209
gpu: data.gpu,
12081210
hourlyPrice: data.hourly_price,
12091211
monthlyPrice: data.monthly_price,
@@ -1357,6 +1359,20 @@ export const unmarshalServerActionResponse = (
13571359
} as ServerActionResponse
13581360
}
13591361

1362+
export const unmarshalServerCompatibleTypes = (
1363+
data: unknown,
1364+
): ServerCompatibleTypes => {
1365+
if (!isJSONObject(data)) {
1366+
throw new TypeError(
1367+
`Unmarshalling the type 'ServerCompatibleTypes' failed as data isn't a dictionary.`,
1368+
)
1369+
}
1370+
1371+
return {
1372+
compatibleTypes: data.compatible_types,
1373+
} as ServerCompatibleTypes
1374+
}
1375+
13601376
export const unmarshalSetImageResponse = (data: unknown): SetImageResponse => {
13611377
if (!isJSONObject(data)) {
13621378
throw new TypeError(

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ export interface ServerType {
696696
* second).
697697
*/
698698
blockBandwidth?: number
699+
/** True if this Instance type has reached end of service. */
700+
endOfService: boolean
699701
}
700702

701703
export interface VolumeType {
@@ -1335,6 +1337,13 @@ export interface GetSecurityGroupRuleResponse {
13351337
rule?: SecurityGroupRule
13361338
}
13371339

1340+
export type GetServerCompatibleTypesRequest = {
1341+
/** Zone to target. If none is passed will use default zone from the config. */
1342+
zone?: ScwZone
1343+
/** UUID of the Instance you want to get. */
1344+
serverId: string
1345+
}
1346+
13381347
export type GetServerRequest = {
13391348
/** Zone to target. If none is passed will use default zone from the config. */
13401349
zone?: ScwZone
@@ -1787,6 +1796,11 @@ export interface ServerActionResponse {
17871796
task?: Task
17881797
}
17891798

1799+
export interface ServerCompatibleTypes {
1800+
/** Instance compatible types. */
1801+
compatibleTypes: string[]
1802+
}
1803+
17901804
export type SetImageRequest = {
17911805
/** Zone to target. If none is passed will use default zone from the config. */
17921806
zone?: ScwZone

0 commit comments

Comments
 (0)