@scaleway/sdk-autoscaling 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,373 @@
1
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalMapOfObject, unmarshalArrayOfObject } from "@scaleway/sdk-client";
2
+ const unmarshalCapacity = (data) => {
3
+ if (!isJSONObject(data)) {
4
+ throw new TypeError(
5
+ `Unmarshalling the type 'Capacity' failed as data isn't a dictionary.`
6
+ );
7
+ }
8
+ return {
9
+ cooldownDelay: data.cooldown_delay,
10
+ maxReplicas: data.max_replicas,
11
+ minReplicas: data.min_replicas
12
+ };
13
+ };
14
+ const unmarshalLoadbalancer = (data) => {
15
+ if (!isJSONObject(data)) {
16
+ throw new TypeError(
17
+ `Unmarshalling the type 'Loadbalancer' failed as data isn't a dictionary.`
18
+ );
19
+ }
20
+ return {
21
+ backendIds: data.backend_ids,
22
+ id: data.id,
23
+ privateNetworkId: data.private_network_id
24
+ };
25
+ };
26
+ const unmarshalInstanceGroup = (data) => {
27
+ if (!isJSONObject(data)) {
28
+ throw new TypeError(
29
+ `Unmarshalling the type 'InstanceGroup' failed as data isn't a dictionary.`
30
+ );
31
+ }
32
+ return {
33
+ capacity: unmarshalCapacity(data.capacity),
34
+ createdAt: unmarshalDate(data.created_at),
35
+ errorMessages: data.error_messages,
36
+ id: data.id,
37
+ instanceTemplateId: data.instance_template_id,
38
+ loadbalancer: unmarshalLoadbalancer(data.loadbalancer),
39
+ name: data.name,
40
+ projectId: data.project_id,
41
+ tags: data.tags,
42
+ updatedAt: unmarshalDate(data.updated_at)
43
+ };
44
+ };
45
+ const unmarshalMetric = (data) => {
46
+ if (!isJSONObject(data)) {
47
+ throw new TypeError(
48
+ `Unmarshalling the type 'Metric' failed as data isn't a dictionary.`
49
+ );
50
+ }
51
+ return {
52
+ aggregate: data.aggregate,
53
+ cockpitMetricName: data.cockpit_metric_name,
54
+ managedMetric: data.managed_metric ? data.managed_metric : void 0,
55
+ name: data.name,
56
+ operator: data.operator,
57
+ samplingRangeMin: data.sampling_range_min,
58
+ threshold: data.threshold
59
+ };
60
+ };
61
+ const unmarshalInstancePolicy = (data) => {
62
+ if (!isJSONObject(data)) {
63
+ throw new TypeError(
64
+ `Unmarshalling the type 'InstancePolicy' failed as data isn't a dictionary.`
65
+ );
66
+ }
67
+ return {
68
+ action: data.action,
69
+ id: data.id,
70
+ instanceGroupId: data.instance_group_id,
71
+ metric: data.metric ? unmarshalMetric(data.metric) : void 0,
72
+ name: data.name,
73
+ priority: data.priority,
74
+ type: data.type,
75
+ value: data.value
76
+ };
77
+ };
78
+ const unmarshalVolumeInstanceTemplateFromEmpty = (data) => {
79
+ if (!isJSONObject(data)) {
80
+ throw new TypeError(
81
+ `Unmarshalling the type 'VolumeInstanceTemplateFromEmpty' failed as data isn't a dictionary.`
82
+ );
83
+ }
84
+ return {
85
+ size: data.size
86
+ };
87
+ };
88
+ const unmarshalVolumeInstanceTemplateFromSnapshot = (data) => {
89
+ if (!isJSONObject(data)) {
90
+ throw new TypeError(
91
+ `Unmarshalling the type 'VolumeInstanceTemplateFromSnapshot' failed as data isn't a dictionary.`
92
+ );
93
+ }
94
+ return {
95
+ size: data.size,
96
+ snapshotId: data.snapshot_id
97
+ };
98
+ };
99
+ const unmarshalVolumeInstanceTemplate = (data) => {
100
+ if (!isJSONObject(data)) {
101
+ throw new TypeError(
102
+ `Unmarshalling the type 'VolumeInstanceTemplate' failed as data isn't a dictionary.`
103
+ );
104
+ }
105
+ return {
106
+ boot: data.boot,
107
+ fromEmpty: data.from_empty ? unmarshalVolumeInstanceTemplateFromEmpty(data.from_empty) : void 0,
108
+ fromSnapshot: data.from_snapshot ? unmarshalVolumeInstanceTemplateFromSnapshot(data.from_snapshot) : void 0,
109
+ name: data.name,
110
+ perfIops: data.perf_iops,
111
+ tags: data.tags,
112
+ volumeType: data.volume_type
113
+ };
114
+ };
115
+ const unmarshalInstanceTemplate = (data) => {
116
+ if (!isJSONObject(data)) {
117
+ throw new TypeError(
118
+ `Unmarshalling the type 'InstanceTemplate' failed as data isn't a dictionary.`
119
+ );
120
+ }
121
+ return {
122
+ cloudInit: data.cloud_init,
123
+ commercialType: data.commercial_type,
124
+ createdAt: unmarshalDate(data.created_at),
125
+ id: data.id,
126
+ imageId: data.image_id,
127
+ name: data.name,
128
+ placementGroupId: data.placement_group_id,
129
+ privateNetworkIds: data.private_network_ids,
130
+ projectId: data.project_id,
131
+ publicIpsV4Count: data.public_ips_v4_count,
132
+ publicIpsV6Count: data.public_ips_v6_count,
133
+ securityGroupId: data.security_group_id,
134
+ status: data.status,
135
+ tags: data.tags,
136
+ updatedAt: unmarshalDate(data.updated_at),
137
+ volumes: unmarshalMapOfObject(
138
+ data.volumes,
139
+ unmarshalVolumeInstanceTemplate
140
+ )
141
+ };
142
+ };
143
+ const unmarshalInstanceGroupEvent = (data) => {
144
+ if (!isJSONObject(data)) {
145
+ throw new TypeError(
146
+ `Unmarshalling the type 'InstanceGroupEvent' failed as data isn't a dictionary.`
147
+ );
148
+ }
149
+ return {
150
+ createdAt: unmarshalDate(data.created_at),
151
+ details: data.details,
152
+ id: data.id,
153
+ level: data.level,
154
+ name: data.name,
155
+ source: data.source
156
+ };
157
+ };
158
+ const unmarshalListInstanceGroupEventsResponse = (data) => {
159
+ if (!isJSONObject(data)) {
160
+ throw new TypeError(
161
+ `Unmarshalling the type 'ListInstanceGroupEventsResponse' failed as data isn't a dictionary.`
162
+ );
163
+ }
164
+ return {
165
+ instanceEvents: unmarshalArrayOfObject(
166
+ data.instance_events,
167
+ unmarshalInstanceGroupEvent
168
+ ),
169
+ totalCount: data.total_count
170
+ };
171
+ };
172
+ const unmarshalListInstanceGroupsResponse = (data) => {
173
+ if (!isJSONObject(data)) {
174
+ throw new TypeError(
175
+ `Unmarshalling the type 'ListInstanceGroupsResponse' failed as data isn't a dictionary.`
176
+ );
177
+ }
178
+ return {
179
+ instanceGroups: unmarshalArrayOfObject(
180
+ data.instance_groups,
181
+ unmarshalInstanceGroup
182
+ ),
183
+ totalCount: data.total_count
184
+ };
185
+ };
186
+ const unmarshalListInstancePoliciesResponse = (data) => {
187
+ if (!isJSONObject(data)) {
188
+ throw new TypeError(
189
+ `Unmarshalling the type 'ListInstancePoliciesResponse' failed as data isn't a dictionary.`
190
+ );
191
+ }
192
+ return {
193
+ policies: unmarshalArrayOfObject(data.policies, unmarshalInstancePolicy),
194
+ totalCount: data.total_count
195
+ };
196
+ };
197
+ const unmarshalListInstanceTemplatesResponse = (data) => {
198
+ if (!isJSONObject(data)) {
199
+ throw new TypeError(
200
+ `Unmarshalling the type 'ListInstanceTemplatesResponse' failed as data isn't a dictionary.`
201
+ );
202
+ }
203
+ return {
204
+ instanceTemplates: unmarshalArrayOfObject(
205
+ data.instance_templates,
206
+ unmarshalInstanceTemplate
207
+ ),
208
+ totalCount: data.total_count
209
+ };
210
+ };
211
+ const marshalCapacity = (request, defaults) => ({
212
+ cooldown_delay: request.cooldownDelay,
213
+ max_replicas: request.maxReplicas,
214
+ min_replicas: request.minReplicas
215
+ });
216
+ const marshalLoadbalancer = (request, defaults) => ({
217
+ backend_ids: request.backendIds,
218
+ id: request.id,
219
+ private_network_id: request.privateNetworkId
220
+ });
221
+ const marshalCreateInstanceGroupRequest = (request, defaults) => ({
222
+ capacity: marshalCapacity(request.capacity),
223
+ loadbalancer: marshalLoadbalancer(request.loadbalancer),
224
+ name: request.name,
225
+ project_id: request.projectId ?? defaults.defaultProjectId,
226
+ tags: request.tags,
227
+ template_id: request.templateId
228
+ });
229
+ const marshalMetric = (request, defaults) => ({
230
+ aggregate: request.aggregate,
231
+ name: request.name,
232
+ operator: request.operator,
233
+ sampling_range_min: request.samplingRangeMin,
234
+ threshold: request.threshold,
235
+ ...resolveOneOf([
236
+ { param: "managed_metric", value: request.managedMetric },
237
+ { param: "cockpit_metric_name", value: request.cockpitMetricName }
238
+ ])
239
+ });
240
+ const marshalCreateInstancePolicyRequest = (request, defaults) => ({
241
+ action: request.action,
242
+ instance_group_id: request.instanceGroupId,
243
+ name: request.name,
244
+ priority: request.priority,
245
+ type: request.type,
246
+ value: request.value,
247
+ ...resolveOneOf([
248
+ {
249
+ param: "metric",
250
+ value: request.metric !== void 0 ? marshalMetric(request.metric) : void 0
251
+ }
252
+ ])
253
+ });
254
+ const marshalVolumeInstanceTemplateFromEmpty = (request, defaults) => ({
255
+ size: request.size
256
+ });
257
+ const marshalVolumeInstanceTemplateFromSnapshot = (request, defaults) => ({
258
+ size: request.size,
259
+ snapshot_id: request.snapshotId
260
+ });
261
+ const marshalVolumeInstanceTemplate = (request, defaults) => ({
262
+ boot: request.boot,
263
+ name: request.name,
264
+ tags: request.tags,
265
+ volume_type: request.volumeType,
266
+ ...resolveOneOf([
267
+ {
268
+ param: "from_empty",
269
+ value: request.fromEmpty !== void 0 ? marshalVolumeInstanceTemplateFromEmpty(request.fromEmpty) : void 0
270
+ },
271
+ {
272
+ param: "from_snapshot",
273
+ value: request.fromSnapshot !== void 0 ? marshalVolumeInstanceTemplateFromSnapshot(
274
+ request.fromSnapshot
275
+ ) : void 0
276
+ }
277
+ ]),
278
+ ...resolveOneOf([{ param: "perf_iops", value: request.perfIops }])
279
+ });
280
+ const marshalCreateInstanceTemplateRequest = (request, defaults) => ({
281
+ cloud_init: request.cloudInit,
282
+ commercial_type: request.commercialType,
283
+ image_id: request.imageId,
284
+ name: request.name,
285
+ placement_group_id: request.placementGroupId,
286
+ private_network_ids: request.privateNetworkIds,
287
+ project_id: request.projectId ?? defaults.defaultProjectId,
288
+ public_ips_v4_count: request.publicIpsV4Count,
289
+ public_ips_v6_count: request.publicIpsV6Count,
290
+ security_group_id: request.securityGroupId,
291
+ tags: request.tags,
292
+ volumes: Object.entries(request.volumes).reduce(
293
+ (acc, [key, value]) => ({
294
+ ...acc,
295
+ [key]: marshalVolumeInstanceTemplate(value)
296
+ }),
297
+ {}
298
+ )
299
+ });
300
+ const marshalUpdateInstanceGroupRequestCapacity = (request, defaults) => ({
301
+ cooldown_delay: request.cooldownDelay,
302
+ max_replicas: request.maxReplicas,
303
+ min_replicas: request.minReplicas
304
+ });
305
+ const marshalUpdateInstanceGroupRequestLoadbalancer = (request, defaults) => ({
306
+ backend_ids: request.backendIds
307
+ });
308
+ const marshalUpdateInstanceGroupRequest = (request, defaults) => ({
309
+ capacity: request.capacity !== void 0 ? marshalUpdateInstanceGroupRequestCapacity(request.capacity) : void 0,
310
+ loadbalancer: request.loadbalancer !== void 0 ? marshalUpdateInstanceGroupRequestLoadbalancer(
311
+ request.loadbalancer
312
+ ) : void 0,
313
+ name: request.name,
314
+ tags: request.tags
315
+ });
316
+ const marshalUpdateInstancePolicyRequestMetric = (request, defaults) => ({
317
+ aggregate: request.aggregate,
318
+ name: request.name,
319
+ operator: request.operator,
320
+ sampling_range_min: request.samplingRangeMin,
321
+ threshold: request.threshold,
322
+ ...resolveOneOf([
323
+ { param: "managed_metric", value: request.managedMetric },
324
+ { param: "cockpit_metric_name", value: request.cockpitMetricName }
325
+ ])
326
+ });
327
+ const marshalUpdateInstancePolicyRequest = (request, defaults) => ({
328
+ action: request.action,
329
+ name: request.name,
330
+ priority: request.priority,
331
+ type: request.type,
332
+ value: request.value,
333
+ ...resolveOneOf([
334
+ {
335
+ param: "metric",
336
+ value: request.metric !== void 0 ? marshalUpdateInstancePolicyRequestMetric(request.metric) : void 0
337
+ }
338
+ ])
339
+ });
340
+ const marshalUpdateInstanceTemplateRequest = (request, defaults) => ({
341
+ cloud_init: request.cloudInit,
342
+ commercial_type: request.commercialType,
343
+ image_id: request.imageId,
344
+ name: request.name,
345
+ placement_group_id: request.placementGroupId,
346
+ private_network_ids: request.privateNetworkIds,
347
+ public_ips_v4_count: request.publicIpsV4Count,
348
+ public_ips_v6_count: request.publicIpsV6Count,
349
+ security_group_id: request.securityGroupId,
350
+ tags: request.tags,
351
+ volumes: request.volumes !== void 0 ? Object.entries(request.volumes).reduce(
352
+ (acc, [key, value]) => ({
353
+ ...acc,
354
+ [key]: marshalVolumeInstanceTemplate(value)
355
+ }),
356
+ {}
357
+ ) : void 0
358
+ });
359
+ export {
360
+ marshalCreateInstanceGroupRequest,
361
+ marshalCreateInstancePolicyRequest,
362
+ marshalCreateInstanceTemplateRequest,
363
+ marshalUpdateInstanceGroupRequest,
364
+ marshalUpdateInstancePolicyRequest,
365
+ marshalUpdateInstanceTemplateRequest,
366
+ unmarshalInstanceGroup,
367
+ unmarshalInstancePolicy,
368
+ unmarshalInstanceTemplate,
369
+ unmarshalListInstanceGroupEventsResponse,
370
+ unmarshalListInstanceGroupsResponse,
371
+ unmarshalListInstancePoliciesResponse,
372
+ unmarshalListInstanceTemplatesResponse
373
+ };