@xen-orchestra/rest-api 0.1.2 → 0.3.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.
- package/README.md +2 -0
- package/dist/abstract-classes/base-controller.mjs +37 -0
- package/dist/abstract-classes/xapi-xo-controller.mjs +5 -10
- package/dist/abstract-classes/xo-controller.mjs +40 -0
- package/dist/helpers/object-wrapper.helper.mjs +2 -2
- package/dist/hosts/host.controller.mjs +75 -0
- package/dist/index.mjs +4 -3
- package/dist/middlewares/generic-error-handler.middleware.mjs +5 -1
- package/dist/open-api/common/response.common.mjs +21 -0
- package/dist/open-api/oa-examples/host.oa-example.mjs +777 -0
- package/dist/open-api/oa-examples/server.oa-example.mjs +28 -0
- package/dist/open-api/oa-examples/sr.oa-example.mjs +81 -0
- package/dist/open-api/oa-examples/task.oa-example.mjs +1 -0
- package/dist/open-api/oa-examples/vbd.oa-example.mjs +34 -0
- package/dist/open-api/oa-examples/vdi-snapshot.oa-example.mjs +42 -0
- package/dist/open-api/oa-examples/vdi.oa-example.mjs +84 -0
- package/dist/open-api/oa-examples/vm-controller.oa-example.mjs +71 -0
- package/dist/open-api/oa-examples/vm-snapshot.oa-example.mjs +178 -0
- package/dist/open-api/oa-examples/vm-template.oa-example.mjs +91 -0
- package/dist/open-api/oa-examples/vm.oa-example.mjs +144 -0
- package/dist/open-api/routes/routes.js +833 -23
- package/dist/rest-api/rest-api.mjs +9 -0
- package/dist/servers/server.controller.mjs +60 -0
- package/dist/srs/sr.controller.mjs +59 -0
- package/dist/vbds/vbd.controller.mjs +61 -0
- package/dist/vdi-snapshots/vdi-snapshot.controller.mjs +59 -0
- package/dist/vdis/vdi.controller.mjs +59 -0
- package/dist/vm-controller/vm-controller.controller.mjs +60 -0
- package/dist/vm-snapshots/vm-snapshot.controller.mjs +60 -0
- package/dist/vm-templates/vm-template.controller.mjs +59 -0
- package/dist/vms/vm.controller.mjs +60 -4
- package/open-api/spec/swagger.json +13933 -384
- package/package.json +2 -2
- package/tsoa.json +3 -0
|
@@ -3,6 +3,12 @@ export class RestApi {
|
|
|
3
3
|
constructor(xoApp) {
|
|
4
4
|
this.#xoApp = xoApp;
|
|
5
5
|
}
|
|
6
|
+
get tasks() {
|
|
7
|
+
return this.#xoApp.tasks;
|
|
8
|
+
}
|
|
9
|
+
get xoApp() {
|
|
10
|
+
return this.#xoApp;
|
|
11
|
+
}
|
|
6
12
|
authenticateUser(...args) {
|
|
7
13
|
return this.#xoApp.authenticateUser(...args);
|
|
8
14
|
}
|
|
@@ -12,6 +18,9 @@ export class RestApi {
|
|
|
12
18
|
getObjectsByType(type, opts) {
|
|
13
19
|
return this.#xoApp.getObjectsByType(type, opts);
|
|
14
20
|
}
|
|
21
|
+
getXapiObject(maybeId, type) {
|
|
22
|
+
return this.#xoApp.getXapiObject(maybeId, type);
|
|
23
|
+
}
|
|
15
24
|
runWithApiContext(...args) {
|
|
16
25
|
return this.#xoApp.runWithApiContext(...args);
|
|
17
26
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { 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';
|
|
14
|
+
import { XoController } from '../abstract-classes/xo-controller.mjs';
|
|
15
|
+
let ServerController = class ServerController extends XoController {
|
|
16
|
+
// --- abstract methods
|
|
17
|
+
getAllCollectionObjects() {
|
|
18
|
+
return this.restApi.xoApp.getAllXenServers();
|
|
19
|
+
}
|
|
20
|
+
getCollectionObject(id) {
|
|
21
|
+
return this.restApi.xoApp.getXenServer(id);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @example fields "status,id"
|
|
25
|
+
* @example filter "status:/^connected$/"
|
|
26
|
+
* @example limit 42
|
|
27
|
+
*/
|
|
28
|
+
async getServers(req, fields, filter, limit) {
|
|
29
|
+
return this.sendObjects(Object.values(await this.getObjects({ filter, limit })), req);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @example id "f07ab729-c0e8-721c-45ec-f11276377030"
|
|
33
|
+
*/
|
|
34
|
+
getServer(id) {
|
|
35
|
+
return this.getObject(id);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
Example(serverIds),
|
|
40
|
+
Example(partialServers),
|
|
41
|
+
Get(''),
|
|
42
|
+
__param(0, Request()),
|
|
43
|
+
__param(1, Query()),
|
|
44
|
+
__param(2, Query()),
|
|
45
|
+
__param(3, Query())
|
|
46
|
+
], ServerController.prototype, "getServers", null);
|
|
47
|
+
__decorate([
|
|
48
|
+
Example(server),
|
|
49
|
+
Get('{id}'),
|
|
50
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
51
|
+
__param(0, Path())
|
|
52
|
+
], ServerController.prototype, "getServer", null);
|
|
53
|
+
ServerController = __decorate([
|
|
54
|
+
Route('servers'),
|
|
55
|
+
Security('*'),
|
|
56
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
57
|
+
Tags('servers'),
|
|
58
|
+
provide(ServerController)
|
|
59
|
+
], ServerController);
|
|
60
|
+
export { ServerController };
|
|
@@ -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 { partialSrs, sr, srIds } from '../open-api/oa-examples/sr.oa-example.mjs';
|
|
15
|
+
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
16
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
17
|
+
let SrController = class SrController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('SR', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @example fields "uuid,name_label,allocationStrategy"
|
|
23
|
+
* @example filter "allocationStrategy:thin"
|
|
24
|
+
* @example limit 42
|
|
25
|
+
*/
|
|
26
|
+
getSrs(req, fields, filter, limit) {
|
|
27
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @example id "c4284e12-37c9-7967-b9e8-83ef229c3e03"
|
|
31
|
+
*/
|
|
32
|
+
getSr(id) {
|
|
33
|
+
return this.getObject(id);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Example(srIds),
|
|
38
|
+
Example(partialSrs),
|
|
39
|
+
Get(''),
|
|
40
|
+
__param(0, Request()),
|
|
41
|
+
__param(1, Query()),
|
|
42
|
+
__param(2, Query()),
|
|
43
|
+
__param(3, Query())
|
|
44
|
+
], SrController.prototype, "getSrs", null);
|
|
45
|
+
__decorate([
|
|
46
|
+
Example(sr),
|
|
47
|
+
Get('{id}'),
|
|
48
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
49
|
+
__param(0, Path())
|
|
50
|
+
], SrController.prototype, "getSr", null);
|
|
51
|
+
SrController = __decorate([
|
|
52
|
+
Route('srs'),
|
|
53
|
+
Security('*'),
|
|
54
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
55
|
+
Tags('srs'),
|
|
56
|
+
provide(SrController),
|
|
57
|
+
__param(0, inject(RestApi))
|
|
58
|
+
], SrController);
|
|
59
|
+
export { SrController };
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { partialVbds, vbd, vbdIds } from '../open-api/oa-examples/vbd.oa-example.mjs';
|
|
15
|
+
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
16
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
17
|
+
let VbdController = class VbdController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('VBD', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @example fields "device,bootable,uuid"
|
|
24
|
+
* @example filter "!bootable?"
|
|
25
|
+
* @example limit 42
|
|
26
|
+
*/
|
|
27
|
+
getVbds(req, fields, filter, limit) {
|
|
28
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @example id "f07ab729-c0e8-721c-45ec-f11276377030"
|
|
33
|
+
*/
|
|
34
|
+
getVbd(id) {
|
|
35
|
+
return this.getObject(id);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
Example(vbdIds),
|
|
40
|
+
Example(partialVbds),
|
|
41
|
+
Get(''),
|
|
42
|
+
__param(0, Request()),
|
|
43
|
+
__param(1, Query()),
|
|
44
|
+
__param(2, Query()),
|
|
45
|
+
__param(3, Query())
|
|
46
|
+
], VbdController.prototype, "getVbds", null);
|
|
47
|
+
__decorate([
|
|
48
|
+
Example(vbd),
|
|
49
|
+
Get('{id}'),
|
|
50
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
51
|
+
__param(0, Path())
|
|
52
|
+
], VbdController.prototype, "getVbd", null);
|
|
53
|
+
VbdController = __decorate([
|
|
54
|
+
Route('vbds'),
|
|
55
|
+
Security('*'),
|
|
56
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
57
|
+
Tags('vbds'),
|
|
58
|
+
provide(VbdController),
|
|
59
|
+
__param(0, inject(RestApi))
|
|
60
|
+
], VbdController);
|
|
61
|
+
export { VbdController };
|
|
@@ -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 { RestApi } from '../rest-api/rest-api.mjs';
|
|
15
|
+
import { partialVdiSnapshots, vdiSnapshot, vdiSnapshotIds } from '../open-api/oa-examples/vdi-snapshot.oa-example.mjs';
|
|
16
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
17
|
+
let VdiSnapshotController = class VdiSnapshotController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('VDI-snapshot', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @example fields "uuid,snapshot_time,$snapshot_of"
|
|
23
|
+
* @example filter "snapshot_time:>1725020038"
|
|
24
|
+
* @example limit 42
|
|
25
|
+
*/
|
|
26
|
+
getVdiSnapshots(req, fields, filter, limit) {
|
|
27
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @example id "d2727772-735b-478f-b6f9-11e7db56dfd0"
|
|
31
|
+
*/
|
|
32
|
+
getVdiSnapshot(id) {
|
|
33
|
+
return this.getObject(id);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Example(vdiSnapshotIds),
|
|
38
|
+
Example(partialVdiSnapshots),
|
|
39
|
+
Get(''),
|
|
40
|
+
__param(0, Request()),
|
|
41
|
+
__param(1, Query()),
|
|
42
|
+
__param(2, Query()),
|
|
43
|
+
__param(3, Query())
|
|
44
|
+
], VdiSnapshotController.prototype, "getVdiSnapshots", null);
|
|
45
|
+
__decorate([
|
|
46
|
+
Example(vdiSnapshot),
|
|
47
|
+
Get('{id}'),
|
|
48
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
49
|
+
__param(0, Path())
|
|
50
|
+
], VdiSnapshotController.prototype, "getVdiSnapshot", null);
|
|
51
|
+
VdiSnapshotController = __decorate([
|
|
52
|
+
Route('vdi-snapshots'),
|
|
53
|
+
Security('*'),
|
|
54
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
55
|
+
Tags('vdis'),
|
|
56
|
+
provide(VdiSnapshotController),
|
|
57
|
+
__param(0, inject(RestApi))
|
|
58
|
+
], VdiSnapshotController);
|
|
59
|
+
export { VdiSnapshotController };
|
|
@@ -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 { RestApi } from '../rest-api/rest-api.mjs';
|
|
15
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
16
|
+
import { partialVdis, vdi, vdiIds } from '../open-api/oa-examples/vdi.oa-example.mjs';
|
|
17
|
+
let VdiController = class VdiController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('VDI', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @example fields "*"
|
|
23
|
+
* @example filter "snapshots:length:>2"
|
|
24
|
+
* @example limit 42
|
|
25
|
+
*/
|
|
26
|
+
getVdis(req, fields, filter, limit) {
|
|
27
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @example id "c77f9955-c1d2-4b39-aa1c-73cdb2dacb7e"
|
|
31
|
+
*/
|
|
32
|
+
getVdi(id) {
|
|
33
|
+
return this.getObject(id);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Example(vdiIds),
|
|
38
|
+
Example(partialVdis),
|
|
39
|
+
Get(''),
|
|
40
|
+
__param(0, Request()),
|
|
41
|
+
__param(1, Query()),
|
|
42
|
+
__param(2, Query()),
|
|
43
|
+
__param(3, Query())
|
|
44
|
+
], VdiController.prototype, "getVdis", null);
|
|
45
|
+
__decorate([
|
|
46
|
+
Example(vdi),
|
|
47
|
+
Get('{id}'),
|
|
48
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
49
|
+
__param(0, Path())
|
|
50
|
+
], VdiController.prototype, "getVdi", null);
|
|
51
|
+
VdiController = __decorate([
|
|
52
|
+
Route('vdis'),
|
|
53
|
+
Security('*'),
|
|
54
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
55
|
+
Tags('vdis'),
|
|
56
|
+
provide(VdiController),
|
|
57
|
+
__param(0, inject(RestApi))
|
|
58
|
+
], VdiController);
|
|
59
|
+
export { VdiController };
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { inject } from 'inversify';
|
|
11
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
12
|
+
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
13
|
+
import { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
|
|
14
|
+
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
15
|
+
import { provide } from 'inversify-binding-decorators';
|
|
16
|
+
import { partialVmControllers, vmController, vmControllerIds, } from '../open-api/oa-examples/vm-controller.oa-example.mjs';
|
|
17
|
+
let VmControllerController = class VmControllerController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('VM-controller', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @example fields "type,uuid"
|
|
24
|
+
* @example filter "power_state:Running"
|
|
25
|
+
* @example limit 42
|
|
26
|
+
*/
|
|
27
|
+
getVmControllers(req, fields, filter, limit) {
|
|
28
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @example id "9b4775bd-9493-490a-9afa-f786a44caa4f"
|
|
32
|
+
*/
|
|
33
|
+
getVmController(id) {
|
|
34
|
+
return this.getObject(id);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
Example(vmControllerIds),
|
|
39
|
+
Example(partialVmControllers),
|
|
40
|
+
Get(''),
|
|
41
|
+
__param(0, Request()),
|
|
42
|
+
__param(1, Query()),
|
|
43
|
+
__param(2, Query()),
|
|
44
|
+
__param(3, Query())
|
|
45
|
+
], VmControllerController.prototype, "getVmControllers", null);
|
|
46
|
+
__decorate([
|
|
47
|
+
Example(vmController),
|
|
48
|
+
Get('{id}'),
|
|
49
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
50
|
+
__param(0, Path())
|
|
51
|
+
], VmControllerController.prototype, "getVmController", null);
|
|
52
|
+
VmControllerController = __decorate([
|
|
53
|
+
Route('vm-controllers'),
|
|
54
|
+
Security('*'),
|
|
55
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
56
|
+
Tags('vms'),
|
|
57
|
+
provide(VmControllerController),
|
|
58
|
+
__param(0, inject(RestApi))
|
|
59
|
+
], VmControllerController);
|
|
60
|
+
export { VmControllerController };
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
13
|
+
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
14
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
15
|
+
import { provide } from 'inversify-binding-decorators';
|
|
16
|
+
import { partialVmSnapshots, vmSnapshot, vmSnapshotIds } from '../open-api/oa-examples/vm-snapshot.oa-example.mjs';
|
|
17
|
+
let VmSnapshotController = class VmSnapshotController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('VM-snapshot', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @example fields "uuid,snapshot_time,$snapshot_of"
|
|
24
|
+
* @example filter "snapshot_time:>1725020038"
|
|
25
|
+
* @example limit 42
|
|
26
|
+
*/
|
|
27
|
+
getVmSnapshots(req, fields, filter, limit) {
|
|
28
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @example id "d68fca2c-41e6-be87-d790-105c1642a090"
|
|
32
|
+
*/
|
|
33
|
+
getVmSnapshot(id) {
|
|
34
|
+
return this.getObject(id);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
__decorate([
|
|
38
|
+
Example(vmSnapshotIds),
|
|
39
|
+
Example(partialVmSnapshots),
|
|
40
|
+
Get(''),
|
|
41
|
+
__param(0, Request()),
|
|
42
|
+
__param(1, Query()),
|
|
43
|
+
__param(2, Query()),
|
|
44
|
+
__param(3, Query())
|
|
45
|
+
], VmSnapshotController.prototype, "getVmSnapshots", null);
|
|
46
|
+
__decorate([
|
|
47
|
+
Example(vmSnapshot),
|
|
48
|
+
Get('{id}'),
|
|
49
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
50
|
+
__param(0, Path())
|
|
51
|
+
], VmSnapshotController.prototype, "getVmSnapshot", null);
|
|
52
|
+
VmSnapshotController = __decorate([
|
|
53
|
+
Route('vm-snapshots'),
|
|
54
|
+
Security('*'),
|
|
55
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
56
|
+
Tags('vms'),
|
|
57
|
+
provide(VmSnapshotController),
|
|
58
|
+
__param(0, inject(RestApi))
|
|
59
|
+
], VmSnapshotController);
|
|
60
|
+
export { VmSnapshotController };
|
|
@@ -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, Security, Query, Request, Response, Route, Tags, Path } 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 { RestApi } from '../rest-api/rest-api.mjs';
|
|
15
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
16
|
+
import { partialVmTemplates, vmTemplate, vmTemplateIds } from '../open-api/oa-examples/vm-template.oa-example.mjs';
|
|
17
|
+
let VmTemplateController = class VmTemplateController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('VM-template', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @example fields "id,isDefaultTemplate,name_label"
|
|
23
|
+
* @example filter "isDefaultTemplate?"
|
|
24
|
+
* @example limit 42
|
|
25
|
+
* */
|
|
26
|
+
getVmTemplates(req, fields, filter, limit) {
|
|
27
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @example id "b7569d99-30f8-178a-7d94-801de3e29b5b-f873abe0-b138-4995-8f6f-498b423d234d"
|
|
31
|
+
* */
|
|
32
|
+
getVmTemplate(id) {
|
|
33
|
+
return this.getObject(id);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Example(vmTemplateIds),
|
|
38
|
+
Example(partialVmTemplates),
|
|
39
|
+
Get(''),
|
|
40
|
+
__param(0, Request()),
|
|
41
|
+
__param(1, Query()),
|
|
42
|
+
__param(2, Query()),
|
|
43
|
+
__param(3, Query())
|
|
44
|
+
], VmTemplateController.prototype, "getVmTemplates", null);
|
|
45
|
+
__decorate([
|
|
46
|
+
Example(vmTemplate),
|
|
47
|
+
Get('{id}'),
|
|
48
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
49
|
+
__param(0, Path())
|
|
50
|
+
], VmTemplateController.prototype, "getVmTemplate", null);
|
|
51
|
+
VmTemplateController = __decorate([
|
|
52
|
+
Route('vm-templates'),
|
|
53
|
+
Security('*'),
|
|
54
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
55
|
+
Tags('vms'),
|
|
56
|
+
provide(VmTemplateController),
|
|
57
|
+
__param(0, inject(RestApi))
|
|
58
|
+
], VmTemplateController);
|
|
59
|
+
export { VmTemplateController };
|
|
@@ -7,11 +7,14 @@ 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 } from 'tsoa';
|
|
10
|
+
import { Example, Get, Path, Post, Query, Request, Response, Route, Security, Tags, SuccessResponse } from 'tsoa';
|
|
11
11
|
import { inject } from 'inversify';
|
|
12
|
+
import { incorrectState, invalidParameters } from 'xo-common/api-errors.js';
|
|
12
13
|
import { provide } from 'inversify-binding-decorators';
|
|
13
|
-
import {
|
|
14
|
+
import { actionAsyncroneResp, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
|
|
15
|
+
import { partialVms, vm, vmIds, vmStatsExample } from '../open-api/oa-examples/vm.oa-example.mjs';
|
|
14
16
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
17
|
+
import { taskLocation } from '../open-api/oa-examples/task.oa-example.mjs';
|
|
15
18
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
16
19
|
let VmController = class VmController extends XapiXoController {
|
|
17
20
|
constructor(restApi) {
|
|
@@ -33,6 +36,40 @@ let VmController = class VmController extends XapiXoController {
|
|
|
33
36
|
getVm(id) {
|
|
34
37
|
return this.getObject(id);
|
|
35
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* VM must be running
|
|
42
|
+
*
|
|
43
|
+
* @example id "f07ab729-c0e8-721c-45ec-f11276377030"
|
|
44
|
+
*/
|
|
45
|
+
async getVmStats(id, granularity) {
|
|
46
|
+
try {
|
|
47
|
+
return await this.restApi.xoApp.getXapiVmStats(id, granularity);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (incorrectState.is(error, {
|
|
51
|
+
property: 'resident_on',
|
|
52
|
+
})) {
|
|
53
|
+
/* throw */ invalidParameters(`VM ${id} is halted or host could not be found.`, error);
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @example id "f07ab729-c0e8-721c-45ec-f11276377030"
|
|
60
|
+
*/
|
|
61
|
+
async startVm(id, sync) {
|
|
62
|
+
const vmId = id;
|
|
63
|
+
const action = () => this.getXapiObject(vmId).$callAsync('start', false, false);
|
|
64
|
+
return this.createAction(action, {
|
|
65
|
+
sync,
|
|
66
|
+
statusCode: noContentResp.status,
|
|
67
|
+
taskProperties: {
|
|
68
|
+
name: 'start VM',
|
|
69
|
+
objectId: vmId,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
}
|
|
36
73
|
};
|
|
37
74
|
__decorate([
|
|
38
75
|
Example(vmIds),
|
|
@@ -46,13 +83,32 @@ __decorate([
|
|
|
46
83
|
__decorate([
|
|
47
84
|
Example(vm),
|
|
48
85
|
Get('{id}'),
|
|
49
|
-
Response(
|
|
86
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
50
87
|
__param(0, Path())
|
|
51
88
|
], VmController.prototype, "getVm", null);
|
|
89
|
+
__decorate([
|
|
90
|
+
Example(vmStatsExample),
|
|
91
|
+
Get('{id}/stats'),
|
|
92
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
93
|
+
Response(422, 'Invalid granularity, VM is halted or host could not be found'),
|
|
94
|
+
__param(0, Path()),
|
|
95
|
+
__param(1, Query())
|
|
96
|
+
], VmController.prototype, "getVmStats", null);
|
|
97
|
+
__decorate([
|
|
98
|
+
Example(taskLocation),
|
|
99
|
+
Post('{id}/actions/start'),
|
|
100
|
+
SuccessResponse(actionAsyncroneResp.status, actionAsyncroneResp.description, actionAsyncroneResp.produce),
|
|
101
|
+
Response(noContentResp.status, noContentResp.description),
|
|
102
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
103
|
+
Response(internalServerErrorResp.status, internalServerErrorResp.description),
|
|
104
|
+
__param(0, Path()),
|
|
105
|
+
__param(1, Query())
|
|
106
|
+
], VmController.prototype, "startVm", null);
|
|
52
107
|
VmController = __decorate([
|
|
53
108
|
Route('vms'),
|
|
54
109
|
Security('*'),
|
|
55
|
-
Response(
|
|
110
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
111
|
+
Tags('vms')
|
|
56
112
|
// the `provide` decorator is mandatory on class that injects/receives dependencies.
|
|
57
113
|
// It automatically bind the class to the IOC container that handles dependency injection
|
|
58
114
|
,
|