Skip to content

Commit 09a28d5

Browse files
feat: Model template as an instance state instead of a separate registry
1 parent 9f2da88 commit 09a28d5

4 files changed

Lines changed: 100 additions & 8 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 52
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/hypeman-0aececd4fa79c47cb7222167d6746064c53b69eb70ee14252be71ccc31e6d2a2.yml
3-
openapi_spec_hash: c514624af74c74835e3187b857184ff2
4-
config_hash: ed668fae8826ff533f38df16c9664f44
1+
configured_endpoints: 54
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel/hypeman-48b300e51c488f55e3f36024515bdb78a8fa5fe44c6fbde99d3f8a34c16df1cb.yml
3+
openapi_spec_hash: 1b53b5b26006f74ccbbb8facc57a9d44
4+
config_hash: dfacce742631adb22616891760f57888

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ Methods:
5454
- <code title="patch /instances/{id}">client.instances.<a href="./src/resources/instances/instances.ts">update</a>(id, { ...params }) -> Instance</code>
5555
- <code title="get /instances">client.instances.<a href="./src/resources/instances/instances.ts">list</a>({ ...params }) -> InstanceListResponse</code>
5656
- <code title="delete /instances/{id}">client.instances.<a href="./src/resources/instances/instances.ts">delete</a>(id) -> void</code>
57+
- <code title="post /instances/{id}/demote-template">client.instances.<a href="./src/resources/instances/instances.ts">demoteTemplate</a>(id) -> Instance</code>
5758
- <code title="post /instances/{id}/fork">client.instances.<a href="./src/resources/instances/instances.ts">fork</a>(id, { ...params }) -> Instance</code>
5859
- <code title="get /instances/{id}">client.instances.<a href="./src/resources/instances/instances.ts">get</a>(id) -> Instance</code>
5960
- <code title="get /instances/{id}/logs">client.instances.<a href="./src/resources/instances/instances.ts">logs</a>(id, { ...params }) -> string</code>
61+
- <code title="post /instances/{id}/promote-template">client.instances.<a href="./src/resources/instances/instances.ts">promoteTemplate</a>(id) -> Instance</code>
6062
- <code title="post /instances/{id}/restore">client.instances.<a href="./src/resources/instances/instances.ts">restore</a>(id) -> Instance</code>
6163
- <code title="post /instances/{id}/standby">client.instances.<a href="./src/resources/instances/instances.ts">standby</a>(id, { ...params }) -> Instance</code>
6264
- <code title="post /instances/{id}/start">client.instances.<a href="./src/resources/instances/instances.ts">start</a>(id, { ...params }) -> Instance</code>

src/resources/instances/instances.ts

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ export class Instances extends APIResource {
8383
});
8484
}
8585

86+
/**
87+
* Demote a template back to standby so it can be restored or deleted
88+
*
89+
* @example
90+
* ```ts
91+
* const instance = await client.instances.demoteTemplate(
92+
* 'id',
93+
* );
94+
* ```
95+
*/
96+
demoteTemplate(id: string, options?: RequestOptions): APIPromise<Instance> {
97+
return this._client.post(path`/instances/${id}/demote-template`, options);
98+
}
99+
86100
/**
87101
* Fork an instance from stopped, standby, or running (with from_running=true)
88102
*
@@ -138,6 +152,20 @@ export class Instances extends APIResource {
138152
}) as APIPromise<Stream<InstanceLogsResponse>>;
139153
}
140154

155+
/**
156+
* Promote a standby instance into a fork-only template
157+
*
158+
* @example
159+
* ```ts
160+
* const instance = await client.instances.promoteTemplate(
161+
* 'id',
162+
* );
163+
* ```
164+
*/
165+
promoteTemplate(id: string, options?: RequestOptions): APIPromise<Instance> {
166+
return this._client.post(path`/instances/${id}/promote-template`, options);
167+
}
168+
141169
/**
142170
* Restore instance from standby
143171
*
@@ -377,9 +405,20 @@ export interface Instance {
377405
* - Shutdown: VM shut down but VMM exists (Cloud Hypervisor native)
378406
* - Stopped: No VMM running, no snapshot exists
379407
* - Standby: No VMM running, snapshot exists (can be restored)
408+
* - Template: Standby snapshot promoted to a fork-only parent; cannot wake while
409+
* forks exist
380410
* - Unknown: Failed to determine state (see state_error for details)
381411
*/
382-
state: 'Created' | 'Initializing' | 'Running' | 'Paused' | 'Shutdown' | 'Stopped' | 'Standby' | 'Unknown';
412+
state:
413+
| 'Created'
414+
| 'Initializing'
415+
| 'Running'
416+
| 'Paused'
417+
| 'Shutdown'
418+
| 'Stopped'
419+
| 'Standby'
420+
| 'Template'
421+
| 'Unknown';
383422

