@xen-orchestra/rest-api 0.7.0 → 0.8.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.
@@ -0,0 +1,59 @@
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 { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
11
+ import { inject } from 'inversify';
12
+ import { provide } from 'inversify-binding-decorators';
13
+ import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
14
+ import { partialPifs, pif, pifIds } from '../open-api/oa-examples/pif.oa-example.mjs';
15
+ import { RestApi } from '../rest-api/rest-api.mjs';
16
+ import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
17
+ let PifController = class PifController extends XapiXoController {
18
+ constructor(restApi) {
19
+ super('PIF', restApi);
20
+ }
21
+ /**
22
+ * @example fields "attached,device,deviceName,id"
23
+ * @example filter "attached?"
24
+ * @example limit 42
25
+ */
26
+ getPifs(req, fields, filter, limit) {
27
+ return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
28
+ }
29
+ /**
30
+ * @example id "d9e42451-3794-089f-de81-4ee0e6137bee"
31
+ */
32
+ getPif(id) {
33
+ return this.getObject(id);
34
+ }
35
+ };
36
+ __decorate([
37
+ Example(pifIds),
38
+ Example(partialPifs),
39
+ Get(''),
40
+ __param(0, Request()),
41
+ __param(1, Query()),
42
+ __param(2, Query()),
43
+ __param(3, Query())
44
+ ], PifController.prototype, "getPifs", null);
45
+ __decorate([
46
+ Example(pif),
47
+ Get('{id}'),
48
+ Response(notFoundResp.status, notFoundResp.description),
49
+ __param(0, Path())
50
+ ], PifController.prototype, "getPif", null);
51
+ PifController = __decorate([
52
+ Route('pifs'),
53
+ Security('*'),
54
+ Response(unauthorizedResp.status, unauthorizedResp.description),
55
+ Tags('pifs'),
56
+ provide(PifController),
57
+ __param(0, inject(RestApi))
58
+ ], PifController);
59
+ export { PifController };
@@ -7,15 +7,17 @@ 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 } from 'tsoa';
10
+ import { Example, Get, Path, Post, Query, Request, Response, Route, Security, Tags, SuccessResponse, Body } 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, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
14
+ import { actionAsyncroneResp, createdResp, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
15
+ import { BASE_URL } from '../index.mjs';
15
16
  import { partialVms, vm, vmIds, vmStatsExample } from '../open-api/oa-examples/vm.oa-example.mjs';
16
17
  import { RestApi } from '../rest-api/rest-api.mjs';
17
18
  import { taskLocation } from '../open-api/oa-examples/task.oa-example.mjs';
18
19
  import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
20
+ const IGNORED_VDIS_TAG = '[NOSNAP]';
19
21
  let VmController = class VmController extends XapiXoController {
20
22
  constructor(restApi) {
21
23
  super('VM', restApi);
@@ -140,6 +142,30 @@ let VmController = class VmController extends XapiXoController {
140
142
  },
141
143
  });
142
144
  }
145
+ /**
146
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
147
+ * @example body { "name_label": "my_awesome_snapshot" }
148
+ */
149
+ async snapshotVm(id, body, sync) {
150
+ const vmId = id;
151
+ const action = async () => {
152
+ const xapiVm = this.getXapiObject(vmId);
153
+ const ref = await xapiVm.$snapshot({ ignoredVdisTag: IGNORED_VDIS_TAG, name_label: body?.name_label });
154
+ const snapshotId = await xapiVm.$xapi.getField('VM', ref, 'uuid');
155
+ if (sync) {
156
+ this.setHeader('Location', `${BASE_URL}/vm-snapshots/${snapshotId}`);
157
+ }
158
+ return { id: snapshotId };
159
+ };
160
+ return this.createAction(action, {
161
+ sync,
162
+ statusCode: createdResp.status,
163
+ taskProperties: {
164
+ name: 'snapshot VM',
165
+ objectId: vmId,
166
+ },
167
+ });
168
+ }
143
169
  };
144
170
  __decorate([
145
171
  Example(vmIds),
@@ -210,6 +236,17 @@ __decorate([
210
236
  __param(0, Path()),
211
237
  __param(1, Query())
212
238
  ], VmController.prototype, "hardRebootVm", null);
239
+ __decorate([
240
+ Example(taskLocation),
241
+ Post('{id}/actions/snapshot'),
242
+ SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
243
+ Response(createdResp.status, 'Snapshot created'),
244
+ Response(notFoundResp.status, notFoundResp.description),
245
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
246
+ __param(0, Path()),
247
+ __param(1, Body()),
248
+ __param(2, Query())
249
+ ], VmController.prototype, "snapshotVm", null);
213
250
  VmController = __decorate([
214
251
  Route('vms'),
215
252
  Security('*'),