@scaleway/sdk 1.14.0 → 1.15.0
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.
- package/dist/api/account/v2/api.gen.js +77 -60
- package/dist/api/applesilicon/v1alpha1/api.gen.js +174 -152
- package/dist/api/baremetal/v1/api.gen.js +434 -378
- package/dist/api/baremetal/v1/api.utils.js +19 -22
- package/dist/api/billing/v2alpha1/api.gen.js +21 -17
- package/dist/api/cockpit/v1beta1/api.gen.js +308 -232
- package/dist/api/container/v1beta1/api.gen.js +384 -337
- package/dist/api/domain/v2beta1/api.gen.js +754 -668
- package/dist/api/flexibleip/v1alpha1/api.gen.js +164 -151
- package/dist/api/function/v1beta1/api.gen.js +467 -407
- package/dist/api/iam/v1alpha1/api.gen.js +641 -557
- package/dist/api/instance/v1/api.gen.js +802 -677
- package/dist/api/instance/v1/api.utils.js +337 -325
- package/dist/api/instance/v1/marshalling.gen.js +2 -1
- package/dist/api/iot/v1/api.gen.js +508 -452
- package/dist/api/ipfs/index.js +2 -0
- package/dist/api/ipfs/v1alpha1/api.gen.js +197 -0
- package/dist/api/ipfs/v1alpha1/content.gen.js +7 -0
- package/dist/api/ipfs/v1alpha1/index.gen.js +5 -0
- package/dist/api/ipfs/v1alpha1/marshalling.gen.js +125 -0
- package/dist/api/k8s/v1/api.gen.js +403 -342
- package/dist/api/k8s/v1/api.utils.js +7 -10
- package/dist/api/k8s/v1/marshalling.gen.js +19 -1
- package/dist/api/k8s/v1/validation-rules.gen.js +10 -1
- package/dist/api/lb/v1/api.gen.js +1501 -1363
- package/dist/api/lb/v1/api.utils.js +71 -75
- package/dist/api/lb/v1/marshalling.gen.js +6 -0
- package/dist/api/marketplace/v1/api.gen.js +35 -32
- package/dist/api/marketplace/v2/api.gen.js +117 -102
- package/dist/api/mnq/v1alpha1/api.gen.js +154 -137
- package/dist/api/rdb/v1/api.gen.js +897 -819
- package/dist/api/redis/v1/api.gen.js +358 -333
- package/dist/api/registry/v1/api.gen.js +211 -189
- package/dist/api/secret/v1alpha1/api.gen.js +265 -245
- package/dist/api/tem/v1alpha1/api.gen.js +182 -147
- package/dist/api/tem/v1alpha1/marshalling.gen.js +32 -1
- package/dist/api/test/v1/api.gen.js +116 -104
- package/dist/api/vpc/v1/api.gen.js +74 -65
- package/dist/api/vpc/v2/api.gen.js +200 -178
- package/dist/api/vpc/v2/marshalling.gen.js +1 -0
- package/dist/api/vpcgw/v1/api.gen.js +575 -501
- package/dist/api/webhosting/v1alpha1/api.gen.js +127 -117
- package/dist/index.cjs +732 -311
- package/dist/index.d.ts +2040 -1540
- package/dist/index.js +28 -26
- package/dist/internal/logger/console-logger.js +4 -5
- package/dist/scw/constants.js +1 -1
- package/dist/scw/errors/scw-error.js +2 -2
- package/package.json +2 -2
|
@@ -10,348 +10,360 @@ const validateNotUndefined = obj => {
|
|
|
10
10
|
return obj;
|
|
11
11
|
};
|
|
12
12
|
class InstanceV1UtilsAPI extends API {
|
|
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
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Waits for {@link Image} to be in a final state.
|
|
15
|
+
*
|
|
16
|
+
* @param request - The request {@link GetImageRequest}
|
|
17
|
+
* @param options - The waiting options
|
|
18
|
+
* @returns A Promise of Image
|
|
19
|
+
*/
|
|
20
|
+
waitForImage = (request, options) => tryAtIntervals(async () => {
|
|
21
|
+
const value = await this.getImage(request).then(res => res.image);
|
|
22
|
+
return {
|
|
23
|
+
done: !IMAGE_TRANSIENT_STATUSES.includes(value.state),
|
|
24
|
+
value
|
|
25
|
+
};
|
|
26
|
+
}, createExponentialBackoffStrategy(options?.minDelay ?? 1, options?.maxDelay ?? 30), options?.timeout);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Waits for {@link PrivateNIC} to be in a final state.
|
|
30
|
+
*
|
|
31
|
+
* @param request - The request {@link GetPrivateNICRequest}
|
|
32
|
+
* @param options - The waiting options
|
|
33
|
+
* @returns A Promise of PrivateNIC
|
|
34
|
+
*/
|
|
35
|
+
waitForPrivateNIC = (request, options) => tryAtIntervals(async () => {
|
|
36
|
+
const value = await this.getPrivateNIC(request).then(res => res.privateNic);
|
|
37
|
+
return {
|
|
38
|
+
done: !PRIVATE_NIC_TRANSIENT_STATUSES.includes(value.state),
|
|
39
|
+
value
|
|
40
|
+
};
|
|
41
|
+
}, createExponentialBackoffStrategy(options?.minDelay ?? 1, options?.maxDelay ?? 30), options?.timeout);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Waits for {@link Server} to be in a final state.
|
|
45
|
+
*
|
|
46
|
+
* @param request - The request {@link GetServerRequest}
|
|
47
|
+
* @param options - The waiting options
|
|
48
|
+
* @returns A Promise of Server
|
|
49
|
+
*/
|
|
50
|
+
waitForServer = (request, options) => tryAtIntervals(async () => {
|
|
51
|
+
const value = await this.getServer(request).then(res => res.server);
|
|
52
|
+
return {
|
|
53
|
+
done: !SERVER_TRANSIENT_STATUSES.includes(value.state),
|
|
54
|
+
value
|
|
55
|
+
};
|
|
56
|
+
}, createExponentialBackoffStrategy(options?.minDelay ?? 1, options?.maxDelay ?? 30), options?.timeout);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Waits for {@link Server} to be in a final state.
|
|
60
|
+
*
|
|
61
|
+
* @param request - The request {@link GetServerRequest}
|
|
62
|
+
* @param options - The waiting options
|
|
63
|
+
* @returns A Promise of Server
|
|
64
|
+
*/
|
|
65
|
+
waitForSnapshot = (request, options) => tryAtIntervals(async () => {
|
|
66
|
+
const value = await this.getSnapshot(request).then(res => res.snapshot);
|
|
67
|
+
return {
|
|
68
|
+
done: !SNAPSHOT_TRANSIENT_STATUSES.includes(value.state),
|
|
69
|
+
value
|
|
70
|
+
};
|
|
71
|
+
}, createExponentialBackoffStrategy(options?.minDelay ?? 1, options?.maxDelay ?? 30), options?.timeout);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Waits for {@link Volume} to be in a final state.
|
|
75
|
+
*
|
|
76
|
+
* @param request - The request {@link GetVolumeRequest}
|
|
77
|
+
* @param options - The waiting options
|
|
78
|
+
* @returns A Promise of Volume
|
|
79
|
+
*/
|
|
80
|
+
waitForVolume = (request, options) => tryAtIntervals(async () => {
|
|
81
|
+
const value = await this.getVolume(request).then(res => res.volume);
|
|
82
|
+
return {
|
|
83
|
+
done: !VOLUME_TRANSIENT_STATUSES.includes(value.state),
|
|
84
|
+
value
|
|
85
|
+
};
|
|
86
|
+
}, createExponentialBackoffStrategy(options?.minDelay ?? 1, options?.maxDelay ?? 30), options?.timeout);
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Updates a snapshot.
|
|
90
|
+
*
|
|
91
|
+
* @param request - The request {@link UpdateSnapshotRequest}
|
|
92
|
+
* @returns A Promise of UpdateSnapshotResponse
|
|
93
|
+
*/
|
|
94
|
+
updateSnapshot = request => this.getSnapshot(request).then(res => validateNotUndefined(res.snapshot)).then(snapshot => this._setSnapshot({
|
|
95
|
+
...snapshot,
|
|
96
|
+
name: request.name ?? snapshot.name,
|
|
97
|
+
snapshotId: snapshot.id
|
|
98
|
+
})).then(res => ({
|
|
99
|
+
snapshot: res.snapshot
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Updates a security group.
|
|
104
|
+
*
|
|
105
|
+
* @param request - The request {@link UpdateSecurityGroupRequest}
|
|
106
|
+
* @returns A Promise of UpdateSecurityGroupResponse
|
|
107
|
+
*/
|
|
108
|
+
updateSecurityGroup = request => this.getSecurityGroup({
|
|
109
|
+
securityGroupId: request.securityGroupId,
|
|
110
|
+
zone: request.zone
|
|
111
|
+
}).then(res => validateNotUndefined(res.securityGroup)).then(securityGroup => this._setSecurityGroup({
|
|
112
|
+
creationDate: securityGroup.creationDate,
|
|
113
|
+
description: request.description ?? securityGroup.description,
|
|
114
|
+
enableDefaultSecurity: request.enableDefaultSecurity ?? securityGroup.enableDefaultSecurity,
|
|
115
|
+
id: securityGroup.id,
|
|
116
|
+
inboundDefaultPolicy: request.inboundDefaultPolicy ?? securityGroup.inboundDefaultPolicy,
|
|
117
|
+
modificationDate: securityGroup.modificationDate,
|
|
118
|
+
name: request.name ?? securityGroup.name,
|
|
119
|
+
organization: securityGroup.organization,
|
|
120
|
+
organizationDefault: request.organizationDefault ?? securityGroup.organizationDefault,
|
|
121
|
+
outboundDefaultPolicy: request.outboundDefaultPolicy ?? securityGroup.outboundDefaultPolicy,
|
|
122
|
+
project: securityGroup.project,
|
|
123
|
+
projectDefault: request.projectDefault ?? securityGroup.projectDefault,
|
|
124
|
+
servers: securityGroup.servers,
|
|
125
|
+
stateful: request.stateful ?? securityGroup.stateful,
|
|
126
|
+
zone: request.zone
|
|
127
|
+
})).then(res => ({
|
|
128
|
+
securityGroup: res.securityGroup
|
|
129
|
+
}));
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Updates a security group rule.
|
|
133
|
+
*
|
|
134
|
+
* @param request - The request {@link UpdateSecurityGroupRuleRequest}
|
|
135
|
+
* @returns A Promise of UpdateSecurityGroupRuleResponse
|
|
136
|
+
*/
|
|
137
|
+
updateSecurityGroupRule = request => this.getSecurityGroupRule({
|
|
138
|
+
securityGroupId: request.securityGroupId,
|
|
139
|
+
securityGroupRuleId: request.securityGroupRuleId,
|
|
140
|
+
zone: request.zone
|
|
141
|
+
}).then(res => validateNotUndefined(res.rule)).then(rule => {
|
|
142
|
+
let sReq = {
|
|
143
|
+
action: request.action ?? rule.action,
|
|
144
|
+
destPortFrom: rule.destPortFrom,
|
|
145
|
+
destPortTo: rule.destPortTo,
|
|
146
|
+
direction: request.direction ?? rule.direction,
|
|
147
|
+
editable: rule.editable,
|
|
148
|
+
id: request.securityGroupRuleId,
|
|
149
|
+
ipRange: request.ipRange ?? rule.ipRange,
|
|
150
|
+
position: request.position ?? rule.position,
|
|
151
|
+
protocol: request.protocol ?? rule.protocol,
|
|
152
|
+
securityGroupId: request.securityGroupId,
|
|
153
|
+
securityGroupRuleId: request.securityGroupRuleId
|
|
154
|
+
};
|
|
155
|
+
if (request.destPortFrom) {
|
|
156
|
+
sReq = {
|
|
157
|
+
...sReq,
|
|
158
|
+
destPortFrom: request.destPortFrom > 0 ? request.destPortFrom : undefined
|
|
41
159
|
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* @param options - The waiting options
|
|
48
|
-
* @returns A Promise of Server
|
|
49
|
-
*/
|
|
50
|
-
this.waitForServer = (request, options) => tryAtIntervals(async () => {
|
|
51
|
-
const value = await this.getServer(request).then(res => res.server);
|
|
52
|
-
return {
|
|
53
|
-
done: !SERVER_TRANSIENT_STATUSES.includes(value.state),
|
|
54
|
-
value
|
|
160
|
+
}
|
|
161
|
+
if (request.destPortTo) {
|
|
162
|
+
sReq = {
|
|
163
|
+
...sReq,
|
|
164
|
+
destPortTo: request.destPortTo > 0 ? request.destPortTo : undefined
|
|
55
165
|
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* @param options - The waiting options
|
|
62
|
-
* @returns A Promise of Server
|
|
63
|
-
*/
|
|
64
|
-
this.waitForSnapshot = (request, options) => tryAtIntervals(async () => {
|
|
65
|
-
const value = await this.getSnapshot(request).then(res => res.snapshot);
|
|
66
|
-
return {
|
|
67
|
-
done: !SNAPSHOT_TRANSIENT_STATUSES.includes(value.state),
|
|
68
|
-
value
|
|
166
|
+
}
|
|
167
|
+
if (sReq.destPortFrom && sReq.destPortTo && sReq.destPortFrom === sReq.destPortTo) {
|
|
168
|
+
sReq = {
|
|
169
|
+
...sReq,
|
|
170
|
+
destPortTo: undefined
|
|
69
171
|
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*/
|
|
78
|
-
this.waitForVolume = (request, options) => tryAtIntervals(async () => {
|
|
79
|
-
const value = await this.getVolume(request).then(res => res.volume);
|
|
80
|
-
return {
|
|
81
|
-
done: !VOLUME_TRANSIENT_STATUSES.includes(value.state),
|
|
82
|
-
value
|
|
172
|
+
}
|
|
173
|
+
// When we use ICMP protocol portFrom and portTo should be set to nil
|
|
174
|
+
if (request.protocol === 'ICMP') {
|
|
175
|
+
sReq = {
|
|
176
|
+
...sReq,
|
|
177
|
+
destPortFrom: undefined,
|
|
178
|
+
destPortTo: undefined
|
|
83
179
|
};
|
|
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
|
-
organizationDefault: request.organizationDefault ?? securityGroup.organizationDefault,
|
|
117
|
-
outboundDefaultPolicy: request.outboundDefaultPolicy ?? securityGroup.outboundDefaultPolicy,
|
|
118
|
-
project: securityGroup.project,
|
|
119
|
-
projectDefault: request.projectDefault ?? securityGroup.projectDefault,
|
|
120
|
-
servers: securityGroup.servers,
|
|
121
|
-
stateful: request.stateful ?? securityGroup.stateful,
|
|
180
|
+
}
|
|
181
|
+
return this._setSecurityGroupRule(sReq);
|
|
182
|
+
}).then(res => ({
|
|
183
|
+
rule: res.rule
|
|
184
|
+
}));
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Updates a server.
|
|
188
|
+
*
|
|
189
|
+
* @param request - The request {@link UpdateServerRequest}
|
|
190
|
+
* @returns A Promise of UpdateServerResponse
|
|
191
|
+
*/
|
|
192
|
+
updateServer = request => this._updateServer(request);
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Creates a server.
|
|
196
|
+
*
|
|
197
|
+
* @param request - The request {@link CreateServerRequest}
|
|
198
|
+
* @returns A Promise of CreateServerResponse
|
|
199
|
+
*/
|
|
200
|
+
createServer = request => this._createServer(request);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Starts an action and wait for the server to be in the correct "terminal
|
|
204
|
+
* state" expected by this action.
|
|
205
|
+
*
|
|
206
|
+
* @param request - The request {@link ServerActionRequest}
|
|
207
|
+
* @returns A Promise of Server
|
|
208
|
+
*/
|
|
209
|
+
serverActionAndWait = async (request, options) => {
|
|
210
|
+
const finalServer = await this.serverAction(request).then(() => this.waitForServer({
|
|
211
|
+
serverId: request.serverId,
|
|
122
212
|
zone: request.zone
|
|
123
|
-
}))
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
213
|
+
}, options));
|
|
214
|
+
|
|
215
|
+
// Check the action was properly executed.
|
|
216
|
+
let expectedState;
|
|
217
|
+
switch (request.action) {
|
|
218
|
+
case 'poweron':
|
|
219
|
+
case 'reboot':
|
|
220
|
+
expectedState = 'running';
|
|
221
|
+
break;
|
|
222
|
+
case 'poweroff':
|
|
223
|
+
expectedState = 'stopped';
|
|
224
|
+
break;
|
|
225
|
+
case 'stop_in_place':
|
|
226
|
+
expectedState = 'stopped in place';
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
if (expectedState && finalServer.state !== expectedState) {
|
|
230
|
+
throw new Error(`expected state ${expectedState} but found ${finalServer.state}: ${finalServer.stateDetail}`);
|
|
231
|
+
}
|
|
232
|
+
return finalServer;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Attaches a volume to a server.
|
|
237
|
+
*
|
|
238
|
+
* @param request - The request {@link AttachVolumeRequest}
|
|
239
|
+
* @returns A Promise of AttachVolumeResponse
|
|
240
|
+
*/
|
|
241
|
+
attachVolume = async request => {
|
|
242
|
+
const volumes = await this.getServer({
|
|
243
|
+
serverId: request.serverId,
|
|
135
244
|
zone: request.zone
|
|
136
|
-
}).then(res => validateNotUndefined(res.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
editable: rule.editable,
|
|
143
|
-
id: request.securityGroupRuleId,
|
|
144
|
-
ipRange: request.ipRange ?? rule.ipRange,
|
|
145
|
-
position: request.position ?? rule.position,
|
|
146
|
-
protocol: request.protocol ?? rule.protocol,
|
|
147
|
-
securityGroupId: request.securityGroupId,
|
|
148
|
-
securityGroupRuleId: request.securityGroupRuleId
|
|
245
|
+
}).then(res => validateNotUndefined(res.server?.volumes));
|
|
246
|
+
const newVolumes = {};
|
|
247
|
+
for (const [key, server] of Object.entries(volumes)) {
|
|
248
|
+
newVolumes[key] = {
|
|
249
|
+
id: server.id,
|
|
250
|
+
name: server.name
|
|
149
251
|
};
|
|
150
|
-
|
|
151
|
-
sReq = {
|
|
152
|
-
...sReq,
|
|
153
|
-
destPortFrom: request.destPortFrom > 0 ? request.destPortFrom : undefined
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (request.destPortTo) {
|
|
157
|
-
sReq = {
|
|
158
|
-
...sReq,
|
|
159
|
-
destPortTo: request.destPortTo > 0 ? request.destPortTo : undefined
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
if (sReq.destPortFrom && sReq.destPortTo && sReq.destPortFrom === sReq.destPortTo) {
|
|
163
|
-
sReq = {
|
|
164
|
-
...sReq,
|
|
165
|
-
destPortTo: undefined
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
// When we use ICMP protocol portFrom and portTo should be set to nil
|
|
169
|
-
if (request.protocol === 'ICMP') {
|
|
170
|
-
sReq = {
|
|
171
|
-
...sReq,
|
|
172
|
-
destPortFrom: undefined,
|
|
173
|
-
destPortTo: undefined
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
return this._setSecurityGroupRule(sReq);
|
|
177
|
-
}).then(res => ({
|
|
178
|
-
rule: res.rule
|
|
179
|
-
}));
|
|
180
|
-
/**
|
|
181
|
-
* Updates a server.
|
|
182
|
-
*
|
|
183
|
-
* @param request - The request {@link UpdateServerRequest}
|
|
184
|
-
* @returns A Promise of UpdateServerResponse
|
|
185
|
-
*/
|
|
186
|
-
this.updateServer = request => this._updateServer(request);
|
|
187
|
-
/**
|
|
188
|
-
* Creates a server.
|
|
189
|
-
*
|
|
190
|
-
* @param request - The request {@link CreateServerRequest}
|
|
191
|
-
* @returns A Promise of CreateServerResponse
|
|
192
|
-
*/
|
|
193
|
-
this.createServer = request => this._createServer(request);
|
|
194
|
-
/**
|
|
195
|
-
* Starts an action and wait for the server to be in the correct "terminal
|
|
196
|
-
* state" expected by this action.
|
|
197
|
-
*
|
|
198
|
-
* @param request - The request {@link ServerActionRequest}
|
|
199
|
-
* @returns A Promise of Server
|
|
200
|
-
*/
|
|
201
|
-
this.serverActionAndWait = async (request, options) => {
|
|
202
|
-
const finalServer = await this.serverAction(request).then(() => this.waitForServer({
|
|
203
|
-
serverId: request.serverId,
|
|
204
|
-
zone: request.zone
|
|
205
|
-
}, options));
|
|
252
|
+
}
|
|
206
253
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
expectedState = 'stopped';
|
|
216
|
-
break;
|
|
217
|
-
case 'stop_in_place':
|
|
218
|
-
expectedState = 'stopped in place';
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
if (expectedState && finalServer.state !== expectedState) {
|
|
222
|
-
throw new Error(`expected state ${expectedState} but found ${finalServer.state}: ${finalServer.stateDetail}`);
|
|
223
|
-
}
|
|
224
|
-
return finalServer;
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Attaches a volume to a server.
|
|
228
|
-
*
|
|
229
|
-
* @param request - The request {@link AttachVolumeRequest}
|
|
230
|
-
* @returns A Promise of AttachVolumeResponse
|
|
231
|
-
*/
|
|
232
|
-
this.attachVolume = async request => {
|
|
233
|
-
const volumes = await this.getServer({
|
|
234
|
-
serverId: request.serverId,
|
|
235
|
-
zone: request.zone
|
|
236
|
-
}).then(res => validateNotUndefined(res.server?.volumes));
|
|
237
|
-
const newVolumes = {};
|
|
238
|
-
for (const [key, server] of Object.entries(volumes)) {
|
|
254
|
+
// We loop through all the possible volume keys (0 to len(volumes))
|
|
255
|
+
// to find a non existing key and assign it to the requested volume.
|
|
256
|
+
// A key should always be found. However we return an error if no keys were found.
|
|
257
|
+
let found = false;
|
|
258
|
+
const volumesLength = Object.keys(volumes).length;
|
|
259
|
+
for (let index = 0; index <= volumesLength; index += 1) {
|
|
260
|
+
const key = index.toString();
|
|
261
|
+
if (!(key in newVolumes)) {
|
|
239
262
|
newVolumes[key] = {
|
|
240
|
-
id:
|
|
241
|
-
name:
|
|
263
|
+
id: request.volumeId,
|
|
264
|
+
name: request.volumeId // name is ignored on this PATCH
|
|
242
265
|
};
|
|
266
|
+
|
|
267
|
+
found = true;
|
|
268
|
+
break;
|
|
243
269
|
}
|
|
270
|
+
}
|
|
271
|
+
if (!found) {
|
|
272
|
+
throw new Error(`could not find key to attach volume ${request.volumeId}`);
|
|
273
|
+
}
|
|
244
274
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
if (!(key in newVolumes)) {
|
|
253
|
-
newVolumes[key] = {
|
|
254
|
-
id: request.volumeId,
|
|
255
|
-
name: request.volumeId // name is ignored on this PATCH
|
|
256
|
-
};
|
|
275
|
+
// Update server
|
|
276
|
+
return this.updateServer({
|
|
277
|
+
serverId: request.serverId,
|
|
278
|
+
volumes: newVolumes,
|
|
279
|
+
zone: request.zone
|
|
280
|
+
}).then(obj => obj);
|
|
281
|
+
};
|
|
257
282
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
283
|
+
/**
|
|
284
|
+
* Detaches a volume from a server.
|
|
285
|
+
*
|
|
286
|
+
* @param request - The request {@link DetachVolumeRequest}
|
|
287
|
+
* @returns A Promise of DetachVolumeResponse
|
|
288
|
+
*/
|
|
289
|
+
detachVolume = async request => {
|
|
290
|
+
// Get server and related volumes.
|
|
291
|
+
const server = await this.getVolume({
|
|
292
|
+
volumeId: request.volumeId,
|
|
293
|
+
zone: request.zone
|
|
294
|
+
}).then(res => validateNotUndefined(res.volume?.server?.id)).then(serverId => this.getServer({
|
|
295
|
+
serverId,
|
|
296
|
+
zone: request.zone
|
|
297
|
+
})).then(res => validateNotUndefined(res.server));
|
|
298
|
+
|
|
299
|
+
// Remove volume.
|
|
300
|
+
const newVolumes = {};
|
|
301
|
+
for (const [key, volume] of Object.entries(server.volumes)) {
|
|
302
|
+
if (volume.id !== request.volumeId) {
|
|
303
|
+
newVolumes[key] = {
|
|
304
|
+
id: volume.id,
|
|
305
|
+
name: volume.name
|
|
306
|
+
};
|
|
264
307
|
}
|
|
308
|
+
}
|
|
265
309
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Detaches a volume from a server.
|
|
275
|
-
*
|
|
276
|
-
* @param request - The request {@link DetachVolumeRequest}
|
|
277
|
-
* @returns A Promise of DetachVolumeResponse
|
|
278
|
-
*/
|
|
279
|
-
this.detachVolume = async request => {
|
|
280
|
-
// Get server and related volumes.
|
|
281
|
-
const server = await this.getVolume({
|
|
282
|
-
volumeId: request.volumeId,
|
|
283
|
-
zone: request.zone
|
|
284
|
-
}).then(res => validateNotUndefined(res.volume?.server?.id)).then(serverId => this.getServer({
|
|
285
|
-
serverId,
|
|
286
|
-
zone: request.zone
|
|
287
|
-
})).then(res => validateNotUndefined(res.server));
|
|
310
|
+
// Update server.
|
|
311
|
+
return this.updateServer({
|
|
312
|
+
serverId: server.id,
|
|
313
|
+
volumes: newVolumes,
|
|
314
|
+
zone: request.zone
|
|
315
|
+
}).then(obj => obj);
|
|
316
|
+
};
|
|
288
317
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
318
|
+
/**
|
|
319
|
+
* Updates an image.
|
|
320
|
+
*
|
|
321
|
+
* @param request - The request {@link UpdateImageRequest}
|
|
322
|
+
* @returns A Promise of UpdateImageResponse
|
|
323
|
+
*/
|
|
324
|
+
updateImage = request => this.getImage({
|
|
325
|
+
zone: request.zone,
|
|
326
|
+
imageId: request.imageId
|
|
327
|
+
}).then(res => validateNotUndefined(res.image)).then(image => ({
|
|
328
|
+
...image,
|
|
329
|
+
name: request.name ?? image.name,
|
|
330
|
+
tags: request.tags ?? image.tags,
|
|
331
|
+
id: image.id
|
|
332
|
+
})).then(imageReq => this.client.fetch({
|
|
333
|
+
body: JSON.stringify(marshalSetImageRequestWithID(imageReq, this.client.settings)),
|
|
334
|
+
headers: {
|
|
335
|
+
'Content-Type': 'application/json; charset=utf-8'
|
|
336
|
+
},
|
|
337
|
+
method: 'PUT',
|
|
338
|
+
path: `/instance/v1/zones/${validatePathParam('zone', imageReq.zone)}/images/${validatePathParam('id', imageReq.id)}`
|
|
339
|
+
}, unmarshalSetImageResponse)).then(res => ({
|
|
340
|
+
image: res.image
|
|
341
|
+
}));
|
|
299
342
|
|
|
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
|
-
'Content-Type': 'application/json; charset=utf-8'
|
|
325
|
-
},
|
|
326
|
-
method: 'PUT',
|
|
327
|
-
path: `/instance/v1/zones/${validatePathParam('zone', imageReq.zone)}/images/${validatePathParam('id', imageReq.id)}`
|
|
328
|
-
}, unmarshalSetImageResponse)).then(res => ({
|
|
329
|
-
image: res.image
|
|
330
|
-
}));
|
|
331
|
-
/**
|
|
332
|
-
* Get the content of a user data on a server for the given key.
|
|
333
|
-
*
|
|
334
|
-
* @param request - The request {@link GetServerUserDataRequest}
|
|
335
|
-
* @returns The content of the key
|
|
336
|
-
*/
|
|
337
|
-
this.getServerUserData = request => this.client.fetch({
|
|
338
|
-
method: 'GET',
|
|
339
|
-
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/user_data/${validatePathParam('key', request.key)}`
|
|
340
|
-
});
|
|
341
|
-
/**
|
|
342
|
-
* Sets the content of a user data on a server for the given key.
|
|
343
|
-
*
|
|
344
|
-
* @param request - The request {@link SetServerUserDataRequest}
|
|
345
|
-
*/
|
|
346
|
-
this.setServerUserData = request => this.client.fetch({
|
|
347
|
-
body: request.content,
|
|
348
|
-
headers: {
|
|
349
|
-
'Content-Type': 'text/plain'
|
|
350
|
-
},
|
|
351
|
-
method: 'PATCH',
|
|
352
|
-
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/user_data/${validatePathParam('key', request.key)}`
|
|
353
|
-
});
|
|
354
|
-
}
|
|
343
|
+
/**
|
|
344
|
+
* Get the content of a user data on a server for the given key.
|
|
345
|
+
*
|
|
346
|
+
* @param request - The request {@link GetServerUserDataRequest}
|
|
347
|
+
* @returns The content of the key
|
|
348
|
+
*/
|
|
349
|
+
getServerUserData = request => this.client.fetch({
|
|
350
|
+
method: 'GET',
|
|
351
|
+
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/user_data/${validatePathParam('key', request.key)}`
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Sets the content of a user data on a server for the given key.
|
|
356
|
+
*
|
|
357
|
+
* @param request - The request {@link SetServerUserDataRequest}
|
|
358
|
+
*/
|
|
359
|
+
setServerUserData = request => this.client.fetch({
|
|
360
|
+
body: request.content,
|
|
361
|
+
headers: {
|
|
362
|
+
'Content-Type': 'text/plain'
|
|
363
|
+
},
|
|
364
|
+
method: 'PATCH',
|
|
365
|
+
path: `/instance/v1/zones/${validatePathParam('zone', request.zone ?? this.client.settings.defaultZone)}/servers/${validatePathParam('serverId', request.serverId)}/user_data/${validatePathParam('key', request.key)}`
|
|
366
|
+
});
|
|
355
367
|
}
|
|
356
368
|
|
|
357
369
|
export { InstanceV1UtilsAPI };
|