@scaleway/sdk-instance 1.3.0 → 2.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.
@@ -1,277 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const sdkClient = require("@scaleway/sdk-client");
4
- const api_gen = require("./api.gen.cjs");
5
- const content_gen = require("./content.gen.cjs");
6
- const validateNotUndefined = (obj) => {
7
- if (obj === void 0) throw new TypeError(`object was found undefined`);
8
- return obj;
9
- };
10
- class InstanceV1UtilsAPI extends api_gen.API {
11
- /**
12
- * Waits for {@link Image} to be in a final state.
13
- *
14
- * @param request - The request {@link GetImageRequest}
15
- * @param options - The waiting options
16
- * @returns A Promise of Image
17
- */
18
- waitForImage = (request, options) => sdkClient.tryAtIntervals(
19
- async () => {
20
- const value = await this.getImage(request).then(
21
- (res) => res.image
22
- );
23
- return {
24
- done: !content_gen.IMAGE_TRANSIENT_STATUSES.includes(value.state),
25
- value
26
- };
27
- },
28
- sdkClient.createExponentialBackoffStrategy(
29
- options?.minDelay ?? 1,
30
- options?.maxDelay ?? 30
31
- ),
32
- options?.timeout
33
- );
34
- /**
35
- * Waits for {@link PrivateNIC} to be in a final state.
36
- *
37
- * @param request - The request {@link GetPrivateNICRequest}
38
- * @param options - The waiting options
39
- * @returns A Promise of PrivateNIC
40
- */
41
- waitForPrivateNIC = (request, options) => sdkClient.tryAtIntervals(
42
- async () => {
43
- const value = await this.getPrivateNIC(request).then(
44
- (res) => res.privateNic
45
- );
46
- return {
47
- done: !content_gen.PRIVATE_NIC_TRANSIENT_STATUSES.includes(value.state),
48
- value
49
- };
50
- },
51
- sdkClient.createExponentialBackoffStrategy(
52
- options?.minDelay ?? 1,
53
- options?.maxDelay ?? 30
54
- ),
55
- options?.timeout
56
- );
57
- /**
58
- * Waits for {@link Server} to be in a final state.
59
- *
60
- * @param request - The request {@link GetServerRequest}
61
- * @param options - The waiting options
62
- * @returns A Promise of Server
63
- */
64
- waitForServer = (request, options) => sdkClient.tryAtIntervals(
65
- async () => {
66
- const value = await this.getServer(request).then(
67
- (res) => res.server
68
- );
69
- return {
70
- done: !content_gen.SERVER_TRANSIENT_STATUSES.includes(value.state),
71
- value
72
- };
73
- },
74
- sdkClient.createExponentialBackoffStrategy(
75
- options?.minDelay ?? 1,
76
- options?.maxDelay ?? 30
77
- ),
78
- options?.timeout
79
- );
80
- /**
81
- * Waits for {@link Server} to be in a final state.
82
- *
83
- * @param request - The request {@link GetServerRequest}
84
- * @param options - The waiting options
85
- * @returns A Promise of Server
86
- */
87
- waitForSnapshot = (request, options) => sdkClient.tryAtIntervals(
88
- async () => {
89
- const value = await this.getSnapshot(request).then(
90
- (res) => res.snapshot
91
- );
92
- return {
93
- done: !content_gen.SNAPSHOT_TRANSIENT_STATUSES.includes(value.state),
94
- value
95
- };
96
- },
97
- sdkClient.createExponentialBackoffStrategy(
98
- options?.minDelay ?? 1,
99
- options?.maxDelay ?? 30
100
- ),
101
- options?.timeout
102
- );
103
- /**
104
- * Waits for {@link Volume} to be in a final state.
105
- *
106
- * @param request - The request {@link GetVolumeRequest}
107
- * @param options - The waiting options
108
- * @returns A Promise of Volume
109
- */
110
- waitForVolume = (request, options) => sdkClient.tryAtIntervals(
111
- async () => {
112
- const value = await this.getVolume(request).then(
113
- (res) => res.volume
114
- );
115
- return {
116
- done: !content_gen.VOLUME_TRANSIENT_STATUSES.includes(value.state),
117
- value
118
- };
119
- },
120
- sdkClient.createExponentialBackoffStrategy(
121
- options?.minDelay ?? 1,
122
- options?.maxDelay ?? 30
123
- ),
124
- options?.timeout
125
- );
126
- /**
127
- * Updates a server.
128
- *
129
- * @param request - The request {@link UpdateServerRequest}
130
- * @returns A Promise of UpdateServerResponse
131
- */
132
- updateServer = (request) => this._updateServer(request);
133
- /**
134
- * Creates a server.
135
- *
136
- * @param request - The request {@link CreateServerRequest}
137
- * @returns A Promise of CreateServerResponse
138
- */
139
- createServer = (request) => this._createServer(request);
140
- /**
141
- * Starts an action and wait for the server to be in the correct "terminal
142
- * state" expected by this action.
143
- *
144
- * @param request - The request {@link ServerActionRequest}
145
- * @returns A Promise of Server
146
- */
147
- serverActionAndWait = async (request, options) => {
148
- const finalServer = await this.serverAction(request).then(
149
- () => this.waitForServer(
150
- {
151
- serverId: request.serverId,
152
- zone: request.zone
153
- },
154
- options
155
- )
156
- );
157
- let expectedState;
158
- switch (request.action) {
159
- case "poweron":
160
- case "reboot":
161
- expectedState = "running";
162
- break;
163
- case "poweroff":
164
- expectedState = "stopped";
165
- break;
166
- case "stop_in_place":
167
- expectedState = "stopped in place";
168
- break;
169
- }
170
- if (expectedState && finalServer.state !== expectedState) {
171
- throw new Error(
172
- `expected state ${expectedState} but found ${finalServer.state}: ${finalServer.stateDetail}`
173
- );
174
- }
175
- return finalServer;
176
- };
177
- /**
178
- * Attaches a volume to a server.
179
- *
180
- * @param request - The request {@link AttachVolumeRequest}
181
- * @returns A Promise of AttachVolumeResponse
182
- */
183
- attachVolume = async (request) => {
184
- const volumes = await this.getServer({
185
- serverId: request.serverId,
186
- zone: request.zone
187
- }).then((res) => validateNotUndefined(res.server?.volumes));
188
- const newVolumes = {};
189
- for (const [key, server] of Object.entries(volumes)) {
190
- newVolumes[key] = { id: server.id, name: server.name };
191
- }
192
- let found = false;
193
- const volumesLength = Object.keys(volumes).length;
194
- for (let index = 0; index <= volumesLength; index += 1) {
195
- const key = index.toString();
196
- if (!(key in newVolumes)) {
197
- newVolumes[key] = {
198
- id: request.volumeId,
199
- name: request.volumeId
200
- // name is ignored on this PATCH
201
- };
202
- found = true;
203
- break;
204
- }
205
- }
206
- if (!found) {
207
- throw new Error(`could not find key to attach volume ${request.volumeId}`);
208
- }
209
- return this.updateServer({
210
- serverId: request.serverId,
211
- volumes: newVolumes,
212
- zone: request.zone
213
- }).then((obj) => obj);
214
- };
215
- /**
216
- * Detaches a volume from a server.
217
- *
218
- * @param request - The request {@link DetachVolumeRequest}
219
- * @returns A Promise of DetachVolumeResponse
220
- */
221
- detachVolume = async (request) => {
222
- const server = await this.getVolume({
223
- volumeId: request.volumeId,
224
- zone: request.zone
225
- }).then((res) => validateNotUndefined(res.volume?.server?.id)).then(
226
- (serverId) => this.getServer({
227
- serverId,
228
- zone: request.zone
229
- })
230
- ).then((res) => validateNotUndefined(res.server));
231
- const newVolumes = {};
232
- for (const [key, volume] of Object.entries(server.volumes)) {
233
- if (volume.id !== request.volumeId) {
234
- newVolumes[key] = { id: volume.id, name: volume.name };
235
- }
236
- }
237
- return this.updateServer({
238
- serverId: server.id,
239
- volumes: newVolumes,
240
- zone: request.zone
241
- }).then((obj) => obj);
242
- };
243
- /**
244
- * Get the content of a user data on a server for the given key.
245
- *
246
- * @param request - The request {@link GetServerUserDataRequest}
247
- * @returns The content of the key
248
- */
249
- getServerUserData = (request) => this.client.fetch({
250
- method: "GET",
251
- path: `/instance/v1/zones/${sdkClient.validatePathParam(
252
- "zone",
253
- request.zone ?? this.client.settings.defaultZone
254
- )}/servers/${sdkClient.validatePathParam(
255
- "serverId",
256
- request.serverId
257
- )}/user_data/${sdkClient.validatePathParam("key", request.key)}`
258
- });
259
- /**
260
- * Sets the content of a user data on a server for the given key.
261
- *
262
- * @param request - The request {@link SetServerUserDataRequest}
263
- */
264
- setServerUserData = (request) => this.client.fetch({
265
- body: request.content,
266
- headers: { "Content-Type": "text/plain" },
267
- method: "PATCH",
268
- path: `/instance/v1/zones/${sdkClient.validatePathParam(
269
- "zone",
270
- request.zone ?? this.client.settings.defaultZone
271
- )}/servers/${sdkClient.validatePathParam(
272
- "serverId",
273
- request.serverId
274
- )}/user_data/${sdkClient.validatePathParam("key", request.key)}`
275
- });
276
- }
277
- exports.InstanceV1UtilsAPI = InstanceV1UtilsAPI;
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const IMAGE_TRANSIENT_STATUSES = ["creating"];
4
- const IP_TRANSIENT_STATUSES = ["pending"];
5
- const PRIVATE_NIC_TRANSIENT_STATUSES = ["syncing"];
6
- const SECURITY_GROUP_TRANSIENT_STATUSES = [
7
- "syncing"
8
- ];
9
- const SERVER_FILESYSTEM_TRANSIENT_STATUSES = [
10
- "attaching",
11
- "detaching"
12
- ];
13
- const SERVER_IP_TRANSIENT_STATUSES = ["pending"];
14
- const SERVER_TRANSIENT_STATUSES = ["starting", "stopping"];
15
- const SNAPSHOT_TRANSIENT_STATUSES = [
16
- "snapshotting",
17
- "importing",
18
- "exporting"
19
- ];
20
- const TASK_TRANSIENT_STATUSES = [
21
- "pending",
22
- "started",
23
- "retry"
24
- ];
25
- const VOLUME_SERVER_TRANSIENT_STATUSES = [
26
- "snapshotting",
27
- "resizing",
28
- "fetching",
29
- "saving",
30
- "hotsyncing",
31
- "attaching"
32
- ];
33
- const VOLUME_TRANSIENT_STATUSES = [
34
- "snapshotting",
35
- "fetching",
36
- "saving",
37
- "attaching",
38
- "resizing",
39
- "hotsyncing"
40
- ];
41
- exports.IMAGE_TRANSIENT_STATUSES = IMAGE_TRANSIENT_STATUSES;
42
- exports.IP_TRANSIENT_STATUSES = IP_TRANSIENT_STATUSES;
43
- exports.PRIVATE_NIC_TRANSIENT_STATUSES = PRIVATE_NIC_TRANSIENT_STATUSES;
44
- exports.SECURITY_GROUP_TRANSIENT_STATUSES = SECURITY_GROUP_TRANSIENT_STATUSES;
45
- exports.SERVER_FILESYSTEM_TRANSIENT_STATUSES = SERVER_FILESYSTEM_TRANSIENT_STATUSES;
46
- exports.SERVER_IP_TRANSIENT_STATUSES = SERVER_IP_TRANSIENT_STATUSES;
47
- exports.SERVER_TRANSIENT_STATUSES = SERVER_TRANSIENT_STATUSES;
48
- exports.SNAPSHOT_TRANSIENT_STATUSES = SNAPSHOT_TRANSIENT_STATUSES;
49
- exports.TASK_TRANSIENT_STATUSES = TASK_TRANSIENT_STATUSES;
50
- exports.VOLUME_SERVER_TRANSIENT_STATUSES = VOLUME_SERVER_TRANSIENT_STATUSES;
51
- exports.VOLUME_TRANSIENT_STATUSES = VOLUME_TRANSIENT_STATUSES;
package/dist/v1/index.cjs DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const api_utils = require("./api.utils.cjs");
4
- const content_gen = require("./content.gen.cjs");
5
- exports.API = api_utils.InstanceV1UtilsAPI;
6
- exports.IMAGE_TRANSIENT_STATUSES = content_gen.IMAGE_TRANSIENT_STATUSES;
7
- exports.IP_TRANSIENT_STATUSES = content_gen.IP_TRANSIENT_STATUSES;
8
- exports.PRIVATE_NIC_TRANSIENT_STATUSES = content_gen.PRIVATE_NIC_TRANSIENT_STATUSES;
9
- exports.SECURITY_GROUP_TRANSIENT_STATUSES = content_gen.SECURITY_GROUP_TRANSIENT_STATUSES;
10
- exports.SERVER_FILESYSTEM_TRANSIENT_STATUSES = content_gen.SERVER_FILESYSTEM_TRANSIENT_STATUSES;
11
- exports.SERVER_IP_TRANSIENT_STATUSES = content_gen.SERVER_IP_TRANSIENT_STATUSES;
12
- exports.SERVER_TRANSIENT_STATUSES = content_gen.SERVER_TRANSIENT_STATUSES;
13
- exports.SNAPSHOT_TRANSIENT_STATUSES = content_gen.SNAPSHOT_TRANSIENT_STATUSES;
14
- exports.TASK_TRANSIENT_STATUSES = content_gen.TASK_TRANSIENT_STATUSES;
15
- exports.VOLUME_SERVER_TRANSIENT_STATUSES = content_gen.VOLUME_SERVER_TRANSIENT_STATUSES;
16
- exports.VOLUME_TRANSIENT_STATUSES = content_gen.VOLUME_TRANSIENT_STATUSES;