Skip to content

Commit ebdbe6e

Browse files
feat: Add Linux auto-standby controller and E2E coverage
1 parent c734bc1 commit ebdbe6e

9 files changed

Lines changed: 205 additions & 4 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: 51
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-a1912a634af4109683e626e337c1a1f1ddf488861bd16692f4bf3a4309477d1b.yml
3-
openapi_spec_hash: 10ce32db64b5ec6815d861f18415be48
4-
config_hash: b3559c96c301e1fcdea2d7e9aba1e5e1
1+
configured_endpoints: 52
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-52bc64e89c8406b774158cdb7fdb239dd4c39e6bace06b32e5224b82462f9ffe.yml
3+
openapi_spec_hash: 647ddb91aa6aca7034f2015071c30ce6
4+
config_hash: d81afc6f4fabf65fc9291db9ddd79f87

api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Methods:
3232

3333
Types:
3434

35+
- <code><a href="./src/resources/instances/instances.ts">AutoStandbyPolicy</a></code>
36+
- <code><a href="./src/resources/instances/instances.ts">AutoStandbyStatus</a></code>
3537
- <code><a href="./src/resources/instances/instances.ts">Instance</a></code>
3638
- <code><a href="./src/resources/instances/instances.ts">InstanceStats</a></code>
3739
- <code><a href="./src/resources/instances/instances.ts">PathInfo</a></code>
@@ -62,6 +64,12 @@ Methods:
6264
- <code title="post /instances/{id}/stop">client.instances.<a href="./src/resources/instances/instances.ts">stop</a>(id) -> Instance</code>
6365
- <code title="get /instances/{id}/wait">client.instances.<a href="./src/resources/instances/instances.ts">wait</a>(id, { ...params }) -> WaitForStateResponse</code>
6466

67+
## AutoStandby
68+
69+
Methods:
70+
71+
- <code title="get /instances/{id}/auto-standby/status">client.instances.autoStandby.<a href="./src/resources/instances/auto-standby.ts">status</a>(id) -> AutoStandbyStatus</code>
72+
6573
## Volumes
6674

6775
Methods:

