@xen-orchestra/rest-api 0.6.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,10 +7,12 @@ 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, Query, Request, Response, Route, Security, Tags } from 'tsoa';
10
+ import { Body, Example, Get, Middlewares, Path, Post, Query, Request, Response, Route, Security, SuccessResponse, Tags, } from 'tsoa';
11
+ import { json } from 'express';
11
12
  import { provide } from 'inversify-binding-decorators';
12
- import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
13
- import { partialServers, server, serverIds } from '../open-api/oa-examples/server.oa-example.mjs';
13
+ import { actionAsyncroneResp, createdResp, invalidParameters, noContentResp, notFoundResp, resourceAlreadyExists, unauthorizedResp, } from '../open-api/common/response.common.mjs';
14
+ import { partialServers, server, serverId, serverIds } from '../open-api/oa-examples/server.oa-example.mjs';
15
+ import { taskLocation } from '../open-api/oa-examples/task.oa-example.mjs';
14
16
  import { XoController } from '../abstract-classes/xo-controller.mjs';
15
17
  let ServerController = class ServerController extends XoController {
16
18
  // --- abstract methods
@@ -34,6 +36,47 @@ let ServerController = class ServerController extends XoController {
34
36
  getServer(id) {
35
37
  return this.getObject(id);
36
38
  }
39
+ /**
40
+ * @example body {
41
+ * "allowUnauthorized": true,
42
+ * "host": "192.168.1.10",
43
+ * "label": "Example server",
44
+ * "username": "root",
45
+ * "password": "awes0meP4ssword"
46
+ * }
47
+ */
48
+ async addServer(body) {
49
+ const server = await this.restApi.xoApp.registerXenServer(body);
50
+ return { id: server.id };
51
+ }
52
+ /**
53
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
54
+ */
55
+ connectServer(id, sync) {
56
+ const serverId = id;
57
+ const action = async () => {
58
+ await this.restApi.xoApp.connectXenServer(serverId);
59
+ };
60
+ return this.createAction(action, {
61
+ statusCode: noContentResp.status,
62
+ sync,
63
+ taskProperties: { name: 'connect server', objectId: serverId },
64
+ });
65
+ }
66
+ /**
67
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
68
+ */
69
+ disconnectServer(id, sync) {
70
+ const serverId = id;
71
+ const action = async () => {
72
+ await this.restApi.xoApp.disconnectXenServer(serverId);
73
+ };
74
+ return this.createAction(action, {
75
+ statusCode: noContentResp.status,
76
+ sync,
77
+ taskProperties: { name: 'disconnect server', objectId: serverId },
78
+ });
79
+ }
37
80
  };
38
81
  __decorate([
39
82
  Example(serverIds),
@@ -50,6 +93,35 @@ __decorate([
50
93
  Response(notFoundResp.status, notFoundResp.description),
51
94
  __param(0, Path())
52
95
  ], ServerController.prototype, "getServer", null);
96
+ __decorate([
97
+ Example(serverId),
98
+ Post(''),
99
+ Middlewares(json()),
100
+ SuccessResponse(createdResp.status, createdResp.description),
101
+ Response(resourceAlreadyExists.status, resourceAlreadyExists.description),
102
+ Response(invalidParameters.status, invalidParameters.description),
103
+ __param(0, Body())
104
+ ], ServerController.prototype, "addServer", null);
105
+ __decorate([
106
+ Example(taskLocation),
107
+ Post('{id}/actions/connect'),
108
+ SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
109
+ Response(noContentResp.status, noContentResp.description),
110
+ Response(notFoundResp.status, notFoundResp.description),
111
+ Response(409, 'The server is already connected'),
112
+ __param(0, Path()),
113
+ __param(1, Query())
114
+ ], ServerController.prototype, "connectServer", null);
115
+ __decorate([
116
+ Example(taskLocation),
117
+ Post('{id}/actions/disconnect'),
118
+ SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
119
+ Response(noContentResp.status, noContentResp.description),
120
+ Response(notFoundResp.status, notFoundResp.description),
121
+ Response(409, 'The server is already disconnected'),
122
+ __param(0, Path()),
123
+ __param(1, Query())
124
+ ], ServerController.prototype, "disconnectServer", null);
53
125
  ServerController = __decorate([
54
126
  Route('servers'),
55
127
  Security('*'),
@@ -0,0 +1 @@
1
+ export {};
@@ -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);
@@ -70,6 +72,100 @@ let VmController = class VmController extends XapiXoController {
70
72
  },
71
73
  });
72
74
  }
75
+ /**
76
+ * Requires guest tools to be installed
77
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
78
+ */
79
+ async cleanShutdownVm(id, sync) {
80
+ const vmId = id;
81
+ const action = async () => {
82
+ await this.getXapiObject(vmId).$callAsync('clean_shutdown');
83
+ };
84
+ return this.createAction(action, {
85
+ sync,
86
+ statusCode: noContentResp.status,
87
+ taskProperties: {
88
+ name: 'clean shutdown VM',
89
+ objectId: vmId,
90
+ },
91
+ });
92
+ }
93
+ /**
94
+ * Requires guest tools to be installed
95
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
96
+ */
97
+ async cleanRebootVm(id, sync) {
98
+ const vmId = id;
99
+ const action = async () => {
100
+ await this.getXapiObject(vmId).$callAsync('clean_reboot');
101
+ };
102
+ return this.createAction(action, {
103
+ sync,
104
+ statusCode: noContentResp.status,
105
+ taskProperties: {
106
+ name: 'clean reboot VM',
107
+ objectId: vmId,
108
+ },
109
+ });
110
+ }
111
+ /**
112
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
113
+ */
114
+ async hardShutdownVm(id, sync) {
115
+ const vmId = id;
116
+ const action = async () => {
117
+ await this.getXapiObject(vmId).$callAsync('hard_shutdown');
118
+ };
119
+ return this.createAction(action, {
120
+ sync,
121
+ statusCode: noContentResp.status,
122
+ taskProperties: {
123
+ name: 'hard shutdown VM',
124
+ objectId: vmId,
125
+ },
126
+ });
127
+ }
128
+ /**
129
+ * @example id "f07ab729-c0e8-721c-45ec-f11276377030"
130
+ */
131
+ async hardRebootVm(id, sync) {
132
+ const vmId = id;
133
+ const action = async () => {
134
+ await this.getXapiObject(vmId).$callAsync('hard_reboot');
135
+ };
136
+ return this.createAction(action, {
137
+ sync,
138
+ statusCode: noContentResp.status,
139
+ taskProperties: {
140
+ name: 'hard reboot VM',
141
+ objectId: vmId,
142
+ },
143
+ });
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
+ }
73
169
  };
