@scaleway/sdk 2.0.0-alpha.11 → 2.0.0-alpha.13

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.
Files changed (204) hide show
  1. package/package.json +2 -2
  2. package/dist/api/account/index.js +0 -4
  3. package/dist/api/account/v2/api.gen.js +0 -147
  4. package/dist/api/account/v2/index.gen.js +0 -4
  5. package/dist/api/account/v2/marshalling.gen.js +0 -39
  6. package/dist/api/account/v3/api.gen.js +0 -129
  7. package/dist/api/account/v3/index.gen.js +0 -6
  8. package/dist/api/account/v3/marshalling.gen.js +0 -39
  9. package/dist/api/account/v3/validation-rules.gen.js +0 -39
  10. package/dist/api/applesilicon/index.js +0 -2
  11. package/dist/api/applesilicon/v1alpha1/api.gen.js +0 -220
  12. package/dist/api/applesilicon/v1alpha1/content.gen.js +0 -7
  13. package/dist/api/applesilicon/v1alpha1/index.gen.js +0 -5
  14. package/dist/api/applesilicon/v1alpha1/marshalling.gen.js +0 -113
  15. package/dist/api/baremetal/index.js +0 -2
  16. package/dist/api/baremetal/v1/api.gen.js +0 -523
  17. package/dist/api/baremetal/v1/api.utils.js +0 -27
  18. package/dist/api/baremetal/v1/content.gen.js +0 -13
  19. package/dist/api/baremetal/v1/index.js +0 -5
  20. package/dist/api/baremetal/v1/marshalling.gen.js +0 -395
  21. package/dist/api/baremetal/v1/validation-rules.gen.js +0 -109
  22. package/dist/api/billing/index.js +0 -2
  23. package/dist/api/billing/v2alpha1/api.gen.js +0 -80
  24. package/dist/api/billing/v2alpha1/index.gen.js +0 -4
  25. package/dist/api/billing/v2alpha1/marshalling.gen.js +0 -53
  26. package/dist/api/block/index.js +0 -2
  27. package/dist/api/block/v1alpha1/api.gen.js +0 -245
  28. package/dist/api/block/v1alpha1/content.gen.js +0 -13
  29. package/dist/api/block/v1alpha1/index.gen.js +0 -7
  30. package/dist/api/block/v1alpha1/marshalling.gen.js +0 -175
  31. package/dist/api/block/v1alpha1/validation-rules.gen.js +0 -42
  32. package/dist/api/cockpit/index.js +0 -2
  33. package/dist/api/cockpit/v1beta1/api.gen.js +0 -448
  34. package/dist/api/cockpit/v1beta1/content.gen.js +0 -7
  35. package/dist/api/cockpit/v1beta1/index.gen.js +0 -5
  36. package/dist/api/cockpit/v1beta1/marshalling.gen.js +0 -220
  37. package/dist/api/container/index.js +0 -2
  38. package/dist/api/container/v1beta1/api.gen.js +0 -549
  39. package/dist/api/container/v1beta1/content.gen.js +0 -22
  40. package/dist/api/container/v1beta1/index.gen.js +0 -5
  41. package/dist/api/container/v1beta1/marshalling.gen.js +0 -330
  42. package/dist/api/document_db/index.js +0 -2
  43. package/dist/api/document_db/v1beta1/api.gen.js +0 -830
  44. package/dist/api/document_db/v1beta1/content.gen.js +0 -19
  45. package/dist/api/document_db/v1beta1/index.gen.js +0 -7
  46. package/dist/api/document_db/v1beta1/marshalling.gen.js +0 -580
  47. package/dist/api/document_db/v1beta1/validation-rules.gen.js +0 -10
  48. package/dist/api/domain/index.js +0 -2
  49. package/dist/api/domain/v2beta1/api.gen.js +0 -875
  50. package/dist/api/domain/v2beta1/content.gen.js +0 -28
  51. package/dist/api/domain/v2beta1/index.gen.js +0 -7
  52. package/dist/api/domain/v2beta1/marshalling.gen.js +0 -958
  53. package/dist/api/flexibleip/index.js +0 -2
  54. package/dist/api/flexibleip/v1alpha1/api.gen.js +0 -203
  55. package/dist/api/flexibleip/v1alpha1/content.gen.js +0 -10
  56. package/dist/api/flexibleip/v1alpha1/index.gen.js +0 -7
  57. package/dist/api/flexibleip/v1alpha1/marshalling.gen.js +0 -97
  58. package/dist/api/flexibleip/v1alpha1/validation-rules.gen.js +0 -14
  59. package/dist/api/function/index.js +0 -2
  60. package/dist/api/function/v1beta1/api.gen.js +0 -560
  61. package/dist/api/function/v1beta1/content.gen.js +0 -22
  62. package/dist/api/function/v1beta1/index.gen.js +0 -5
  63. package/dist/api/function/v1beta1/marshalling.gen.js +0 -368
  64. package/dist/api/iam/index.js +0 -2
  65. package/dist/api/iam/v1alpha1/api.gen.js +0 -799
  66. package/dist/api/iam/v1alpha1/index.gen.js +0 -6
  67. package/dist/api/iam/v1alpha1/marshalling.gen.js +0 -373
  68. package/dist/api/iam/v1alpha1/validation-rules.gen.js +0 -207
  69. package/dist/api/instance/index.js +0 -2
  70. package/dist/api/instance/v1/api.gen.js +0 -1003
  71. package/dist/api/instance/v1/api.utils.js +0 -369
  72. package/dist/api/instance/v1/content.gen.js +0 -31
  73. package/dist/api/instance/v1/index.js +0 -2
  74. package/dist/api/instance/v1/marshalling.gen.js +0 -1206
  75. package/dist/api/instance/v1/marshalling.utils.js +0 -63
  76. package/dist/api/iot/index.js +0 -2
  77. package/dist/api/iot/v1/api.gen.js +0 -581
  78. package/dist/api/iot/v1/content.gen.js +0 -7
  79. package/dist/api/iot/v1/index.gen.js +0 -5
  80. package/dist/api/iot/v1/marshalling.gen.js +0 -388
  81. package/dist/api/ipfs/index.js +0 -2
  82. package/dist/api/ipfs/v1alpha1/api.gen.js +0 -197
  83. package/dist/api/ipfs/v1alpha1/content.gen.js +0 -7
  84. package/dist/api/ipfs/v1alpha1/index.gen.js +0 -5
  85. package/dist/api/ipfs/v1alpha1/marshalling.gen.js +0 -121
  86. package/dist/api/k8s/index.js +0 -2
  87. package/dist/api/k8s/v1/api.gen.js +0 -454
  88. package/dist/api/k8s/v1/api.utils.js +0 -13
  89. package/dist/api/k8s/v1/content.gen.js +0 -13
  90. package/dist/api/k8s/v1/index.js +0 -4
  91. package/dist/api/k8s/v1/marshalling.gen.js +0 -333
  92. package/dist/api/k8s/v1/validation-rules.gen.js +0 -101
  93. package/dist/api/lb/index.js +0 -2
  94. package/dist/api/lb/v1/api.gen.js +0 -1669
  95. package/dist/api/lb/v1/api.utils.js +0 -81
  96. package/dist/api/lb/v1/content.gen.js +0 -16
  97. package/dist/api/lb/v1/index.js +0 -2
  98. package/dist/api/lb/v1/marshalling.gen.js +0 -923
  99. package/dist/api/marketplace/index.js +0 -4
  100. package/dist/api/marketplace/v1/api.gen.js +0 -60
  101. package/dist/api/marketplace/v1/index.gen.js +0 -4
  102. package/dist/api/marketplace/v1/marshalling.gen.js +0 -92
  103. package/dist/api/marketplace/v2/api.gen.js +0 -162
  104. package/dist/api/marketplace/v2/index.gen.js +0 -4
  105. package/dist/api/marketplace/v2/marshalling.gen.js +0 -94
  106. package/dist/api/mnq/index.js +0 -2
  107. package/dist/api/mnq/v1alpha1/api.gen.js +0 -205
  108. package/dist/api/mnq/v1alpha1/index.gen.js +0 -4
  109. package/dist/api/mnq/v1alpha1/marshalling.gen.js +0 -121
  110. package/dist/api/rdb/index.js +0 -2
  111. package/dist/api/rdb/v1/api.gen.js +0 -972
  112. package/dist/api/rdb/v1/content.gen.js +0 -22
  113. package/dist/api/rdb/v1/index.gen.js +0 -7
  114. package/dist/api/rdb/v1/marshalling.gen.js +0 -636
  115. package/dist/api/rdb/v1/validation-rules.gen.js +0 -10
  116. package/dist/api/redis/index.js +0 -2
  117. package/dist/api/redis/v1/api.gen.js +0 -389
  118. package/dist/api/redis/v1/content.gen.js +0 -7
  119. package/dist/api/redis/v1/index.gen.js +0 -5
  120. package/dist/api/redis/v1/marshalling.gen.js +0 -259
  121. package/dist/api/registry/index.js +0 -2
  122. package/dist/api/registry/v1/api.gen.js +0 -252
  123. package/dist/api/registry/v1/content.gen.js +0 -13
  124. package/dist/api/registry/v1/index.gen.js +0 -5
  125. package/dist/api/registry/v1/marshalling.gen.js +0 -106
  126. package/dist/api/secret/index.js +0 -2
  127. package/dist/api/secret/v1alpha1/api.gen.js +0 -415
  128. package/dist/api/secret/v1alpha1/index.gen.js +0 -4
  129. package/dist/api/secret/v1alpha1/marshalling.gen.js +0 -143
  130. package/dist/api/tem/index.js +0 -2
  131. package/dist/api/tem/v1alpha1/api.gen.js +0 -229
  132. package/dist/api/tem/v1alpha1/content.gen.js +0 -10
  133. package/dist/api/tem/v1alpha1/index.gen.js +0 -5
  134. package/dist/api/tem/v1alpha1/marshalling.gen.js +0 -159
  135. package/dist/api/test/index.js +0 -2
  136. package/dist/api/test/v1/api.gen.js +0 -152
  137. package/dist/api/test/v1/content.gen.js +0 -7
  138. package/dist/api/test/v1/index.gen.js +0 -5
  139. package/dist/api/test/v1/marshalling.gen.js +0 -79
  140. package/dist/api/vpc/index.js +0 -4
  141. package/dist/api/vpc/v1/api.gen.js +0 -110
  142. package/dist/api/vpc/v1/index.gen.js +0 -4
  143. package/dist/api/vpc/v1/marshalling.gen.js +0 -44
  144. package/dist/api/vpc/v2/api.gen.js +0 -276
  145. package/dist/api/vpc/v2/index.gen.js +0 -4
  146. package/dist/api/vpc/v2/marshalling.gen.js +0 -135
  147. package/dist/api/vpcgw/index.js +0 -2
  148. package/dist/api/vpcgw/v1/api.gen.js +0 -669
  149. package/dist/api/vpcgw/v1/content.gen.js +0 -10
  150. package/dist/api/vpcgw/v1/index.gen.js +0 -5
  151. package/dist/api/vpcgw/v1/marshalling.gen.js +0 -336
  152. package/dist/api/webhosting/index.js +0 -2
  153. package/dist/api/webhosting/v1alpha1/api.gen.js +0 -210
  154. package/dist/api/webhosting/v1alpha1/content.gen.js +0 -7
  155. package/dist/api/webhosting/v1alpha1/index.gen.js +0 -7
  156. package/dist/api/webhosting/v1alpha1/marshalling.gen.js +0 -173
  157. package/dist/api/webhosting/v1alpha1/validation-rules.gen.js +0 -23
  158. package/dist/helpers/is-browser.js +0 -5
  159. package/dist/helpers/is-response.js +0 -10
  160. package/dist/helpers/json.js +0 -11
  161. package/dist/helpers/marshalling.js +0 -130
  162. package/dist/index.cjs +0 -24364
  163. package/dist/index.d.ts +0 -27584
  164. package/dist/index.js +0 -69
  165. package/dist/internal/async/interval-retrier.js +0 -105
  166. package/dist/internal/async/sleep.js +0 -13
  167. package/dist/internal/interceptors/composer.js +0 -46
  168. package/dist/internal/interceptors/helpers.js +0 -32
  169. package/dist/internal/logger/console-logger.js +0 -38
  170. package/dist/internal/logger/index.js +0 -41
  171. package/dist/internal/logger/level-resolver.js +0 -13
  172. package/dist/internal/validations/string-validation.js +0 -38
  173. package/dist/node_modules/.pnpm/@scaleway_random-name@4.0.2/node_modules/@scaleway/random-name/dist/index.js +0 -13
  174. package/dist/scw/api.js +0 -12
  175. package/dist/scw/auth.js +0 -68
  176. package/dist/scw/client-ini-factory.js +0 -174
  177. package/dist/scw/client-ini-profile.js +0 -54
  178. package/dist/scw/client-settings.js +0 -78
  179. package/dist/scw/client.js +0 -98
  180. package/dist/scw/constants.js +0 -4
  181. package/dist/scw/custom-marshalling.js +0 -131
  182. package/dist/scw/errors/error-parser.js +0 -107
  183. package/dist/scw/errors/non-standard/invalid-request-mapper.js +0 -36
  184. package/dist/scw/errors/non-standard/unknown-resource-mapper.js +0 -27
  185. package/dist/scw/errors/scw-error.js +0 -66
  186. package/dist/scw/errors/standard/already-exists-error.js +0 -26
  187. package/dist/scw/errors/standard/denied-authentication-error.js +0 -52
  188. package/dist/scw/errors/standard/index.js +0 -13
  189. package/dist/scw/errors/standard/invalid-arguments-error.js +0 -67
  190. package/dist/scw/errors/standard/out-of-stock-error.js +0 -22
  191. package/dist/scw/errors/standard/permissions-denied-error.js +0 -48
  192. package/dist/scw/errors/standard/precondition-failed-error.js +0 -42
  193. package/dist/scw/errors/standard/quotas-exceeded-error.js +0 -68
  194. package/dist/scw/errors/standard/resource-expired-error.js +0 -26
  195. package/dist/scw/errors/standard/resource-locked-error.js +0 -25
  196. package/dist/scw/errors/standard/resource-not-found-error.js +0 -25
  197. package/dist/scw/errors/standard/too-many-requests-error.js +0 -70
  198. package/dist/scw/errors/standard/transient-state-error.js +0 -26
  199. package/dist/scw/errors/types.js +0 -23
  200. package/dist/scw/fetch/build-fetcher.js +0 -72
  201. package/dist/scw/fetch/http-dumper.js +0 -54
  202. package/dist/scw/fetch/http-interceptors.js +0 -99
  203. package/dist/scw/fetch/resource-paginator.js +0 -84
  204. package/dist/scw/fetch/response-parser.js +0 -72
