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

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 (215) hide show
  1. package/dist/api/account/index.js +4 -0
  2. package/dist/api/account/v2/api.gen.js +147 -0
  3. package/dist/api/account/v2/index.gen.js +4 -0
  4. package/dist/api/account/v2/marshalling.gen.js +39 -0
  5. package/dist/api/account/v3/api.gen.js +129 -0
  6. package/dist/api/account/v3/index.gen.js +6 -0
  7. package/dist/api/account/v3/marshalling.gen.js +39 -0
  8. package/dist/api/account/v3/validation-rules.gen.js +39 -0
  9. package/dist/api/applesilicon/index.js +2 -0
  10. package/dist/api/applesilicon/v1alpha1/api.gen.js +220 -0
  11. package/dist/api/applesilicon/v1alpha1/content.gen.js +7 -0
  12. package/dist/api/applesilicon/v1alpha1/index.gen.js +5 -0
  13. package/dist/api/applesilicon/v1alpha1/marshalling.gen.js +113 -0
  14. package/dist/api/baremetal/index.js +2 -0
  15. package/dist/api/baremetal/v1/api.gen.js +523 -0
  16. package/dist/api/baremetal/v1/api.utils.js +27 -0
  17. package/dist/api/baremetal/v1/content.gen.js +13 -0
  18. package/dist/api/baremetal/v1/index.js +5 -0
  19. package/dist/api/baremetal/v1/marshalling.gen.js +406 -0
  20. package/dist/api/baremetal/v1/validation-rules.gen.js +109 -0
  21. package/dist/api/billing/index.js +2 -0
  22. package/dist/api/billing/v2alpha1/api.gen.js +80 -0
  23. package/dist/api/billing/v2alpha1/index.gen.js +4 -0
  24. package/dist/api/billing/v2alpha1/marshalling.gen.js +53 -0
  25. package/dist/api/block/index.js +2 -0
  26. package/dist/api/block/v1alpha1/api.gen.js +249 -0
  27. package/dist/api/block/v1alpha1/content.gen.js +13 -0
  28. package/dist/api/block/v1alpha1/index.gen.js +7 -0
  29. package/dist/api/block/v1alpha1/marshalling.gen.js +182 -0
  30. package/dist/api/block/v1alpha1/validation-rules.gen.js +52 -0
  31. package/dist/api/cockpit/index.js +2 -0
  32. package/dist/api/cockpit/v1beta1/api.gen.js +543 -0
  33. package/dist/api/cockpit/v1beta1/content.gen.js +7 -0
  34. package/dist/api/cockpit/v1beta1/index.gen.js +5 -0
  35. package/dist/api/cockpit/v1beta1/marshalling.gen.js +271 -0
  36. package/dist/api/container/index.js +2 -0
  37. package/dist/api/container/v1beta1/api.gen.js +549 -0
  38. package/dist/api/container/v1beta1/content.gen.js +22 -0
  39. package/dist/api/container/v1beta1/index.gen.js +7 -0
  40. package/dist/api/container/v1beta1/marshalling.gen.js +358 -0
  41. package/dist/api/container/v1beta1/validation-rules.gen.js +44 -0
  42. package/dist/api/document_db/index.js +2 -0
  43. package/dist/api/document_db/v1beta1/api.gen.js +830 -0
  44. package/dist/api/document_db/v1beta1/content.gen.js +19 -0
  45. package/dist/api/document_db/v1beta1/index.gen.js +7 -0
  46. package/dist/api/document_db/v1beta1/marshalling.gen.js +636 -0
  47. package/dist/api/document_db/v1beta1/validation-rules.gen.js +10 -0
  48. package/dist/api/domain/index.js +2 -0
  49. package/dist/api/domain/v2beta1/api.gen.js +867 -0
  50. package/dist/api/domain/v2beta1/content.gen.js +28 -0
  51. package/dist/api/domain/v2beta1/index.gen.js +5 -0
  52. package/dist/api/domain/v2beta1/marshalling.gen.js +1172 -0
  53. package/dist/api/flexibleip/index.js +2 -0
  54. package/dist/api/flexibleip/v1alpha1/api.gen.js +195 -0
  55. package/dist/api/flexibleip/v1alpha1/content.gen.js +10 -0
  56. package/dist/api/flexibleip/v1alpha1/index.gen.js +7 -0
  57. package/dist/api/flexibleip/v1alpha1/marshalling.gen.js +97 -0
  58. package/dist/api/flexibleip/v1alpha1/validation-rules.gen.js +14 -0
  59. package/dist/api/function/index.js +2 -0
  60. package/dist/api/function/v1beta1/api.gen.js +560 -0
  61. package/dist/api/function/v1beta1/content.gen.js +22 -0
  62. package/dist/api/function/v1beta1/index.gen.js +7 -0
  63. package/dist/api/function/v1beta1/marshalling.gen.js +396 -0
  64. package/dist/api/function/v1beta1/validation-rules.gen.js +44 -0
  65. package/dist/api/iam/index.js +2 -0
  66. package/dist/api/iam/v1alpha1/api.gen.js +783 -0
  67. package/dist/api/iam/v1alpha1/index.gen.js +6 -0
  68. package/dist/api/iam/v1alpha1/marshalling.gen.js +384 -0
  69. package/dist/api/iam/v1alpha1/validation-rules.gen.js +207 -0
  70. package/dist/api/instance/index.js +2 -0
  71. package/dist/api/instance/v1/api.gen.js +1003 -0
  72. package/dist/api/instance/v1/api.utils.js +369 -0
  73. package/dist/api/instance/v1/content.gen.js +31 -0
  74. package/dist/api/instance/v1/index.js +2 -0
  75. package/dist/api/instance/v1/marshalling.gen.js +1415 -0
  76. package/dist/api/instance/v1/marshalling.utils.js +63 -0
  77. package/dist/api/iot/index.js +2 -0
  78. package/dist/api/iot/v1/api.gen.js +573 -0
  79. package/dist/api/iot/v1/content.gen.js +7 -0
  80. package/dist/api/iot/v1/index.gen.js +5 -0
  81. package/dist/api/iot/v1/marshalling.gen.js +439 -0
  82. package/dist/api/ipam/index.js +2 -0
  83. package/dist/api/ipam/v1/api.gen.js +113 -0
  84. package/dist/api/ipam/v1/index.gen.js +6 -0
  85. package/dist/api/ipam/v1/marshalling.gen.js +77 -0
  86. package/dist/api/ipam/v1/validation-rules.gen.js +11 -0
  87. package/dist/api/ipfs/index.js +2 -0
  88. package/dist/api/ipfs/v1alpha1/api.gen.js +314 -0
  89. package/dist/api/ipfs/v1alpha1/content.gen.js +10 -0
  90. package/dist/api/ipfs/v1alpha1/index.gen.js +5 -0
  91. package/dist/api/ipfs/v1alpha1/marshalling.gen.js +180 -0
  92. package/dist/api/k8s/index.js +2 -0
  93. package/dist/api/k8s/v1/api.gen.js +454 -0
  94. package/dist/api/k8s/v1/api.utils.js +13 -0
  95. package/dist/api/k8s/v1/content.gen.js +13 -0
  96. package/dist/api/k8s/v1/index.js +4 -0
  97. package/dist/api/k8s/v1/marshalling.gen.js +421 -0
  98. package/dist/api/k8s/v1/validation-rules.gen.js +101 -0
  99. package/dist/api/lb/index.js +2 -0
  100. package/dist/api/lb/v1/api.gen.js +1669 -0
  101. package/dist/api/lb/v1/api.utils.js +81 -0
  102. package/dist/api/lb/v1/content.gen.js +16 -0
  103. package/dist/api/lb/v1/index.js +2 -0
  104. package/dist/api/lb/v1/marshalling.gen.js +1039 -0
  105. package/dist/api/marketplace/index.js +4 -0
  106. package/dist/api/marketplace/v1/api.gen.js +60 -0
  107. package/dist/api/marketplace/v1/index.gen.js +4 -0
  108. package/dist/api/marketplace/v1/marshalling.gen.js +92 -0
  109. package/dist/api/marketplace/v2/api.gen.js +162 -0
  110. package/dist/api/marketplace/v2/index.gen.js +4 -0
  111. package/dist/api/marketplace/v2/marshalling.gen.js +94 -0
  112. package/dist/api/mnq/index.js +4 -0
  113. package/dist/api/mnq/v1alpha1/api.gen.js +197 -0
  114. package/dist/api/mnq/v1alpha1/index.gen.js +4 -0
  115. package/dist/api/mnq/v1alpha1/marshalling.gen.js +126 -0
  116. package/dist/api/mnq/v1beta1/api.gen.js +529 -0
  117. package/dist/api/mnq/v1beta1/index.gen.js +6 -0
  118. package/dist/api/mnq/v1beta1/marshalling.gen.js +212 -0
  119. package/dist/api/mnq/v1beta1/validation-rules.gen.js +77 -0
  120. package/dist/api/rdb/index.js +2 -0
  121. package/dist/api/rdb/v1/api.gen.js +972 -0
  122. package/dist/api/rdb/v1/content.gen.js +22 -0
  123. package/dist/api/rdb/v1/index.gen.js +7 -0
  124. package/dist/api/rdb/v1/marshalling.gen.js +694 -0
  125. package/dist/api/rdb/v1/validation-rules.gen.js +10 -0
  126. package/dist/api/redis/index.js +2 -0
  127. package/dist/api/redis/v1/api.gen.js +389 -0
  128. package/dist/api/redis/v1/content.gen.js +7 -0
  129. package/dist/api/redis/v1/index.gen.js +5 -0
  130. package/dist/api/redis/v1/marshalling.gen.js +283 -0
  131. package/dist/api/registry/index.js +2 -0
  132. package/dist/api/registry/v1/api.gen.js +252 -0
  133. package/dist/api/registry/v1/content.gen.js +13 -0
  134. package/dist/api/registry/v1/index.gen.js +5 -0
  135. package/dist/api/registry/v1/marshalling.gen.js +108 -0
  136. package/dist/api/secret/index.js +2 -0
  137. package/dist/api/secret/v1alpha1/api.gen.js +415 -0
  138. package/dist/api/secret/v1alpha1/index.gen.js +4 -0
  139. package/dist/api/secret/v1alpha1/marshalling.gen.js +150 -0
  140. package/dist/api/tem/index.js +2 -0
  141. package/dist/api/tem/v1alpha1/api.gen.js +229 -0
  142. package/dist/api/tem/v1alpha1/content.gen.js +10 -0
  143. package/dist/api/tem/v1alpha1/index.gen.js +5 -0
  144. package/dist/api/tem/v1alpha1/marshalling.gen.js +168 -0
  145. package/dist/api/test/index.js +2 -0
  146. package/dist/api/test/v1/api.gen.js +152 -0
  147. package/dist/api/test/v1/content.gen.js +7 -0
  148. package/dist/api/test/v1/index.gen.js +5 -0
  149. package/dist/api/test/v1/marshalling.gen.js +81 -0
  150. package/dist/api/vpc/index.js +4 -0
  151. package/dist/api/vpc/v1/api.gen.js +110 -0
  152. package/dist/api/vpc/v1/index.gen.js +4 -0
  153. package/dist/api/vpc/v1/marshalling.gen.js +44 -0
  154. package/dist/api/vpc/v2/api.gen.js +276 -0
  155. package/dist/api/vpc/v2/index.gen.js +4 -0
  156. package/dist/api/vpc/v2/marshalling.gen.js +137 -0
  157. package/dist/api/vpcgw/index.js +2 -0
  158. package/dist/api/vpcgw/v1/api.gen.js +669 -0
  159. package/dist/api/vpcgw/v1/content.gen.js +10 -0
  160. package/dist/api/vpcgw/v1/index.gen.js +5 -0
  161. package/dist/api/vpcgw/v1/marshalling.gen.js +359 -0
  162. package/dist/api/webhosting/index.js +2 -0
  163. package/dist/api/webhosting/v1alpha1/api.gen.js +158 -0
  164. package/dist/api/webhosting/v1alpha1/content.gen.js +7 -0
  165. package/dist/api/webhosting/v1alpha1/index.gen.js +7 -0
  166. package/dist/api/webhosting/v1alpha1/marshalling.gen.js +146 -0
  167. package/dist/api/webhosting/v1alpha1/validation-rules.gen.js +14 -0
  168. package/dist/helpers/is-browser.js +5 -0
  169. package/dist/helpers/is-response.js +10 -0
  170. package/dist/helpers/json.js +11 -0
  171. package/dist/helpers/marshalling.js +130 -0
  172. package/dist/index.cjs +26484 -0
  173. package/dist/index.d.ts +31184 -0
  174. package/dist/index.js +71 -0
  175. package/dist/internal/async/interval-retrier.js +105 -0
  176. package/dist/internal/async/sleep.js +13 -0
  177. package/dist/internal/interceptors/composer.js +46 -0
  178. package/dist/internal/interceptors/helpers.js +32 -0
  179. package/dist/internal/logger/console-logger.js +38 -0
  180. package/dist/internal/logger/index.js +41 -0
  181. package/dist/internal/logger/level-resolver.js +13 -0
  182. package/dist/internal/validations/string-validation.js +38 -0
  183. package/dist/node_modules/.pnpm/@scaleway_random-name@4.0.2/node_modules/@scaleway/random-name/dist/index.js +13 -0
  184. package/dist/scw/api.js +12 -0
  185. package/dist/scw/auth.js +68 -0
  186. package/dist/scw/client-ini-factory.js +174 -0
  187. package/dist/scw/client-ini-profile.js +54 -0
  188. package/dist/scw/client-settings.js +78 -0
  189. package/dist/scw/client.js +98 -0
  190. package/dist/scw/constants.js +4 -0
  191. package/dist/scw/custom-marshalling.js +131 -0
  192. package/dist/scw/errors/error-parser.js +107 -0
  193. package/dist/scw/errors/non-standard/invalid-request-mapper.js +36 -0
  194. package/dist/scw/errors/non-standard/unknown-resource-mapper.js +27 -0
  195. package/dist/scw/errors/scw-error.js +66 -0
  196. package/dist/scw/errors/standard/already-exists-error.js +26 -0
  197. package/dist/scw/errors/standard/denied-authentication-error.js +52 -0
  198. package/dist/scw/errors/standard/index.js +13 -0
  199. package/dist/scw/errors/standard/invalid-arguments-error.js +67 -0
  200. package/dist/scw/errors/standard/out-of-stock-error.js +22 -0
  201. package/dist/scw/errors/standard/permissions-denied-error.js +48 -0
  202. package/dist/scw/errors/standard/precondition-failed-error.js +42 -0
  203. package/dist/scw/errors/standard/quotas-exceeded-error.js +68 -0
  204. package/dist/scw/errors/standard/resource-expired-error.js +26 -0
  205. package/dist/scw/errors/standard/resource-locked-error.js +25 -0
  206. package/dist/scw/errors/standard/resource-not-found-error.js +25 -0
  207. package/dist/scw/errors/standard/too-many-requests-error.js +70 -0
  208. package/dist/scw/errors/standard/transient-state-error.js +26 -0
  209. package/dist/scw/errors/types.js +23 -0
  210. package/dist/scw/fetch/build-fetcher.js +72 -0
  211. package/dist/scw/fetch/http-dumper.js +54 -0
  212. package/dist/scw/fetch/http-interceptors.js +99 -0
  213. package/dist/scw/fetch/resource-paginator.js +84 -0
  214. package/dist/scw/fetch/response-parser.js +72 -0
  215. package/package.json +2 -2
@@ -0,0 +1,369 @@
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 };
@@ -0,0 +1,31 @@
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 };
@@ -0,0 +1,2 @@
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';