@xen-orchestra/rest-api 0.13.1 → 0.14.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.
@@ -12,16 +12,19 @@ import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
12
12
  import { RestApi } from '../rest-api/rest-api.mjs';
13
13
  import { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
14
14
  import { AlarmService } from '../alarms/alarm.service.mjs';
15
- import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
15
+ import { escapeUnsafeComplexMatcher, limitAndFilterArray } from '../helpers/utils.helper.mjs';
16
16
  import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
17
17
  import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
18
18
  import { provide } from 'inversify-binding-decorators';
19
- import { partialVmControllers, vmController, vmControllerIds, } from '../open-api/oa-examples/vm-controller.oa-example.mjs';
19
+ import { partialVmControllers, vmController, vmControllerIds, vmControllerVdis, } from '../open-api/oa-examples/vm-controller.oa-example.mjs';
20
+ import { VmService } from '../vms/vm.service.mjs';
20
21
  let VmControllerController = class VmControllerController extends XapiXoController {
21
22
  #alarmService;
22
- constructor(restApi, alarmService) {
23
+ #vmService;
24
+ constructor(restApi, alarmService, vmService) {
23
25
  super('VM-controller', restApi);
24
26
  this.#alarmService = alarmService;
27
+ this.#vmService = vmService;
25
28
  }
26
29
  /**
27
30
  *
@@ -52,6 +55,16 @@ let VmControllerController = class VmControllerController extends XapiXoControll
52
55
  });
53
56
  return this.sendObjects(Object.values(alarms), req, 'alarms');
54
57
  }
58
+ /**
59
+ * @example id "9b4775bd-9493-490a-9afa-f786a44caa4f"
60
+ * @example fields "VDI_type,id,name_label"
61
+ * @example filter "VDI_type:user"
62
+ * @example limit 42
63
+ */
64
+ getVmControllerVdis(req, id, fields, ndjson, filter, limit) {
65
+ const vdis = this.#vmService.getVmVdis(id, 'VM-controller');
66
+ return this.sendObjects(limitAndFilterArray(vdis, { filter, limit }), req, obj => obj.type.toLowerCase() + 's');
67
+ }
55
68
  };
56
69
  __decorate([
57
70
  Example(vmControllerIds),
@@ -81,6 +94,18 @@ __decorate([
81
94
  __param(4, Query()),
82
95
  __param(5, Query())
83
96
  ], VmControllerController.prototype, "getVmControllerAlarms", null);
97
+ __decorate([
98
+ Example(vmControllerVdis),
99
+ Get('{id}/vdis'),
100
+ Tags('vdis'),
101
+ Response(notFoundResp.status, notFoundResp.description),
102
+ __param(0, Request()),
103
+ __param(1, Path()),
104
+ __param(2, Query()),
105
+ __param(3, Query()),
106
+ __param(4, Query()),
107
+ __param(5, Query())
108
+ ], VmControllerController.prototype, "getVmControllerVdis", null);
84
109
  VmControllerController = __decorate([
85
110
  Route('vm-controllers'),
86
111
  Security('*'),
@@ -88,6 +113,7 @@ VmControllerController = __decorate([
88
113
  Tags('vms'),
89
114
  provide(VmControllerController),
90
115
  __param(0, inject(RestApi)),
91
- __param(1, inject(AlarmService))
116
+ __param(1, inject(AlarmService)),
117
+ __param(2, inject(VmService))
92
118
  ], VmControllerController);
93
119
  export { VmControllerController };
@@ -10,18 +10,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
10
10
  import { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
11
11
  import { inject } from 'inversify';
12
12
  import { AlarmService } from '../alarms/alarm.service.mjs';
13
- import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
13
+ import { escapeUnsafeComplexMatcher, limitAndFilterArray } from '../helpers/utils.helper.mjs';
14
14
  import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
15
15
  import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
16
16
  import { RestApi } from '../rest-api/rest-api.mjs';
17
17
  import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
18
18
  import { provide } from 'inversify-binding-decorators';
19
- import { partialVmSnapshots, vmSnapshot, vmSnapshotIds } from '../open-api/oa-examples/vm-snapshot.oa-example.mjs';
19
+ import { partialVmSnapshots, vmSnapshot, vmSnapshotIds, vmSnapshotVdis, } from '../open-api/oa-examples/vm-snapshot.oa-example.mjs';
20
+ import { VmService } from '../vms/vm.service.mjs';
20
21
  let VmSnapshotController = class VmSnapshotController extends XapiXoController {
21
22
  #alarmService;
22
- constructor(restApi, alarmService) {
23
+ #vmService;
24
+ constructor(restApi, alarmService, vmService) {
23
25
  super('VM-snapshot', restApi);
24
26
  this.#alarmService = alarmService;
27
+ this.#vmService = vmService;
25
28
  }
26
29
  /**
27
30
  *
@@ -52,6 +55,16 @@ let VmSnapshotController = class VmSnapshotController extends XapiXoController {
52
55
  });
53
56
  return this.sendObjects(Object.values(alarms), req, 'alarms');
54
57
  }
58
+ /**
59
+ * @example id "d68fca2c-41e6-be87-d790-105c1642a090"
60
+ * @example fields "VDI_type,id,name_label"
61
+ * @example filter "VDI_type:user"
62
+ * @example limit 42
63
+ */
64
+ getVmSnapshotVdis(req, id, fields, ndjson, filter, limit) {
65
+ const vdis = this.#vmService.getVmVdis(id, 'VM-snapshot');
66
+ return this.sendObjects(limitAndFilterArray(vdis, { filter, limit }), req, obj => obj.type.toLowerCase() + 's');
67
+ }
55
68
  };
56
69
  __decorate([
57
70
  Example(vmSnapshotIds),
@@ -81,6 +94,18 @@ __decorate([
81
94
  __param(4, Query()),
82
95
  __param(5, Query())
83
96
  ], VmSnapshotController.prototype, "getVmSnapshotAlarms", null);
97
+ __decorate([
98
+ Example(vmSnapshotVdis),
99
+ Get('{id}/vdis'),
100
+ Tags('vdis'),
101
+ Response(notFoundResp.status, notFoundResp.description),
102
+ __param(0, Request()),
103
+ __param(1, Path()),
104
+ __param(2, Query()),
105
+ __param(3, Query()),
106
+ __param(4, Query()),
107
+ __param(5, Query())
108
+ ], VmSnapshotController.prototype, "getVmSnapshotVdis", null);
84
109
  VmSnapshotController = __decorate([
85
110
  Route('vm-snapshots'),
86
111
  Security('*'),
@@ -88,6 +113,7 @@ VmSnapshotController = __decorate([
88
113
  Tags('vms'),
89
114
  provide(VmSnapshotController),
90
115
  __param(0, inject(RestApi)),
91
- __param(1, inject(AlarmService))
116
+ __param(1, inject(AlarmService)),
117
+ __param(2, inject(VmService))
92
118
  ], VmSnapshotController);
93
119
  export { VmSnapshotController };
@@ -11,17 +11,20 @@ import { Example, Get, Security, Query, Request, Response, Route, Tags, Path } f
11
11
  import { inject } from 'inversify';
12
12
  import { provide } from 'inversify-binding-decorators';
13
13
  import { AlarmService } from '../alarms/alarm.service.mjs';
14
- import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
14
+ import { escapeUnsafeComplexMatcher, limitAndFilterArray } from '../helpers/utils.helper.mjs';
15
15
  import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
16
16
  import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
17
17
  import { RestApi } from '../rest-api/rest-api.mjs';
18
18
  import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
19
- import { partialVmTemplates, vmTemplate, vmTemplateIds } from '../open-api/oa-examples/vm-template.oa-example.mjs';
19
+ import { partialVmTemplates, vmTemplate, vmTemplateIds, vmTemplateVdis, } from '../open-api/oa-examples/vm-template.oa-example.mjs';
20
+ import { VmService } from '../vms/vm.service.mjs';
20
21
  let VmTemplateController = class VmTemplateController extends XapiXoController {
21
22
  #alarmService;
22
- constructor(restApi, alarmService) {
23
+ #vmService;
24
+ constructor(restApi, alarmService, vmService) {
23
25
  super('VM-template', restApi);
24
26
  this.#alarmService = alarmService;
27
+ this.#vmService = vmService;
25
28
  }
26
29
  /**
27
30
  * @example fields "id,isDefaultTemplate,name_label"
@@ -51,6 +54,16 @@ let VmTemplateController = class VmTemplateController extends XapiXoController {
51
54
  });
52
55
  return this.sendObjects(Object.values(alarms), req, 'alarms');
53
56
  }
57
+ /**
58
+ * @example id "6d50ba76-0f11-1ff1-4f6a-b502afc31b8e"
59
+ * @example fields "VDI_type,id,name_label"
60
+ * @example filter "VDI_type:user"
61
+ * @example limit 42
62
+ */
63
+ getVmTemplateVdis(req, id, fields, ndjson, filter, limit) {
64
+ const vdis = this.#vmService.getVmVdis(id, 'VM-template');
65
+ return this.sendObjects(limitAndFilterArray(vdis, { filter, limit }), req, obj => obj.type.toLowerCase() + 's');
66
+ }
54
67
  };
55
68
  __decorate([
56
69
  Example(vmTemplateIds),
@@ -80,6 +93,18 @@ __decorate([
80
93
  __param(4, Query()),
81
94
  __param(5, Query())
82
95
  ], VmTemplateController.prototype, "getVmTemplateAlarms", null);
96
+ __decorate([
97
+ Example(vmTemplateVdis),
98
+ Get('{id}/vdis'),
99
+ Tags('vdis'),
100
+ Response(notFoundResp.status, notFoundResp.description),
101
+ __param(0, Request()),
102
+ __param(1, Path()),
103
+ __param(2, Query()),
104
+ __param(3, Query()),
105
+ __param(4, Query()),
106
+ __param(5, Query())
107
+ ], VmTemplateController.prototype, "getVmTemplateVdis", null);
83
108
  VmTemplateController = __decorate([
84
109
  Route('vm-templates'),
85
110
  Security('*'),
@@ -87,6 +112,7 @@ VmTemplateController = __decorate([
87
112
  Tags('vms'),
88
113
  provide(VmTemplateController),
89
114
  __param(0, inject(RestApi)),
90
- __param(1, inject(AlarmService))
115
+ __param(1, inject(AlarmService)),
116
+ __param(2, inject(VmService))
91
117
  ], VmTemplateController);
92
118
  export { VmTemplateController };
@@ -14,18 +14,21 @@ import { provide } from 'inversify-binding-decorators';
14
14
  import { AlarmService } from '../alarms/alarm.service.mjs';
15
15
  import { asynchronousActionResp, createdResp, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
16
16
  import { BASE_URL } from '../index.mjs';
17
- import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
17
+ import { escapeUnsafeComplexMatcher, limitAndFilterArray } from '../helpers/utils.helper.mjs';
18
18
  import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
19
- import { partialVms, vm, vmIds, vmStatsExample } from '../open-api/oa-examples/vm.oa-example.mjs';
19
+ import { partialVms, vm, vmIds, vmStatsExample, vmVdis } from '../open-api/oa-examples/vm.oa-example.mjs';
20
20
  import { RestApi } from '../rest-api/rest-api.mjs';
21
21
  import { taskLocation } from '../open-api/oa-examples/task.oa-example.mjs';
22
22
  import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
23
+ import { VmService } from './vm.service.mjs';
23
24
  const IGNORED_VDIS_TAG = '[NOSNAP]';
24
25
  let VmController = class VmController extends XapiXoController {
25
26
  #alarmService;
26
- constructor(restApi, alarmService) {
27
+ #vmService;
28
+ constructor(restApi, alarmService, vmService) {
27
29
  super('VM', restApi);
28
30
  this.#alarmService = alarmService;
31
+ this.#vmService = vmService;
29
32
  }
30
33
  /**
31
34
  *
@@ -313,6 +316,16 @@ let VmController = class VmController extends XapiXoController {
313
316
  });
314
317
  return this.sendObjects(Object.values(alarms), req, 'alarms');
315
318
  }
319
+ /**
320
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
321
+ * @example fields "VDI_type,id,name_label"
322
+ * @example filter "VDI_type:user"
323
+ * @example limit 42
324
+ */
325
+ getVmVdis(req, id, fields, ndjson, filter, limit) {
326
+ const vdis = this.#vmService.getVmVdis(id, 'VM');
327
+ return this.sendObjects(limitAndFilterArray(vdis, { filter, limit }), req, obj => obj.type.toLowerCase() + 's');
328
+ }
316
329
  };
317
330
  __decorate([
318
331
  Example(vmIds),
@@ -464,6 +477,18 @@ __decorate([
464
477
  __param(4, Query()),
465
478
  __param(5, Query())
466
479
  ], VmController.prototype, "getVmAlarms", null);
480
+ __decorate([
481
+ Example(vmVdis),
482
+ Get('{id}/vdis'),
483
+ Tags('vdis'),
484
+ Response(notFoundResp.status, notFoundResp.description),
485
+ __param(0, Request()),
486
+ __param(1, Path()),
487
+ __param(2, Query()),
488
+ __param(3, Query()),
489
+ __param(4, Query()),
490
+ __param(5, Query())
491
+ ], VmController.prototype, "getVmVdis", null);
467
492
  VmController = __decorate([
468
493
  Route('vms'),
469
494
  Security('*'),
@@ -474,6 +499,7 @@ VmController = __decorate([
474
499
  ,
475
500
  provide(VmController),
476
501
  __param(0, inject(RestApi)),
477
- __param(1, inject(AlarmService))
502
+ __param(1, inject(AlarmService)),
503
+ __param(2, inject(VmService))
478
504
  ], VmController);
479
505
  export { VmController };
@@ -13,7 +13,7 @@ export class VmService {
13
13
  const xoApp = this.#restApi.xoApp;
14
14
  const xapi = xoApp.getXapi(pool);
15
15
  const currentUser = this.#restApi.getCurrentUser();
16
- const xapiVm = await xapi.createVm(template, rest, undefined, currentUser?.id);
16
+ const xapiVm = await xapi.createVm(template, rest, undefined, currentUser.id);
17
17
  $defer.onFailure(() => xapi.VM_destroy(xapiVm.$ref));
18
18
  const xoVm = this.#restApi.getObject(xapiVm.uuid, 'VM');
19
19
  let cloudConfigVdi;
@@ -84,4 +84,17 @@ export class VmService {
84
84
  total,
85
85
  };
86
86
  }
87
+ getVmVdis(id, vmType) {
88
+ const getObject = this.#restApi.getObject.bind(this.#restApi);
89
+ const vdis = [];
90
+ const vm = getObject(id, vmType);
91
+ for (const vbdId of vm.$VBDs) {
92
+ const vbd = getObject(vbdId, 'VBD');
93
+ if (vbd.VDI !== undefined) {
94
+ const vdi = getObject(vbd.VDI, ['VDI-snapshot', 'VDI']);
95
+ vdis.push(vdi);
96
+ }
97
+ }
98
+ return vdis;
99
+ }
87
100
  }