src/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ import {
8282
Volumes,
8383
} from './resources/volumes';
8484
import {
85+
AutoStandbyPolicy,
86+
AutoStandbyStatus,
8587
Instance,
8688
InstanceCreateParams,
8789
InstanceForkParams,
@@ -837,6 +839,8 @@ export declare namespace Hypeman {
837839

838840
export {
839841
Instances as Instances,
842+
type AutoStandbyPolicy as AutoStandbyPolicy,
843+
type AutoStandbyStatus as AutoStandbyStatus,
840844
type Instance as Instance,
841845
type InstanceStats as InstanceStats,
842846
type PathInfo as PathInfo,

src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export {
4343
} from './ingresses';
4444
export {
4545
Instances,
46+
type AutoStandbyPolicy,
47+
type AutoStandbyStatus,
4648
type Instance,
4749
type InstanceStats,
4850
type PathInfo,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../../core/resource';
4+
import * as InstancesAPI from './instances';
5+
import { APIPromise } from '../../core/api-promise';
6+
import { RequestOptions } from '../../internal/request-options';
7+
import { path } from '../../internal/utils/path';
8+
9+
export class AutoStandby extends APIResource {
10+
/**
11+
* Get auto-standby diagnostic status
12+
*
13+
* @example
14+
* ```ts
15+
* const autoStandbyStatus =
16+
* await client.instances.autoStandby.status('id');
17+
* ```
18+
*/
19+
status(id: string, options?: RequestOptions): APIPromise<InstancesAPI.AutoStandbyStatus> {
20+
return this._client.get(path`/instances/${id}/auto-standby/status`, options);
21+
}
22+
}

src/resources/instances/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
export { AutoStandby } from './auto-standby';
34
export {
45
Instances,
6+
type AutoStandbyPolicy,
7+
type AutoStandbyStatus,
58
type Instance,
69
type InstanceStats,
710
type PathInfo,

src/resources/instances/instances.ts

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { APIResource } from '../../core/resource';
44
import * as Shared from '../shared';
5+
import * as AutoStandbyAPI from './auto-standby';
6+
import { AutoStandby } from './auto-standby';
57
import * as SnapshotScheduleAPI from './snapshot-schedule';
68
import { SnapshotScheduleUpdateParams } from './snapshot-schedule';
79
import * as SnapshotsAPI from './snapshots';
@@ -15,6 +17,7 @@ import { RequestOptions } from '../../internal/request-options';
1517
import { path } from '../../internal/utils/path';
1618

1719
export class Instances extends APIResource {
20+
autoStandby: AutoStandbyAPI.AutoStandby = new AutoStandbyAPI.AutoStandby(this._client);
1821
volumes: VolumesAPI.Volumes = new VolumesAPI.Volumes(this._client);
1922
snapshots: SnapshotsAPI.Snapshots = new SnapshotsAPI.Snapshots(this._client);
2023
snapshotSchedule: SnapshotScheduleAPI.SnapshotSchedule = new SnapshotScheduleAPI.SnapshotSchedule(
@@ -235,6 +238,114 @@ export class Instances extends APIResource {
235238
}
236239
}
237240

241+
/**
242+
* Linux-only automatic standby policy based on active inbound TCP connections
243+
* observed from the host conntrack table.
244+
*/
245+
export interface AutoStandbyPolicy {
246+
/**
247+
* Whether automatic standby is enabled for this instance.
248+
*/
249+
enabled?: boolean;
250+
251+
/**
252+
* How long the instance must have zero qualifying inbound TCP connections before
253+
* Hypeman places it into standby.
254+
*/
255+
idle_timeout?: string;
256+
257+
/**
258+
* Optional destination TCP ports that should not keep the instance awake.
259+
*/
260+
ignore_destination_ports?: Array<number>;
261+
262+
/**
263+
* Optional client CIDRs that should not keep the instance awake.
264+
*/
265+
ignore_source_cidrs?: Array<string>;
266+
}
267+
268+
export interface AutoStandbyStatus {
269+
/**
270+
* Number of currently tracked qualifying inbound TCP connections.
271+
*/
272+
active_inbound_connections: number;
273+
274+
/**
275+
* Whether the instance has any auto-standby policy configured.
276+
*/
277+
configured: boolean;
278+
279+
/**
280+
* Whether the instance is currently eligible to enter standby.
281+
*/
282+
eligible: boolean;
283+
284+
/**
285+
* Whether the configured auto-standby policy is enabled.
286+
*/
287+
enabled: boolean;
288+
289+
reason:
290+
| 'unsupported_platform'
291+
| 'policy_missing'
292+
| 'policy_disabled'
293+
| 'instance_not_running'
294+
| 'network_disabled'
295+
| 'missing_ip'
296+
| 'has_vgpu'
297+
| 'active_inbound_connections'
298+
| 'idle_timeout_not_elapsed'
299+
| 'observer_error'
300+
| 'ready_for_standby';
301+
302+
status:
303+
| 'unsupported'
304+
| 'disabled'
305+
| 'ineligible'
306+
| 'active'
307+
| 'idle_countdown'
308+
| 'ready_for_standby'
309+
| 'standby_requested'
310+
| 'error';
311+
312+
/**
313+
* Whether the current host platform supports auto-standby diagnostics.
314+
*/
315+
supported: boolean;
316+
317+
/**
318+
* Diagnostic identifier for the runtime tracking mode in use.
319+
*/
320+
tracking_mode: string;
321+
322+
/**
323+
* Remaining time before the controller attempts standby, when applicable.
324+
*/
325+
countdown_remaining?: string | null;
326+
327+
/**
328+
* When the controller most recently observed the instance become idle.
329+
*/
330+
idle_since?: string | null;
331+
332+
/**
333+
* Configured idle timeout from the auto-standby policy.
334+
*/
335+
idle_timeout?: string | null;
336+
337+
/**
338+
* Timestamp of the most recent qualifying inbound TCP activity the controller
339+
* observed.
340+
*/
341+
last_inbound_activity_at?: string | null;
342+
343+
/**
344+
* When the controller expects to attempt standby next, if a countdown is active.
345+
*/
346+
next_standby_at?: string | null;
347+
}
348+
238349
export interface Instance {
239350
/**
240351
* Auto-generated unique identifier (CUID2 format)
@@ -270,6 +381,12 @@ export interface Instance {
270381
*/
271382
state: 'Created' | 'Initializing' | 'Running' | 'Paused' | 'Shutdown' | 'Stopped' | 'Standby' | 'Unknown';
272383

384+
/**
385+
* Linux-only automatic standby policy based on active inbound TCP connections
386+
* observed from the host conntrack table.
387+
*/
388+
auto_standby?: AutoStandbyPolicy;
389+
273390
/**
274391
* Disk I/O rate limit (human-readable, e.g., "100MB/s")
275392
*/
@@ -684,6 +801,12 @@ export interface InstanceCreateParams {
684801
*/
685802
name: string;
686803

804+
/**
805+
* Linux-only automatic standby policy based on active inbound TCP connections
806+
* observed from the host conntrack table.
807+
*/
808+
auto_standby?: AutoStandbyPolicy;
809+
687810
/**
688811
* Override image CMD (like docker run <image> <command>). Omit to use image
689812
* default.
@@ -913,6 +1036,12 @@ export namespace InstanceCreateParams {
9131036
}
9141037

9151038
export interface InstanceUpdateParams {
1039+
/**
1040+
* Linux-only automatic standby policy based on active inbound TCP connections
1041+
* observed from the host conntrack table.
1042+
*/
1043+
auto_standby?: AutoStandbyPolicy;
1044+
9161045
/**
9171046
* Environment variables to update (merged with existing). Only keys referenced by
9181047
* the instance's existing credential `source.env` bindings are accepted. Use this
@@ -1018,11 +1147,14 @@ export interface InstanceWaitParams {
10181147
timeout?: string;
10191148
}
10201149

1150+
Instances.AutoStandby = AutoStandby;
10211151
Instances.Volumes = Volumes;
10221152
Instances.Snapshots = Snapshots;
10231153

10241154
export declare namespace Instances {
10251155
export {
1156+
type AutoStandbyPolicy as AutoStandbyPolicy,
1157+
type AutoStandbyStatus as AutoStandbyStatus,
10261158
type Instance as Instance,
10271159
type InstanceStats as InstanceStats,
10281160
type PathInfo as PathInfo,
@@ -1046,6 +1178,8 @@ export declare namespace Instances {
10461178
type InstanceWaitParams as InstanceWaitParams,
10471179
};
10481180

1181+
export { AutoStandby as AutoStandby };
1182+
10491183
export {
10501184
Volumes as Volumes,
10511185
type VolumeAttachParams as VolumeAttachParams,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import Hypeman from '@onkernel/hypeman';
4+
5+
const client = new Hypeman({
6+
apiKey: 'My API Key',
7+
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
8+
});
9+
10+
describe('resource autoStandby', () => {
11+
// Mock server tests are disabled
12+
test.skip('status', async () => {
13+
const responsePromise = client.instances.autoStandby.status('id');
14+
const rawResponse = await responsePromise.asResponse();
15+
expect(rawResponse).toBeInstanceOf(Response);
16+
const response = await responsePromise;
17+
expect(response).not.toBeInstanceOf(Response);
18+
const dataAndResponse = await responsePromise.withResponse();
19+
expect(dataAndResponse.data).toBe(response);
20+
expect(dataAndResponse.response).toBe(rawResponse);
21+
});
22+
});

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ describe('resource instances', () => {
2828
const response = await client.instances.create({
2929
image: 'docker.io/library/alpine:latest',
3030
name: 'my-workload-1',
31+
auto_standby: {
32+
enabled: true,
33+
idle_timeout: '5m',
34+
ignore_destination_ports: [22, 9000],
35+
ignore_source_cidrs: ['10.0.0.0/8', '192.168.0.0/16'],
36+
},
3137
cmd: ['echo', 'hello'],
3238
credentials: {
3339
OUTBOUND_OPENAI_KEY: {

0 commit comments

Comments
 (0)