diff --git a/src/api.ts b/src/api.ts index df54aa1..842e476 100644 --- a/src/api.ts +++ b/src/api.ts @@ -140,6 +140,14 @@ interface InstanceStopOptions { instanceId: string; } +interface InstanceBootOptions { + snapshotId: string; + vcpus?: number; + memory?: number; + diskSize?: number; + metadata?: Record; +} + interface SyncOptions { delete?: boolean; dryRun?: boolean; @@ -413,6 +421,11 @@ class Instance { await this.refresh(); } + async reboot(): Promise { + await this.client.POST(`/instance/${this.id}/reboot`); + await this.refresh(); + } + async setMetadata(metadata: Record): Promise { await this.client.POST(`/instance/${this.id}/metadata`, {}, metadata); await this.refresh(); @@ -1255,6 +1268,28 @@ class MorphCloudClient { stop: async (options: InstanceStopOptions): Promise => { await this.DELETE(`/instance/${options.instanceId}`); }, + + boot: async (options: InstanceBootOptions): Promise => { + const { snapshotId, vcpus, memory, diskSize, metadata } = options; + + // Build request body + const body: any = {}; + if (vcpus !== undefined) { + body.vcpus = vcpus; + } + if (memory !== undefined) { + body.memory = memory; + } + if (diskSize !== undefined) { + body.disk_size = diskSize; + } + if (metadata) { + body.metadata = metadata; + } + + const response = await this.POST(`/snapshot/${snapshotId}/boot`, {}, body); + return new Instance(response, this); + }, }; } @@ -1279,4 +1314,5 @@ export type { InstanceSnapshotOptions, InstanceGetOptions, InstanceStopOptions, + InstanceBootOptions, };