-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathautoscale.ts
More file actions
647 lines (568 loc) · 17 KB
/
autoscale.ts
File metadata and controls
647 lines (568 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import * as Shared from '../shared';
import { APIPromise } from '../../core/api-promise';
import { buildHeaders } from '../../internal/headers';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
export class Autoscale extends APIResource {
/**
* To create a new autoscale pool, send a POST request to `/v2/droplets/autoscale`
* setting the required attributes.
*
* The response body will contain a JSON object with a key called `autoscale_pool`
* containing the standard attributes for the new autoscale pool.
*
* @example
* ```ts
* const autoscale = await client.gpuDroplets.autoscale.create(
* {
* config: {
* min_instances: 1,
* max_instances: 5,
* target_cpu_utilization: 0.5,
* cooldown_minutes: 10,
* },
* droplet_template: {
* name: 'example.com',
* region: 'nyc3',
* size: 'c-2',
* image: 'ubuntu-20-04-x64',
* ssh_keys: [
* '3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45',
* ],
* backups: true,
* ipv6: true,
* monitoring: true,
* tags: ['env:prod', 'web'],
* user_data:
* '#cloud-config\nruncmd:\n - touch /test.txt\n',
* vpc_uuid: '760e09ef-dc84-11e8-981e-3cfdfeaae000',
* },
* name: 'my-autoscale-pool',
* },
* );
* ```
*/
create(body: AutoscaleCreateParams, options?: RequestOptions): APIPromise<AutoscaleCreateResponse> {
return this._client.post('/v2/droplets/autoscale', {
body,
defaultBaseURL: 'https://api.digitalocean.com',
...options,
});
}
/**
* To show information about an individual autoscale pool, send a GET request to
* `/v2/droplets/autoscale/$AUTOSCALE_POOL_ID`.
*
* @example
* ```ts
* const autoscale =
* await client.gpuDroplets.autoscale.retrieve(
* '0d3db13e-a604-4944-9827-7ec2642d32ac',
* );
* ```
*/
retrieve(autoscalePoolID: string, options?: RequestOptions): APIPromise<AutoscaleRetrieveResponse> {
return this._client.get(path`/v2/droplets/autoscale/${autoscalePoolID}`, {
defaultBaseURL: 'https://api.digitalocean.com',
...options,
});
}
/**
* To update the configuration of an existing autoscale pool, send a PUT request to
* `/v2/droplets/autoscale/$AUTOSCALE_POOL_ID`. The request must contain a full
* representation of the autoscale pool including existing attributes.
*
* @example
* ```ts
* const autoscale = await client.gpuDroplets.autoscale.update(
* '0d3db13e-a604-4944-9827-7ec2642d32ac',
* {
* config: { target_number_instances: 2 },
* droplet_template: {
* name: 'example.com',
* region: 'nyc3',
* size: 'c-2',
* image: 'ubuntu-20-04-x64',
* ssh_keys: [
* '3b:16:e4:bf:8b:00:8b:b8:59:8c:a9:d3:f0:19:fa:45',
* ],
* backups: true,
* ipv6: true,
* monitoring: true,
* tags: ['env:prod', 'web'],
* user_data:
* '#cloud-config\nruncmd:\n - touch /test.txt\n',
* vpc_uuid: '760e09ef-dc84-11e8-981e-3cfdfeaae000',
* },
* name: 'my-autoscale-pool',
* },
* );
* ```
*/
update(
autoscalePoolID: string,
body: AutoscaleUpdateParams,
options?: RequestOptions,
): APIPromise<AutoscaleUpdateResponse> {
return this._client.put(path`/v2/droplets/autoscale/${autoscalePoolID}`, {
body,
defaultBaseURL: 'https://api.digitalocean.com',
...options,
});
}
/**
* To list all autoscale pools in your team, send a GET request to
* `/v2/droplets/autoscale`. The response body will be a JSON object with a key of
* `autoscale_pools` containing an array of autoscale pool objects. These each
* contain the standard autoscale pool attributes.
*
* @example
* ```ts
* const autoscales =
* await client.gpuDroplets.autoscale.list();
* ```
*/
list(
query: AutoscaleListParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<AutoscaleListResponse> {
return this._client.get('/v2/droplets/autoscale', {
query,
defaultBaseURL: 'https://api.digitalocean.com',
...options,
});
}
/**
* To destroy an autoscale pool, send a DELETE request to the
* `/v2/droplets/autoscale/$AUTOSCALE_POOL_ID` endpoint.
*
* A successful response will include a 202 response code and no content.
*
* @example
* ```ts
* await client.gpuDroplets.autoscale.delete(
* '0d3db13e-a604-4944-9827-7ec2642d32ac',
* );
* ```
*/
delete(autoscalePoolID: string, options?: RequestOptions): APIPromise<void> {
return this._client.delete(path`/v2/droplets/autoscale/${autoscalePoolID}`, {
defaultBaseURL: 'https://api.digitalocean.com',
...options,
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
});
}
/**
* To destroy an autoscale pool and its associated resources (Droplets), send a
* DELETE request to the `/v2/droplets/autoscale/$AUTOSCALE_POOL_ID/dangerous`
* endpoint.
*
* @example
* ```ts
* await client.gpuDroplets.autoscale.deleteDangerous(
* '0d3db13e-a604-4944-9827-7ec2642d32ac',
* { 'X-Dangerous': true },
* );
* ```
*/
deleteDangerous(
autoscalePoolID: string,
params: AutoscaleDeleteDangerousParams,
options?: RequestOptions,
): APIPromise<void> {
const { 'X-Dangerous': xDangerous } = params;
return this._client.delete(path`/v2/droplets/autoscale/${autoscalePoolID}/dangerous`, {
defaultBaseURL: 'https://api.digitalocean.com',
...options,
headers: buildHeaders([{ Accept: '*/*', 'X-Dangerous': xDangerous.toString() }, options?.headers]),
});
}
/**
* To list all of the scaling history events of an autoscale pool, send a GET
* request to `/v2/droplets/autoscale/$AUTOSCALE_POOL_ID/history`.
*
* The response body will be a JSON object with a key of `history`. This will be
* set to an array containing objects each representing a history event.
*
* @example
* ```ts
* const response =
* await client.gpuDroplets.autoscale.listHistory(
* '0d3db13e-a604-4944-9827-7ec2642d32ac',
* );
* ```
*/
listHistory(
autoscalePoolID: string,
query: AutoscaleListHistoryParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<AutoscaleListHistoryResponse> {
return this._client.get(path`/v2/droplets/autoscale/${autoscalePoolID}/history`, {
query,
defaultBaseURL: 'https://api.digitalocean.com',
...options,
});
}
/**
* To list the Droplets in an autoscale pool, send a GET request to
* `/v2/droplets/autoscale/$AUTOSCALE_POOL_ID/members`.
*
* The response body will be a JSON object with a key of `droplets`. This will be
* set to an array containing information about each of the Droplets in the
* autoscale pool.
*
* @example
* ```ts
* const response =
* await client.gpuDroplets.autoscale.listMembers(
* '0d3db13e-a604-4944-9827-7ec2642d32ac',
* );
* ```
*/
listMembers(
autoscalePoolID: string,
query: AutoscaleListMembersParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<AutoscaleListMembersResponse> {
return this._client.get(path`/v2/droplets/autoscale/${autoscalePoolID}/members`, {
query,
defaultBaseURL: 'https://api.digitalocean.com',
...options,
});
}
}
export interface AutoscalePool {
/**
* A unique identifier for each autoscale pool instance. This is automatically
* generated upon autoscale pool creation.
*/
id: string;
/**
* The number of active Droplets in the autoscale pool.
*/
active_resources_count: number;
/**
* The scaling configuration for an autoscale pool, which is how the pool scales up
* and down (either by resource utilization or static configuration).
*/
config: AutoscalePoolStaticConfig | AutoscalePoolDynamicConfig;
/**
* A time value given in ISO8601 combined date and time format that represents when
* the autoscale pool was created.
*/
created_at: string;
droplet_template: AutoscalePoolDropletTemplate;
/**
* The human-readable name set for the autoscale pool.
*/
name: string;
/**
* The current status of the autoscale pool.
*/
status: 'active' | 'deleting' | 'error';
/**
* A time value given in ISO8601 combined date and time format that represents when
* the autoscale pool was last updated.
*/
updated_at: string;
current_utilization?: CurrentUtilization;
}
export interface AutoscalePoolDropletTemplate {
/**
* The Droplet image to be used for all Droplets in the autoscale pool. You may
* specify the slug or the image ID.
*/
image: string;
/**
* The datacenter in which all of the Droplets will be created.
*/
region:
| 'nyc1'
| 'nyc2'
| 'nyc3'
| 'ams2'
| 'ams3'
| 'sfo1'
| 'sfo2'
| 'sfo3'
| 'sgp1'
| 'lon1'
| 'fra1'
| 'tor1'
| 'blr1'
| 'syd1';
/**
* The Droplet size to be used for all Droplets in the autoscale pool.
*/
size: string;
/**
* The SSH keys to be installed on the Droplets in the autoscale pool. You can
* either specify the key ID or the fingerprint. Requires `ssh_key:read` scope.
*/
ssh_keys: Array<string>;
/**
* Assigns a unique IPv6 address to each of the Droplets in the autoscale pool.
*/
ipv6?: boolean;
/**
* The name(s) to be applied to all Droplets in the autoscale pool.
*/
name?: string;
/**
* The project that the Droplets in the autoscale pool will belong to. Requires
* `project:read` scope.
*/
project_id?: string;
/**
* The tags to apply to each of the Droplets in the autoscale pool. Requires
* `tag:read` scope.
*/
tags?: Array<string>;
/**
* A string containing user data that cloud-init consumes to configure a Droplet on
* first boot. User data is often a cloud-config file or Bash script. It must be
* plain text and may not exceed 64 KiB in size.
*/
user_data?: string;
/**
* The VPC where the Droplets in the autoscale pool will be created. The VPC must
* be in the region where you want to create the Droplets. Requires `vpc:read`
* scope.
*/
vpc_uuid?: string;
/**
* Installs the Droplet agent. This must be set to true to monitor Droplets for
* resource utilization scaling.
*/
with_droplet_agent?: boolean;
}
export interface AutoscalePoolDynamicConfig {
/**
* The maximum number of Droplets in an autoscale pool.
*/
max_instances: number;
/**
* The minimum number of Droplets in an autoscale pool.
*/
min_instances: number;
/**
* The number of minutes to wait between scaling events in an autoscale pool.
* Defaults to 10 minutes.
*/
cooldown_minutes?: number;
/**
* Target CPU utilization as a decimal.
*/
target_cpu_utilization?: number;
/**
* Target memory utilization as a decimal.
*/
target_memory_utilization?: number;
}
export interface AutoscalePoolStaticConfig {
/**
* Fixed number of instances in an autoscale pool.
*/
target_number_instances: number;
}
export interface CurrentUtilization {
/**
* The average CPU utilization of the autoscale pool.
*/
cpu?: number;
/**
* The average memory utilization of the autoscale pool.
*/
memory?: number;
}
export interface AutoscaleCreateResponse {
autoscale_pool?: AutoscalePool;
}
export interface AutoscaleRetrieveResponse {
autoscale_pool?: AutoscalePool;
}
export interface AutoscaleUpdateResponse {
autoscale_pool?: AutoscalePool;
}
export interface AutoscaleListResponse {
/**
* Information about the response itself.
*/
meta: Shared.MetaProperties;
autoscale_pools?: Array<AutoscalePool>;
links?: Shared.PageLinks;
}
export interface AutoscaleListHistoryResponse {
/**
* Information about the response itself.
*/
meta: Shared.MetaProperties;
history?: Array<AutoscaleListHistoryResponse.History>;
links?: Shared.PageLinks;
}
export namespace AutoscaleListHistoryResponse {
export interface History {
/**
* The creation time of the history event in ISO8601 combined date and time format.
*/
created_at: string;
/**
* The current number of Droplets in the autoscale pool.
*/
current_instance_count: number;
/**
* The target number of Droplets for the autoscale pool after the scaling event.
*/
desired_instance_count: number;
/**
* The unique identifier of the history event.
*/
history_event_id: string;
/**
* The reason for the scaling event.
*/
reason: 'CONFIGURATION_CHANGE' | 'SCALE_UP' | 'SCALE_DOWN';
/**
* The status of the scaling event.
*/
status: 'in_progress' | 'success' | 'error';
/**
* The last updated time of the history event in ISO8601 combined date and time
* format.
*/
updated_at: string;
}
}
export interface AutoscaleListMembersResponse {
/**
* Information about the response itself.
*/
meta: Shared.MetaProperties;
droplets?: Array<AutoscaleListMembersResponse.Droplet>;
links?: Shared.PageLinks;
}
export namespace AutoscaleListMembersResponse {
export interface Droplet {
/**
* The creation time of the Droplet in ISO8601 combined date and time format.
*/
created_at: string;
current_utilization: Droplet.CurrentUtilization;
/**
* The unique identifier of the Droplet.
*/
droplet_id: number;
/**
* The health status of the Droplet.
*/
health_status: string;
/**
* The power status of the Droplet.
*/
status: 'provisioning' | 'active' | 'deleting' | 'off';
/**
* The last updated time of the Droplet in ISO8601 combined date and time format.
*/
updated_at: string;
}
export namespace Droplet {
export interface CurrentUtilization {
/**
* The CPU utilization average of the individual Droplet.
*/
cpu?: number;
/**
* The memory utilization average of the individual Droplet.
*/
memory?: number;
}
}
}
export interface AutoscaleCreateParams {
/**
* The scaling configuration for an autoscale pool, which is how the pool scales up
* and down (either by resource utilization or static configuration).
*/
config: AutoscalePoolStaticConfig | AutoscalePoolDynamicConfig;
droplet_template: AutoscalePoolDropletTemplate;
/**
* The human-readable name of the autoscale pool. This field cannot be updated
*/
name: string;
}
export interface AutoscaleUpdateParams {
/**
* The scaling configuration for an autoscale pool, which is how the pool scales up
* and down (either by resource utilization or static configuration).
*/
config: AutoscalePoolStaticConfig | AutoscalePoolDynamicConfig;
droplet_template: AutoscalePoolDropletTemplate;
/**
* The human-readable name of the autoscale pool. This field cannot be updated
*/
name: string;
}
export interface AutoscaleListParams {
/**
* The name of the autoscale pool
*/
name?: string;
/**
* Which 'page' of paginated results to return.
*/
page?: number;
/**
* Number of items returned per page
*/
per_page?: number;
}
export interface AutoscaleDeleteDangerousParams {
/**
* Acknowledge this action will destroy the autoscale pool and its associated
* resources and _can not_ be reversed.
*/
'X-Dangerous': boolean;
}
export interface AutoscaleListHistoryParams {
/**
* Which 'page' of paginated results to return.
*/
page?: number;
/**
* Number of items returned per page
*/
per_page?: number;
}
export interface AutoscaleListMembersParams {
/**
* Which 'page' of paginated results to return.
*/
page?: number;
/**
* Number of items returned per page
*/
per_page?: number;
}
export declare namespace Autoscale {
export {
type AutoscalePool as AutoscalePool,
type AutoscalePoolDropletTemplate as AutoscalePoolDropletTemplate,
type AutoscalePoolDynamicConfig as AutoscalePoolDynamicConfig,
type AutoscalePoolStaticConfig as AutoscalePoolStaticConfig,
type CurrentUtilization as CurrentUtilization,
type AutoscaleCreateResponse as AutoscaleCreateResponse,
type AutoscaleRetrieveResponse as AutoscaleRetrieveResponse,
type AutoscaleUpdateResponse as AutoscaleUpdateResponse,
type AutoscaleListResponse as AutoscaleListResponse,
type AutoscaleListHistoryResponse as AutoscaleListHistoryResponse,
type AutoscaleListMembersResponse as AutoscaleListMembersResponse,
type AutoscaleCreateParams as AutoscaleCreateParams,
type AutoscaleUpdateParams as AutoscaleUpdateParams,
type AutoscaleListParams as AutoscaleListParams,
type AutoscaleDeleteDangerousParams as AutoscaleDeleteDangerousParams,
type AutoscaleListHistoryParams as AutoscaleListHistoryParams,
type AutoscaleListMembersParams as AutoscaleListMembersParams,
};
}