Skip to content

Commit efd2051

Browse files
authored
feat: add support for updating hibernation timeout (#31)
1 parent 6cd070e commit efd2051

File tree

5 files changed

+260
-7
lines changed

5 files changed

+260
-7
lines changed

openapi.json

Lines changed: 136 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,57 @@
747747
],
748748
"title": "VMStartResponse"
749749
},
750+
"VMUpdateHibernationTimeoutRequest": {
751+
"properties": {
752+
"hibernation_timeout_seconds": {
753+
"description": "The new hibernation timeout in seconds.\n\nMust be greater than 0 and less than or equal to 86400 (24 hours).\n",
754+
"example": 300,
755+
"maximum": 86400,
756+
"minimum": 1,
757+
"type": "integer"
758+
}
759+
},
760+
"required": ["hibernation_timeout_seconds"],
761+
"title": "VMUpdateHibernationTimeoutRequest",
762+
"type": "object"
763+
},
764+
"VMUpdateHibernationTimeoutResponse": {
765+
"allOf": [
766+
{
767+
"properties": {
768+
"errors": {
769+
"items": [
770+
{
771+
"oneOf": [
772+
{ "type": "string" },
773+
{ "additionalProperties": true, "type": "object" }
774+
],
775+
"title": "Error"
776+
}
777+
],
778+
"type": "array"
779+
},
780+
"success": { "type": "boolean" }
781+
},
782+
"title": "Response",
783+
"type": "object"
784+
},
785+
{
786+
"properties": {
787+
"data": {
788+
"properties": {
789+
"hibernation_timeout_seconds": { "type": "integer" },
790+
"id": { "type": "string" }
791+
},
792+
"required": ["id", "hibernation_timeout_seconds"],
793+
"type": "object"
794+
}
795+
},
796+
"type": "object"
797+
}
798+
],
799+
"title": "VMUpdateHibernationTimeoutResponse"
800+
},
750801
"VMUpdateSpecsRequest": {
751802
"properties": {
752803
"tier": {
@@ -1181,6 +1232,49 @@
11811232
"tags": ["vm"]
11821233
}
11831234
},
1235+
"/vm/{id}/hibernation_timeout": {
1236+
"put": {
1237+
"callbacks": {},
1238+
"description": "Updates the hibernation timeout of a running VM.\n\nThis endpoint can only be used on VMs that belong to your team's workspace.\nThe new timeout must be greater than 0 and less than or equal to 86400 seconds (24 hours).\n",
1239+
"operationId": "vm/update_hibernation_timeout",
1240+
"parameters": [
1241+
{
1242+
"description": "Sandbox ID",
1243+
"example": "new",
1244+
"in": "path",
1245+
"name": "id",
1246+
"required": true,
1247+
"schema": { "type": "string" }
1248+
}
1249+
],
1250+
"requestBody": {
1251+
"content": {
1252+
"application/json": {
1253+
"schema": {
1254+
"$ref": "#/components/schemas/VMUpdateHibernationTimeoutRequest"
1255+
}
1256+
}
1257+
},
1258+
"description": "VM Update Hibernation Timeout Request",
1259+
"required": false
1260+
},
1261+
"responses": {
1262+
"200": {
1263+
"content": {
1264+
"application/json": {
1265+
"schema": {
1266+
"$ref": "#/components/schemas/VMUpdateHibernationTimeoutResponse"
1267+
}
1268+
}
1269+
},
1270+
"description": "VM Update Hibernation Timeout Response"
1271+
}
1272+
},
1273+
"security": [{ "authorization": ["vm:manage"] }],
1274+
"summary": "Update VM Hibernation Timeout",
1275+
"tags": ["vm"]
1276+
}
1277+
},
11841278
"/vm/{id}/shutdown": {
11851279
"post": {
11861280
"callbacks": {},
@@ -1220,6 +1314,47 @@
12201314
"tags": ["vm"]
12211315
}
12221316
},
1317+
"/vm/{id}/specs": {
1318+
"put": {
1319+
"callbacks": {},
1320+
"description": "Updates the specifications (CPU, memory, storage) of a running VM.\n\nThis endpoint can only be used on VMs that belong to your team's workspace.\nThe new tier must not exceed your team's maximum allowed tier.\n",
1321+
"operationId": "vm/update_specs",
1322+
"parameters": [
1323+
{
1324+
"description": "Sandbox ID",
1325+
"example": "new",
1326+
"in": "path",
1327+
"name": "id",
1328+
"required": true,
1329+
"schema": { "type": "string" }
1330+
}
1331+
],
1332+
"requestBody": {
1333+
"content": {
1334+
"application/json": {
1335+
"schema": { "$ref": "#/components/schemas/VMUpdateSpecsRequest" }
1336+
}
1337+
},
1338+
"description": "VM Update Specs Request",
1339+
"required": false
1340+
},
1341+
"responses": {
1342+
"200": {
1343+
"content": {
1344+
"application/json": {
1345+
"schema": {
1346+
"$ref": "#/components/schemas/VMUpdateSpecsResponse"
1347+
}
1348+
}
1349+
},
1350+
"description": "VM Update Specs Response"
1351+
}
1352+
},
1353+
"security": [{ "authorization": ["vm:manage"] }],
1354+
"summary": "Update VM Specs",
1355+
"tags": ["vm"]
1356+
}
1357+
},
12231358
"/vm/{id}/start": {
12241359
"post": {
12251360
"callbacks": {},
@@ -1263,7 +1398,7 @@
12631398
"post": {
12641399
"callbacks": {},
12651400
"description": "Updates the specifications (CPU, memory, storage) of a running VM.\n\nThis endpoint can only be used on VMs that belong to your team's workspace.\nThe new tier must not exceed your team's maximum allowed tier.\n",
1266-
"operationId": "vm/update_specs",
1401+
"operationId": "vm/update_specs (2)",
12671402
"parameters": [
12681403
{
12691404
"description": "Sandbox ID",

src/client/sdk.gen.ts

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
import { createClient, createConfig, type OptionsLegacyParser } from '@hey-api/client-fetch';
4-
import type { MetaInfoError, MetaInfoResponse, WorkspaceCreateData, WorkspaceCreateError, WorkspaceCreateResponse2, TokenCreateData, TokenCreateError, TokenCreateResponse2, TokenUpdateData, TokenUpdateError, TokenUpdateResponse2, SandboxListData, SandboxListError, SandboxListResponse2, SandboxCreateData, SandboxCreateError, SandboxCreateResponse2, SandboxGetData, SandboxGetError, SandboxGetResponse2, SandboxForkData, SandboxForkError, SandboxForkResponse2, VmHibernateData, VmHibernateError, VmHibernateResponse, VmShutdownData, VmShutdownError, VmShutdownResponse, VmStartData, VmStartError, VmStartResponse, VmUpdateSpecsData, VmUpdateSpecsError, VmUpdateSpecsResponse } from './types.gen';
4+
import type { MetaInfoError, MetaInfoResponse, WorkspaceCreateData, WorkspaceCreateError, WorkspaceCreateResponse2, TokenCreateData, TokenCreateError, TokenCreateResponse2, TokenUpdateData, TokenUpdateError, TokenUpdateResponse2, SandboxListData, SandboxListError, SandboxListResponse2, SandboxCreateData, SandboxCreateError, SandboxCreateResponse2, SandboxGetData, SandboxGetError, SandboxGetResponse2, SandboxForkData, SandboxForkError, SandboxForkResponse2, VmHibernateData, VmHibernateError, VmHibernateResponse, VmUpdateHibernationTimeoutData, VmUpdateHibernationTimeoutError, VmUpdateHibernationTimeoutResponse, VmShutdownData, VmShutdownError, VmShutdownResponse, VmUpdateSpecsData, VmUpdateSpecsError, VmUpdateSpecsResponse, VmStartData, VmStartError, VmStartResponse, VmUpdateSpecs2Data, VmUpdateSpecs2Error, VmUpdateSpecs2Response } from './types.gen';
55

66
export const client = createClient(createConfig());
77

@@ -118,6 +118,21 @@ export const vmHibernate = <ThrowOnError extends boolean = false>(options: Optio
118118
});
119119
};
120120

121+
/**
122+
* Update VM Hibernation Timeout
123+
* Updates the hibernation timeout of a running VM.
124+
*
125+
* This endpoint can only be used on VMs that belong to your team's workspace.
126+
* The new timeout must be greater than 0 and less than or equal to 86400 seconds (24 hours).
127+
*
128+
*/
129+
export const vmUpdateHibernationTimeout = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<VmUpdateHibernationTimeoutData, ThrowOnError>) => {
130+
return (options?.client ?? client).put<VmUpdateHibernationTimeoutResponse, VmUpdateHibernationTimeoutError, ThrowOnError>({
131+
...options,
132+
url: '/vm/{id}/hibernation_timeout'
133+
});
134+
};
135+
121136
/**
122137
* Shutdown a VM
123138
* Stops a running VM, ending all currently running processes
@@ -135,6 +150,21 @@ export const vmShutdown = <ThrowOnError extends boolean = false>(options: Option
135150
});
136151
};
137152

153+
/**
154+
* Update VM Specs
155+
* Updates the specifications (CPU, memory, storage) of a running VM.
156+
*
157+
* This endpoint can only be used on VMs that belong to your team's workspace.
158+
* The new tier must not exceed your team's maximum allowed tier.
159+
*
160+
*/
161+
export const vmUpdateSpecs = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<VmUpdateSpecsData, ThrowOnError>) => {
162+
return (options?.client ?? client).put<VmUpdateSpecsResponse, VmUpdateSpecsError, ThrowOnError>({
163+
...options,
164+
url: '/vm/{id}/specs'
165+
});
166+
};
167+
138168
/**
139169
* Start a VM
140170
* Start a virtual machine for the sandbox (devbox) with the given ID
@@ -162,8 +192,8 @@ export const vmStart = <ThrowOnError extends boolean = false>(options: OptionsLe
162192
* The new tier must not exceed your team's maximum allowed tier.
163193
*
164194
*/
165-
export const vmUpdateSpecs = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<VmUpdateSpecsData, ThrowOnError>) => {
166-
return (options?.client ?? client).post<VmUpdateSpecsResponse, VmUpdateSpecsError, ThrowOnError>({
195+
export const vmUpdateSpecs2 = <ThrowOnError extends boolean = false>(options: OptionsLegacyParser<VmUpdateSpecs2Data, ThrowOnError>) => {
196+
return (options?.client ?? client).post<VmUpdateSpecs2Response, VmUpdateSpecs2Error, ThrowOnError>({
167197
...options,
168198
url: '/vm/{id}/update_specs'
169199
});

src/client/types.gen.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,28 @@ export type VMStartResponse = {
390390
};
391391
};
392392

393+
export type VMUpdateHibernationTimeoutRequest = {
394+
/**
395+
* The new hibernation timeout in seconds.
396+
*
397+
* Must be greater than 0 and less than or equal to 86400 (24 hours).
398+
*
399+
*/
400+
hibernation_timeout_seconds: number;
401+
};
402+
403+
export type VMUpdateHibernationTimeoutResponse = {
404+
errors?: Array<((string | {
405+
[key: string]: unknown;
406+
}))>;
407+
success?: boolean;
408+
} & {
409+
data?: {
410+
hibernation_timeout_seconds: number;
411+
id: string;
412+
};
413+
};
414+
393415
export type VMUpdateSpecsRequest = {
394416
/**
395417
* Determines which specs to update the VM with.
@@ -555,6 +577,23 @@ export type VmHibernateResponse = (VMHibernateResponse);
555577

556578
export type VmHibernateError = unknown;
557579

580+
export type VmUpdateHibernationTimeoutData = {
581+
/**
582+
* VM Update Hibernation Timeout Request
583+
*/
584+
body?: VMUpdateHibernationTimeoutRequest;
585+
path: {
586+
/**
587+
* Sandbox ID
588+
*/
589+
id: string;
590+
};
591+
};
592+
593+
export type VmUpdateHibernationTimeoutResponse = (VMUpdateHibernationTimeoutResponse);
594+
595+
export type VmUpdateHibernationTimeoutError = unknown;
596+
558597
export type VmShutdownData = {
559598
/**
560599
* VM Shutdown Request
@@ -572,6 +611,23 @@ export type VmShutdownResponse = (VMShutdownResponse);
572611

573612
export type VmShutdownError = unknown;
574613

614+
export type VmUpdateSpecsData = {
615+
/**
616+
* VM Update Specs Request
617+
*/
618+
body?: VMUpdateSpecsRequest;
619+
path: {
620+
/**
621+
* Sandbox ID
622+
*/
623+
id: string;
624+
};
625+
};
626+
627+
export type VmUpdateSpecsResponse = (VMUpdateSpecsResponse);
628+
629+
export type VmUpdateSpecsError = unknown;
630+
575631
export type VmStartData = {
576632
/**
577633
* VM Start Request
@@ -589,7 +645,7 @@ export type VmStartResponse = (VMStartResponse);
589645

590646
export type VmStartError = unknown;
591647

592-
export type VmUpdateSpecsData = {
648+
export type VmUpdateSpecs2Data = {
593649
/**
594650
* VM Update Specs Request
595651
*/
@@ -602,6 +658,6 @@ export type VmUpdateSpecsData = {
602658
};
603659
};
604660

605-
export type VmUpdateSpecsResponse = (VMUpdateSpecsResponse);
661+
export type VmUpdateSpecs2Response = (VMUpdateSpecsResponse);
606662

607-
export type VmUpdateSpecsError = unknown;
663+
export type VmUpdateSpecs2Error = unknown;

src/sandbox-client.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
vmHibernate,
88
vmShutdown,
99
vmStart,
10+
vmUpdateHibernationTimeout,
1011
vmUpdateSpecs,
1112
} from "./client";
1213
import { Sandbox } from "./sandbox";
@@ -371,6 +372,28 @@ export class SandboxClient {
371372
handleResponse(response, `Failed to update sandbox tier ${id}`);
372373
}
373374

375+
/**
376+
* Updates the hibernation timeout of a sandbox.
377+
*
378+
* @param id The ID of the sandbox to update
379+
* @param timeoutSeconds The new hibernation timeout in seconds
380+
*/
381+
async updateHibernationTimeout(
382+
id: string,
383+
timeoutSeconds: number
384+
): Promise<void> {
385+
const response = await vmUpdateHibernationTimeout({
386+
client: this.apiClient,
387+
path: { id },
388+
body: { hibernation_timeout_seconds: timeoutSeconds },
389+
});
390+
391+
handleResponse(
392+
response,
393+
`Failed to update hibernation timeout for sandbox ${id}`
394+
);
395+
}
396+
374397
private async connectToSandbox(
375398
id: string,
376399
startVm: () => Promise<

src/sandbox.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,13 @@ export class Sandbox extends SandboxWithoutClient {
245245
public async updateTier(tier: VMTier): Promise<void> {
246246
await this.sandboxClient.updateTier(this.id, tier);
247247
}
248+
249+
/**
250+
* Updates the hibernation timeout of a sandbox.
251+
*
252+
* @param timeoutSeconds The new hibernation timeout in seconds
253+
*/
254+
public async updateHibernationTimeout(timeoutSeconds: number): Promise<void> {
255+
await this.sandboxClient.updateHibernationTimeout(this.id, timeoutSeconds);
256+
}
248257
}

0 commit comments

Comments
 (0)