@xen-orchestra/rest-api 0.8.0 → 0.10.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.
Files changed (48) hide show
  1. package/README.md +2 -1
  2. package/dist/abstract-classes/base-controller.mjs +17 -2
  3. package/dist/alarms/alarm.controller.mjs +3 -2
  4. package/dist/groups/group.controller.mjs +3 -2
  5. package/dist/helpers/cache.helper.mjs +52 -0
  6. package/dist/helpers/stream.helper.mjs +5 -0
  7. package/dist/helpers/utils.helper.mjs +4 -0
  8. package/dist/hosts/host.controller.mjs +3 -2
  9. package/dist/index.mjs +1 -1
  10. package/dist/ioc/ioc.mjs +16 -0
  11. package/dist/messages/message.controller.mjs +3 -2
  12. package/dist/middlewares/generic-error-handler.middleware.mjs +5 -1
  13. package/dist/networks/network.controller.mjs +18 -4
  14. package/dist/open-api/common/response.common.mjs +1 -1
  15. package/dist/open-api/oa-examples/pci.oa-example.mjs +30 -0
  16. package/dist/open-api/oa-examples/pgpu.oa-example.mjs +36 -0
  17. package/dist/open-api/oa-examples/pool.oa-example.mjs +4 -0
  18. package/dist/open-api/oa-examples/schedule.oa-example.mjs +3 -0
  19. package/dist/open-api/oa-examples/sm.oa-example.mjs +58 -0
  20. package/dist/open-api/oa-examples/vm-controller.oa-example.mjs +1 -1
  21. package/dist/open-api/oa-examples/xoa.oa-example.mjs +61 -0
  22. package/dist/open-api/routes/routes.js +897 -67
  23. package/dist/pcis/pci.controller.mjs +60 -0
  24. package/dist/pgpus/pgpu.controller.mjs +60 -0
  25. package/dist/pifs/pif.controller.mjs +3 -2
  26. package/dist/pools/pool.controller.mjs +215 -7
  27. package/dist/pools/pool.type.mjs +1 -0
  28. package/dist/rest-api/rest-api.mjs +3 -0
  29. package/dist/schedules/schedule.controller.mjs +5 -4
  30. package/dist/servers/server.controller.mjs +19 -6
  31. package/dist/sms/sm.controller.mjs +60 -0
  32. package/dist/srs/sr.controller.mjs +3 -2
  33. package/dist/users/user.controller.mjs +3 -2
  34. package/dist/vbds/vbd.controller.mjs +3 -2
  35. package/dist/vdi-snapshots/vdi-snapshot.controller.mjs +3 -2
  36. package/dist/vdis/vdi.controller.mjs +3 -2
  37. package/dist/vifs/vif.controller.mjs +3 -2
  38. package/dist/vm-controller/vm-controller.controller.mjs +3 -2
  39. package/dist/vm-snapshots/vm-snapshot.controller.mjs +3 -2
  40. package/dist/vm-templates/vm-template.controller.mjs +3 -2
  41. package/dist/vms/vm.controller.mjs +198 -12
  42. package/dist/vms/vm.service.mjs +47 -0
  43. package/dist/xoa/xoa.controller.mjs +55 -0
  44. package/dist/xoa/xoa.service.mjs +488 -0
  45. package/dist/xoa/xoa.type.mjs +1 -0
  46. package/open-api/spec/swagger.json +5729 -2883
  47. package/package.json +12 -4
  48. package/tsoa.json +20 -0