74
170
  __decorate([
75
171
  Example(vmIds),
@@ -104,6 +200,53 @@ __decorate([
104
200
  __param(0, Path()),
105
201
  __param(1, Query())
106
202
  ], VmController.prototype, "startVm", null);
203
+ __decorate([
204
+ Example(taskLocation),
205
+ Post('{id}/actions/clean_shutdown'),
206
+ SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
207
+ Response(noContentResp.status, noContentResp.description),
208
+ Response(notFoundResp.status, notFoundResp.description),
209
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
210
+ __param(0, Path()),
211
+ __param(1, Query())
212
+ ], VmController.prototype, "cleanShutdownVm", null);
213
+ __decorate([
214
+ Example(taskLocation),
215
+ Post('{id}/actions/clean_reboot'),
216
+ __param(0, Path()),
217
+ __param(1, Query())
218
+ ], VmController.prototype, "cleanRebootVm", null);
219
+ __decorate([
220
+ Example(taskLocation),
221
+ Post('{id}/actions/hard_shutdown'),
222
+ SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
223
+ Response(noContentResp.status, noContentResp.description),
224
+ Response(notFoundResp.status, notFoundResp.description),
225
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
226
+ __param(0, Path()),
227
+ __param(1, Query())
228
+ ], VmController.prototype, "hardShutdownVm", null);
229
+ __decorate([
230
+ Example(taskLocation),
231
+ Post('{id}/actions/hard_reboot'),
232
+ SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
233
+ Response(noContentResp.status, noContentResp.description),
234
+ Response(notFoundResp.status, notFoundResp.description),
235
+ Response(internalServerErrorResp.status, internalServerErrorResp.description),
236
+ __param(0, Path()),
237
+ __param(1, Query())
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);
107
250
  VmController = __decorate([
108
251
  Route('vms'),
109
252
  Security('*'),