@@ -1,369 +0,0 @@
1
- import { tryAtIntervals, createExponentialBackoffStrategy } from '../../../internal/async/interval-retrier.js';
2
- import { validatePathParam } from '../../../helpers/marshalling.js';
3
- import { API } from './api.gen.js';
4
- import { IMAGE_TRANSIENT_STATUSES, PRIVATE_NIC_TRANSIENT_STATUSES, SERVER_TRANSIENT_STATUSES, SNAPSHOT_TRANSIENT_STATUSES, VOLUME_TRANSIENT_STATUSES } from './content.gen.js';
5
- import { unmarshalSetImageResponse } from './marshalling.gen.js';
6
- import { marshalSetImageRequestWithID } from './marshalling.utils.js';
7
-
8
- const validateNotUndefined = obj => {
9
- if (obj === undefined) throw new TypeError(`object was found undefined`);
10
- return obj;
11
- };
12
- class InstanceV1UtilsAPI extends API {
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
159
- };
160
- }
161
- if (request.destPortTo) {
162
- sReq = {
163
- ...sReq,
164
- destPortTo: request.destPortTo > 0 ? request.destPortTo : undefined
165
- };
166
- }
167
- if (sReq.destPortFrom && sReq.destPortTo && sReq.destPortFrom === sReq.destPortTo) {
168
- sReq = {
169
- ...sReq,
170
- destPortTo: undefined
171
- };
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
179
- };
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,
212
- zone: request.zone
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,
244
- zone: request.zone
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
251
- };
252
- }
253
-
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)) {
262
- newVolumes[key] = {
263
- id: request.volumeId,
264
- name: request.volumeId // name is ignored on this PATCH
265
- };
266
-
267
- found = true;
268
- break;
269
- }
270
- }
271
- if (!found) {
272
- throw new Error(`could not find key to attach volume ${request.volumeId}`);
273
- }
274
-
275
- // Update server
276
- return this.updateServer({
277
- serverId: request.serverId,
278
- volumes: newVolumes,
279
- zone: request.zone
280
- }).then(obj => obj);
281
- };
282
-
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
- };
307
- }
308
- }
309
-
310
- // Update server.
311
- return this.updateServer({
312
- serverId: server.id,
313
- volumes: newVolumes,
314
- zone: request.zone
315
- }).then(obj => obj);
316
- };
317
-
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
- }));
342
-
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
- });
367
- }
368
-
369
- export { InstanceV1UtilsAPI };
@@ -1,31 +0,0 @@
1
- // This file was automatically generated. DO NOT EDIT.
2
- // If you have any remark or suggestion do not hesitate to open an issue.
3
-
4
- /** Lists transient statutes of the enum {@link ImageState}. */
5
- const IMAGE_TRANSIENT_STATUSES = ['creating'];
6
-
7
- /** Lists transient statutes of the enum {@link IpState}. */
8
- const IP_TRANSIENT_STATUSES = ['pending'];
9
-
10
- /** Lists transient statutes of the enum {@link PrivateNICState}. */
11
- const PRIVATE_NIC_TRANSIENT_STATUSES = ['syncing'];
12
-
13
- /** Lists transient statutes of the enum {@link SecurityGroupState}. */
14
- const SECURITY_GROUP_TRANSIENT_STATUSES = ['syncing'];
15
-
16
- /** Lists transient statutes of the enum {@link ServerState}. */
17
- const SERVER_TRANSIENT_STATUSES = ['starting', 'stopping'];
18
-
19
- /** Lists transient statutes of the enum {@link SnapshotState}. */
20
- const SNAPSHOT_TRANSIENT_STATUSES = ['snapshotting', 'importing', 'exporting'];
21
-
22
- /** Lists transient statutes of the enum {@link TaskStatus}. */
23
- const TASK_TRANSIENT_STATUSES = ['pending', 'started', 'retry'];
24
-
25
- /** Lists transient statutes of the enum {@link VolumeServerState}. */
26
- const VOLUME_SERVER_TRANSIENT_STATUSES = ['snapshotting', 'fetching', 'resizing', 'saving', 'hotsyncing'];
27
-
28
- /** Lists transient statutes of the enum {@link VolumeState}. */
29
- const VOLUME_TRANSIENT_STATUSES = ['snapshotting', 'fetching', 'resizing', 'saving', 'hotsyncing'];
30
-
31
- export { IMAGE_TRANSIENT_STATUSES, IP_TRANSIENT_STATUSES, PRIVATE_NIC_TRANSIENT_STATUSES, SECURITY_GROUP_TRANSIENT_STATUSES, SERVER_TRANSIENT_STATUSES, SNAPSHOT_TRANSIENT_STATUSES, TASK_TRANSIENT_STATUSES, VOLUME_SERVER_TRANSIENT_STATUSES, VOLUME_TRANSIENT_STATUSES };
@@ -1,2 +0,0 @@
1
- export { InstanceV1UtilsAPI as API } from './api.utils.js';
2
- export { IMAGE_TRANSIENT_STATUSES, IP_TRANSIENT_STATUSES, PRIVATE_NIC_TRANSIENT_STATUSES, SECURITY_GROUP_TRANSIENT_STATUSES, SERVER_TRANSIENT_STATUSES, SNAPSHOT_TRANSIENT_STATUSES, TASK_TRANSIENT_STATUSES, VOLUME_SERVER_TRANSIENT_STATUSES, VOLUME_TRANSIENT_STATUSES } from './content.gen.js';