@@ -23,7 +23,7 @@ let VdiController = class VdiController extends XapiXoController {
23
23
  * @example filter "snapshots:length:>2"
24
24
  * @example limit 42
25
25
  */
26
- getVdis(req, fields, filter, limit) {
26
+ getVdis(req, fields, ndjson, filter, limit) {
27
27
  return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
28
28
  }
29
29
  /**
@@ -40,7 +40,8 @@ __decorate([
40
40
  __param(0, Request()),
41
41
  __param(1, Query()),
42
42
  __param(2, Query()),
43
- __param(3, Query())
43
+ __param(3, Query()),
44
+ __param(4, Query())
44
45
  ], VdiController.prototype, "getVdis", null);
45
46
  __decorate([
46
47
  Example(vdi),
@@ -23,7 +23,7 @@ let VifController = class VifController extends XapiXoController {
23
23
  * @example filter "attached?"
24
24
  * @example limit 42
25
25
  */
26
- getVifs(req, fields, filter, limit) {
26
+ getVifs(req, fields, ndjson, filter, limit) {
27
27
  return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
28
28
  }
29
29
  /**
@@ -40,7 +40,8 @@ __decorate([
40
40
  __param(0, Request()),
41
41
  __param(1, Query()),
42
42
  __param(2, Query()),
43
- __param(3, Query())
43
+ __param(3, Query()),
44
+ __param(4, Query())
44
45
  ], VifController.prototype, "getVifs", null);
45
46
  __decorate([
46
47
  Example(vif),
@@ -24,7 +24,7 @@ let VmControllerController = class VmControllerController extends XapiXoControll
24
24
  * @example filter "power_state:Running"
25
25
  * @example limit 42
26
26
  */
27
- getVmControllers(req, fields, filter, limit) {
27
+ getVmControllers(req, fields, ndjson, filter, limit) {
28
28
  return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
29
29
  }
30
30
  /**
@@ -41,7 +41,8 @@ __decorate([
41
41
  __param(0, Request()),
42
42
  __param(1, Query()),
43
43
  __param(2, Query()),
44
- __param(3, Query())
44
+ __param(3, Query()),
45
+ __param(4, Query())
45
46
  ], VmControllerController.prototype, "getVmControllers", null);
46
47
  __decorate([
47
48
  Example(vmController),
@@ -24,7 +24,7 @@ let VmSnapshotController = class VmSnapshotController extends XapiXoController {
24
24
  * @example filter "snapshot_time:>1725020038"
25
25
  * @example limit 42
26
26
  */
27
- getVmSnapshots(req, fields, filter, limit) {
27
+ getVmSnapshots(req, fields, ndjson, filter, limit) {
28
28
  return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
29
29
  }
30
30
  /**
@@ -41,7 +41,8 @@ __decorate([
41
41
  __param(0, Request()),
42
42
  __param(1, Query()),
43
43
  __param(2, Query()),
44
- __param(3, Query())
44
+ __param(3, Query()),
45
+ __param(4, Query())
45
46
  ], VmSnapshotController.prototype, "getVmSnapshots", null);
46
47
  __decorate([
47
48
  Example(vmSnapshot),
@@ -23,7 +23,7 @@ let VmTemplateController = class VmTemplateController extends XapiXoController {
23
23
  * @example filter "isDefaultTemplate?"
24
24
  * @example limit 42
25
25
  * */
26
- getVmTemplates(req, fields, filter, limit) {
26
+ getVmTemplates(req, fields, ndjson, filter, limit) {
27
27
  return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
28
28
  }
29
29
  /**
@@ -40,7 +40,8 @@ __decorate([
40
40
  __param(0, Request()),
41
41
  __param(1, Query()),
42
42
  __param(2, Query()),
43
- __param(3, Query())
43
+ __param(3, Query()),
44
+ __param(4, Query())
44
45
  ], VmTemplateController.prototype, "getVmTemplates", null);
45
46
  __decorate([
46
47
  Example(vmTemplate),
@@ -7,11 +7,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __param = (this && this.__param) || function (paramIndex, decorator) {
8
8
  return function (target, key) { decorator(target, key, paramIndex); }
9
9
  };
10
- import { Example, Get, Path, Post, Query, Request, Response, Route, Security, Tags, SuccessResponse, Body } from 'tsoa';
10
+ import { Example, Get, Path, Post, Query, Request, Response, Route, Security, Tags, SuccessResponse, Body, Put, Delete, } from 'tsoa';
11
11
  import { inject } from 'inversify';
12
12
  import { incorrectState, invalidParameters } from 'xo-common/api-errors.js';
13
13
  import { provide } from 'inversify-binding-decorators';
14
- import { actionAsyncroneResp, createdResp, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
14
+ import { asynchronousActionResp, createdResp, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
15
15
  import { BASE_URL } from '../index.mjs';
16
16
  import { partialVms, vm, vmIds, vmStatsExample } from '../open-api/oa-examples/vm.oa-example.mjs';
17
17
  import { RestApi } from '../rest-api/rest-api.mjs';
@@ -28,7 +28,7 @@ let VmController = class VmController extends XapiXoController {
28
28
  * @example filter "power_state:Running"
29
29
  * @example limit 42
30
30
  */
31
- getVms(req, fields, filter, limit) {
31
+ getVms(req, fields, ndjson, filter, limit) {
32
32
  return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
33
33
  }
34
34
  /**
@@ -58,15 +58,67 @@ let VmController = class VmController extends XapiXoController {
58
58
  }
59
59
  }
60
60
  /**
61
+ * The VM must be running
62
+ *
63
+ * List of possible data_source (Based on [Xenserver doc](https://docs.xenserver.com/en-us/xenserver/8/monitor-performance#available-vm-metrics))
64
+ * - **cpu#** : Utilization of vCPU cpu (fraction). Enabled by default. *Condition*: vCPU cpu exists.
65
+ * - **cpu_usage** : Domain CPU usage. *Condition*: None.
66
+ * - **memory** : Memory currently allocated to VM (Bytes). Enabled by default. *Condition*: None.
67
+ * - **memory_target** : Target of VM balloon driver (Bytes). Enabled by default. *Condition*: None.
68
+ * - **memory_internal_free** : Memory used as reported by the guest agent (KiB). Enabled by default. *Condition*: None.
69
+ * - **runstate_fullrun** : Fraction of time that all vCPUs are running. *Condition*: None.
70
+ * - **runstate_full_contention** : Fraction of time that all vCPUs are runnable (waiting for CPU). *Condition*: None.
71
+ * - **runstate_concurrency_hazard** : Fraction of time that some vCPUs are running and some are runnable. *Condition*: None.
72
+ * - **runstate_blocked** : Fraction of time that all vCPUs are blocked or offline. *Condition*: None.
73
+ * - **runstate_partial_run** : Fraction of time that some vCPUs are running, and some are blocked. *Condition*: None.
74
+ * - **runstate_partial_contention** : Fraction of time that some vCPUs are runnable and some are blocked. *Condition*: None.
75
+ * - **vbd_#_write** : Writes to device vbd in bytes per second. Enabled by default. *Condition*: VBD vbd exists.
76
+ * - **vbd_#_read** : Reads from device vbd in bytes per second. Enabled by default. *Condition*: VBD vbd exists.
77
+ * - **vbd_#_write_latency** : Writes to device vbd in microseconds. *Condition*: VBD vbd exists.
78
+ * - **vbd_#_read_latency** : Reads from device vbd in microseconds. *Condition*: VBD vbd exists.
79
+ * - **vbd_#_iops_read** : Read requests per second. *Condition*: At least one plugged VBD for non-ISO VDI on the host.
80
+ * - **vbd_#_iops_write** : Write requests per second. *Condition*: At least one plugged VBD for non-ISO VDI on the host.
81
+ * - **vbd_#_iops_total** : I/O requests per second. *Condition*: At least one plugged VBD for non-ISO VDI on the host.
82
+ * - **vbd_#_iowait** : Percentage of time waiting for I/O. *Condition*: At least one plugged VBD for non-ISO VDI on the host.
83
+ * - **vbd_#_inflight** : Number of I/O requests currently in flight. *Condition*: At least one plugged VBD for non-ISO VDI on the host.
84
+ * - **vbd_#_avgqu_sz** : Average I/O queue size. *Condition*: At least one plugged VBD for non-ISO VDI on the host.
85
+ * - **vif_#_rx** : Bytes per second received on virtual interface number vif. Enabled by default. *Condition*: VIF vif exists.
86
+ * - **vif_#_tx** : Bytes per second transmitted on virtual interface vif. Enabled by default. *Condition*: VIF vif exists.
87
+ * - **vif_#_rx_errors** : Receive errors per second on virtual interface vif. Enabled by default. *Condition*: VIF vif exists.
88
+ * - **vif_#_tx_errors** : Transmit errors per second on virtual interface vif. Enabled by default. *Condition*: VIF vif exists.
89
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
90
+ * @example dataSource "cpu0"
91
+ */
92
+ async addDataSource(id, dataSource) {
93
+ await this.getXapiObject(id).$call('record_data_source', dataSource);
94
+ }
95
+ /**
96
+ * The VM must be running
97
+ *
98
+ * For a list of possible data sources, see the endpoint documentation: `GET {id}/stats/data_source/{data_source}`
99
+ *
61
100
  * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
101
+ * @example dataSource "cpu0"
62
102
  */
63
- async startVm(id, sync) {
103
+ async deleteDataSource(id, dataSource) {
104
+ await this.getXapiObject(id).$call('forget_data_source_archives', dataSource);
105
+ }
106
+ /**
107
+ * The VM must be halted
108
+ *
109
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
110
+ * @example body { "hostId": "b61a5c92-700e-4966-a13b-00633f03eea8" }
111
+ */
112
+ async startVm(id, body, sync) {
64
113
  const vmId = id;
65
- const action = () => this.getXapiObject(vmId).$callAsync('start', false, false);
114
+ const action = async () => {
115
+ await this.getXapi(vmId).startVm(vmId, { startOnly: true, hostId: body?.hostId });
116
+ };
66
117
  return this.createAction(action, {
67
118
  sync,
68
119
  statusCode: noContentResp.status,
69
120
  taskProperties: {
121
+ args: body,
70
122
  name: 'start VM',
71
123
  objectId: vmId,
72
124
  },
@@ -142,6 +194,82 @@ let VmController = class VmController extends XapiXoController {
142
194
  },
143
195
  });
144
196
  }
197
+ /**
198
+ * The VM must be running
199
+ *
200
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
201
+ */
202
+ async pauseVm(id, sync) {
203
+ const vmId = id;
204
+ const action = async () => {
205
+ await this.getXapiObject(vmId).$callAsync('pause');
206
+ };
207
+ return this.createAction(action, {
208
+ sync,
209
+ statusCode: noContentResp.status,
210
+ taskProperties: {
211
+ name: 'pause VM',
212
+ objectId: vmId,
213
+ },
214
+ });
215
+ }
216
+ /**
217
+ * The VM must be running
218
+ *
219
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
220
+ */
221
+ async suspendVm(id, sync) {
222
+ const vmId = id;
223
+ const action = async () => {
224
+ await this.getXapiObject(vmId).$callAsync('suspend');
225
+ };
226
+ return this.createAction(action, {
227
+ sync,
228
+ statusCode: noContentResp.status,
229
+ taskProperties: {
230
+ name: 'suspend VM',
231
+ objectId: vmId,
232
+ },
233
+ });
234
+ }
235
+ /**
236
+ * The VM must be suspended
237
+ *
238
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
239
+ */
240
+ async resumeVm(id, sync) {
241
+ const vmId = id;
242
+ const action = async () => {
243
+ await this.getXapi(vmId).resumeVm(vmId);
244
+ };
245
+ return this.createAction(action, {
246
+ sync,
247
+ statusCode: noContentResp.status,
248
+ taskProperties: {
249
+ name: 'resume VM',
250
+ objectId: vmId,
251
+ },
252
+ });
253
+ }
254
+ /**
255
+ * The VM must be paused
256
+ *
257
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
258
+ */
259
+ async unpauseVm(id, sync) {
260
+ const vmId = id;
261
+ const action = async () => {
262
+ await this.getXapi(vmId).unpauseVm(vmId);
263
+ };
264
+ return this.createAction(action, {
265
+ sync,
266
+ statusCode: noContentResp.status,
267
+ taskProperties: {
268
+ name: 'unpause VM',
269
+ objectId: vmId,
270
+ },
271
+ });
272
+ }
145
273
  /**
146
274
  * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
147
275
  * @example body { "name_label": "my_awesome_snapshot" }
@@ -174,7 +302,8 @@ __decorate([
174
302
  __param(0, Request()),
175
303
  __param(1, Query()),
176
304
  __param(2, Query()),
177
- __param(3, Query())
305
+ __param(3, Query()),
306
+ __param(4, Query())
178
307
  ], VmController.prototype, "getVms", null);
179
308
  __decorate([
180
309
  Example(vm),
@@ -190,20 +319,37 @@ __decorate([
190
319
  __param(0, Path()),
191
320
  __param(1, Query())
192
321
  ], VmController.prototype, "getVmStats", null);
322
+ __decorate([
323
+ SuccessResponse(noContentResp.status, noContentResp.description),
324
+ Response(notFoundResp.status, notFoundResp.description),
325
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
326
+ Put('{id}/stats/data_source/{data_source}'),
327
+ __param(0, Path()),
328
+ __param(1, Path('data_source'))
329
+ ], VmController.prototype, "addDataSource", null);
330
+ __decorate([
331
+ SuccessResponse(noContentResp.status, noContentResp.description),
332
+ Response(notFoundResp.status, notFoundResp.description),
333
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
334
+ Delete('{id}/stats/data_source/{data_source}'),
335
+ __param(0, Path()),
336
+ __param(1, Path('data_source'))
337
+ ], VmController.prototype, "deleteDataSource", null);
193
338
  __decorate([
194
339
  Example(taskLocation),
195
340
  Post('{id}/actions/start'),
196
- SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
341
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
197
342
  Response(noContentResp.status, noContentResp.description),
198
343
  Response(notFoundResp.status, notFoundResp.description),
199
344
  Response(internalServerErrorResp.status, internalServerErrorResp.description),
200
345
  __param(0, Path()),
201
- __param(1, Query())
346
+ __param(1, Body()),
347
+ __param(2, Query())
202
348
  ], VmController.prototype, "startVm", null);
203
349
  __decorate([
204
350
  Example(taskLocation),
205
351
  Post('{id}/actions/clean_shutdown'),
206
- SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
352
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
207
353
  Response(noContentResp.status, noContentResp.description),
208
354
  Response(notFoundResp.status, notFoundResp.description),
209
355
  Response(internalServerErrorResp.status, internalServerErrorResp.description),
@@ -219,7 +365,7 @@ __decorate([
219
365
  __decorate([
220
366
  Example(taskLocation),
221
367
  Post('{id}/actions/hard_shutdown'),
222
- SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
368
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
223
369
  Response(noContentResp.status, noContentResp.description),
224
370
  Response(notFoundResp.status, notFoundResp.description),
225
371
  Response(internalServerErrorResp.status, internalServerErrorResp.description),
@@ -229,17 +375,57 @@ __decorate([
229
375
  __decorate([
230
376
  Example(taskLocation),
231
377
  Post('{id}/actions/hard_reboot'),
232
- SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
378
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
233
379
  Response(noContentResp.status, noContentResp.description),
234
380
  Response(notFoundResp.status, notFoundResp.description),
235
381
  Response(internalServerErrorResp.status, internalServerErrorResp.description),
236
382
  __param(0, Path()),
237
383
  __param(1, Query())
238
384
  ], VmController.prototype, "hardRebootVm", null);
385
+ __decorate([
386
+ Example(taskLocation),
387
+ Post('{id}/actions/pause'),
388
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
389
+ Response(noContentResp.status, noContentResp.description),
390
+ Response(notFoundResp.status, notFoundResp.description),
391
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
392
+ __param(0, Path()),
393
+ __param(1, Query())
394
+ ], VmController.prototype, "pauseVm", null);
395
+ __decorate([
396
+ Example(taskLocation),
397
+ Post('{id}/actions/suspend'),
398
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
399
+ Response(noContentResp.status, noContentResp.description),
400
+ Response(notFoundResp.status, notFoundResp.description),
401
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
402
+ __param(0, Path()),
403
+ __param(1, Query())
404
+ ], VmController.prototype, "suspendVm", null);
405
+ __decorate([
406
+ Example(taskLocation),
407
+ Post('{id}/actions/resume'),
408
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
409
+ Response(noContentResp.status, noContentResp.description),
410
+ Response(notFoundResp.status, notFoundResp.description),
411
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
412
+ __param(0, Path()),
413
+ __param(1, Query())
414
+ ], VmController.prototype, "resumeVm", null);
415
+ __decorate([
416
+ Example(taskLocation),
417
+ Post('{id}/actions/unpause'),
418
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
419
+ Response(noContentResp.status, noContentResp.description),
420
+ Response(notFoundResp.status, notFoundResp.description),
421
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
422
+ __param(0, Path()),
423
+ __param(1, Query())
424
+ ], VmController.prototype, "unpauseVm", null);
239
425
  __decorate([
240
426
  Example(taskLocation),
241
427
  Post('{id}/actions/snapshot'),
242
- SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
428
+ SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce),
243
429
  Response(createdResp.status, 'Snapshot created'),
244
430
  Response(notFoundResp.status, notFoundResp.description),
245
431
  Response(internalServerErrorResp.status, internalServerErrorResp.description),
@@ -0,0 +1,47 @@
1
+ import { createLogger } from '@xen-orchestra/log';
2
+ import { defer } from 'golike-defer';
3
+ import { Task } from '@vates/task';
4
+ const log = createLogger('xo:rest-api:vm-service');
5
+ export class VmService {
6
+ #restApi;
7
+ constructor(restApi) {
8
+ this.#restApi = restApi;
9
+ }
10
+ async #create($defer, params) {
11
+ const { pool, template, cloud_config, boot, destroy_cloud_config_vdi, network_config, ...rest } = params;
12
+ const xoApp = this.#restApi.xoApp;
13
+ const xapi = xoApp.getXapi(pool);
14
+ const currentUser = this.#restApi.getCurrentUser();
15
+ const xapiVm = await xapi.createVm(template, rest, undefined, currentUser?.id);
16
+ $defer.onFailure(() => xapi.VM_destroy(xapiVm.$ref));
17
+ const xoVm = this.#restApi.getObject(xapiVm.uuid, 'VM');
18
+ let cloudConfigVdi;
19
+ if (cloud_config !== undefined) {
20
+ const cloudConfigVdiUuid = await xapi.VM_createCloudInitConfig(xapiVm.$ref, cloud_config, {
21
+ networkConfig: network_config,
22
+ });
23
+ cloudConfigVdi = xoApp.getXapiObject(cloudConfigVdiUuid, 'VDI');
24
+ }
25
+ let timeLimit;
26
+ if (boot) {
27
+ timeLimit = Date.now() + 10 * 60 * 1000;
28
+ await xapiVm.$callAsync('start', false, false);
29
+ }
30
+ if (destroy_cloud_config_vdi && cloudConfigVdi !== undefined && boot) {
31
+ Task.info('Destruction of the cloud config VDI is planned and will be done as soon as possible');
32
+ xapi.VDI_destroyCloudInitConfig(cloudConfigVdi.$ref, { timeLimit }).catch(error => {
33
+ log.error('destroy cloud init config VDI failed', {
34
+ error,
35
+ vdi: {
36
+ uuid: cloudConfigVdi.uuid,
37
+ },
38
+ vm: {
39
+ uuid: xoVm.uuid,
40
+ },
41
+ });
42
+ });
43
+ }
44
+ return xoVm.id;
45
+ }
46
+ create = defer(this.#create);
47
+ }
@@ -0,0 +1,55 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ };
10
+ import { Controller, Example, Get, Query, Request, Response, Route, Security, Tags } from 'tsoa';
11
+ import { inject } from 'inversify';
12
+ import { PassThrough } from 'node:stream';
13
+ import { provide } from 'inversify-binding-decorators';
14
+ import { unauthorizedResp } from '../open-api/common/response.common.mjs';
15
+ import { xoaDashboard } from '../open-api/oa-examples/xoa.oa-example.mjs';
16
+ import { XoaService } from './xoa.service.mjs';
17
+ import { NDJSON_CONTENT_TYPE } from '../helpers/utils.helper.mjs';
18
+ let XoaController = class XoaController extends Controller {
19
+ #xoaService;
20
+ constructor(xoaService) {
21
+ super();
22
+ this.#xoaService = xoaService;
23
+ }
24
+ async getDashboard(req, ndjson) {
25
+ const stream = ndjson ? new PassThrough() : undefined;
26
+ const isStream = ndjson && stream !== undefined;
27
+ if (isStream) {
28
+ const res = req.res;
29
+ res.setHeader('Content-Type', NDJSON_CONTENT_TYPE);
30
+ stream.pipe(res);
31
+ }
32
+ const dashboard = await this.#xoaService.getDashboard({ stream });
33
+ if (isStream) {
34
+ stream.end();
35
+ }
36
+ else {
37
+ return dashboard;
38
+ }
39
+ }
40
+ };
41
+ __decorate([
42
+ Example(xoaDashboard),
43
+ Get('dashboard'),
44
+ __param(0, Request()),
45
+ __param(1, Query())
46
+ ], XoaController.prototype, "getDashboard", null);
47
+ XoaController = __decorate([
48
+ Route(''),
49
+ Security('*'),
50
+ Response(unauthorizedResp.status, unauthorizedResp.description),
51
+ Tags('xoa'),
52
+ provide(XoaController),
53
+ __param(0, inject(XoaService))
54
+ ], XoaController);
55
+ export { XoaController };