384423
/**
385424
* Linux-only automatic standby policy based on active inbound TCP connections
@@ -812,7 +851,16 @@ export interface WaitForStateResponse {
812851
/**
813852
* Current instance state when the wait completed
814853
*/
815-
state: 'Created' | 'Initializing' | 'Running' | 'Paused' | 'Shutdown' | 'Stopped' | 'Standby' | 'Unknown';
854+
state:
855+
| 'Created'
856+
| 'Initializing'
857+
| 'Running'
858+
| 'Paused'
859+
| 'Shutdown'
860+
| 'Stopped'
861+
| 'Standby'
862+
| 'Template'
863+
| 'Unknown';
816864

817865
/**
818866
* Whether the timeout expired before the target state was reached
@@ -1095,7 +1143,16 @@ export interface InstanceListParams {
10951143
/**
10961144
* Filter instances by state (e.g., Running, Stopped)
10971145
*/
1098-
state?: 'Created' | 'Initializing' | 'Running' | 'Paused' | 'Shutdown' | 'Stopped' | 'Standby' | 'Unknown';
1146+
state?:
1147+
| 'Created'
1148+
| 'Initializing'
1149+
| 'Running'
1150+
| 'Paused'
1151+
| 'Shutdown'
1152+
| 'Stopped'
1153+
| 'Standby'
1154+
| 'Template'
1155+
| 'Unknown';
10991156

11001157
/**
11011158
* Filter instances by tag key-value pairs. Uses deepObject style:
@@ -1189,7 +1246,16 @@ export interface InstanceWaitParams {
11891246
/**
11901247
* Target state to wait for
11911248
*/
1192-
state: 'Created' | 'Initializing' | 'Running' | 'Paused' | 'Shutdown' | 'Stopped' | 'Standby' | 'Unknown';
1249+
state:
1250+
| 'Created'
1251+
| 'Initializing'
1252+
| 'Running'
1253+
| 'Paused'
1254+
| 'Shutdown'
1255+
| 'Stopped'
1256+
| 'Standby'
1257+
| 'Template'
1258+
| 'Unknown';
11931259

11941260
/**
11951261
* Maximum duration to wait (Go duration format, e.g. "30s", "2m"). Capped at 5

tests/api-resources/instances/instances.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ describe('resource instances', () => {
138138
expect(dataAndResponse.response).toBe(rawResponse);
139139
});
140140

141+
// Mock server tests are disabled
142+
test.skip('demoteTemplate', async () => {
143+
const responsePromise = client.instances.demoteTemplate('id');
144+
const rawResponse = await responsePromise.asResponse();
145+
expect(rawResponse).toBeInstanceOf(Response);
146+
const response = await responsePromise;
147+
expect(response).not.toBeInstanceOf(Response);
148+
const dataAndResponse = await responsePromise.withResponse();
149+
expect(dataAndResponse.data).toBe(response);
150+
expect(dataAndResponse.response).toBe(rawResponse);
151+
});
152+
141153
// Mock server tests are disabled
142154
test.skip('fork: only required params', async () => {
143155
const responsePromise = client.instances.fork('id', { name: 'my-workload-1-fork' });
@@ -199,6 +211,18 @@ describe('resource instances', () => {
199211
).rejects.toThrow(Hypeman.NotFoundError);
200212
});
201213

214+
// Mock server tests are disabled
215+
test.skip('promoteTemplate', async () => {
216+
const responsePromise = client.instances.promoteTemplate('id');
217+
const rawResponse = await responsePromise.asResponse();
218+
expect(rawResponse).toBeInstanceOf(Response);
219+
const response = await responsePromise;
220+
expect(response).not.toBeInstanceOf(Response);
221+
const dataAndResponse = await responsePromise.withResponse();
222+
expect(dataAndResponse.data).toBe(response);
223+
expect(dataAndResponse.response).toBe(rawResponse);
224+
});
225+
202226
// Mock server tests are disabled
203227
test.skip('restore', async () => {
204228
const responsePromise = client.instances.restore('id');

0 commit comments

Comments
 (0)