@xen-orchestra/rest-api 0.5.0 → 0.7.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 +1 -0
- package/dist/groups/group.controller.mjs +60 -0
- package/dist/middlewares/generic-error-handler.middleware.mjs +8 -1
- package/dist/networks/network.controller.mjs +59 -0
- package/dist/open-api/common/response.common.mjs +12 -0
- package/dist/open-api/oa-examples/group.oa-example.mjs +23 -0
- package/dist/open-api/oa-examples/network.oa-example.mjs +50 -0
- package/dist/open-api/oa-examples/server.oa-example.mjs +1 -0
- package/dist/open-api/routes/routes.js +362 -0
- package/dist/servers/server.controller.mjs +75 -3
- package/dist/servers/server.type.mjs +1 -0
- package/dist/vms/vm.controller.mjs +106 -0
- package/open-api/spec/swagger.json +1087 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -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 { group, groupIds, partialGroups } from '../open-api/oa-examples/group.oa-example.mjs';
|
|
14
|
+
import { XoController } from '../abstract-classes/xo-controller.mjs';
|
|
15
|
+
let GroupController = class GroupController extends XoController {
|
|
16
|
+
// --- abstract methods
|
|
17
|
+
getAllCollectionObjects() {
|
|
18
|
+
return this.restApi.xoApp.getAllGroups();
|
|
19
|
+
}
|
|
20
|
+
getCollectionObject(id) {
|
|
21
|
+
return this.restApi.xoApp.getGroup(id);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @example fields "name,id,users"
|
|
25
|
+
* @example filter "users:length:>0"
|
|
26
|
+
* @example limit 42
|
|
27
|
+
*/
|
|
28
|
+
async getGroups(req, fields, filter, limit) {
|
|
29
|
+
return this.sendObjects(Object.values(await this.getObjects({ filter, limit })), req);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @example id "7d98fee4-3357-41a7-ac3f-9124212badb7"
|
|
33
|
+
*/
|
|
34
|
+
getGroup(id) {
|
|
35
|
+
return this.getObject(id);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
__decorate([
|
|
39
|
+
Example(groupIds),
|
|
40
|
+
Example(partialGroups),
|
|
41
|
+
Get(''),
|
|
42
|
+
__param(0, Request()),
|
|
43
|
+
__param(1, Query()),
|
|
44
|
+
__param(2, Query()),
|
|
45
|
+
__param(3, Query())
|
|
46
|
+
], GroupController.prototype, "getGroups", null);
|
|
47
|
+
__decorate([
|
|
48
|
+
Example(group),
|
|
49
|
+
Get('{id}'),
|
|
50
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
51
|
+
__param(0, Path())
|
|
52
|
+
], GroupController.prototype, "getGroup", null);
|
|
53
|
+
GroupController = __decorate([
|
|
54
|
+
Route('groups'),
|
|
55
|
+
Security('*'),
|
|
56
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
57
|
+
Tags('groups'),
|
|
58
|
+
provide(GroupController)
|
|
59
|
+
], GroupController);
|
|
60
|
+
export { GroupController };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createLogger } from '@xen-orchestra/log';
|
|
2
|
-
import { featureUnauthorized, forbiddenOperation, invalidCredentials, invalidParameters, noSuchObject, notImplemented, unauthorized, } from 'xo-common/api-errors.js';
|
|
2
|
+
import { featureUnauthorized, forbiddenOperation, incorrectState, invalidCredentials, invalidParameters, noSuchObject, notImplemented, objectAlreadyExists, unauthorized, } from 'xo-common/api-errors.js';
|
|
3
3
|
const log = createLogger('xo:rest-api:error-handler');
|
|
4
4
|
// must have 4 parameters to be recognized as an error middleware by express
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -19,12 +19,19 @@ export default function genericErrorHandler(error, req, res, _next) {
|
|
|
19
19
|
else if (invalidCredentials.is(error)) {
|
|
20
20
|
res.status(401);
|
|
21
21
|
}
|
|
22
|
+
else if (objectAlreadyExists.is(error)) {
|
|
23
|
+
res.status(409);
|
|
24
|
+
}
|
|
22
25
|
else if (invalidParameters.is(error)) {
|
|
23
26
|
res.status(422);
|
|
24
27
|
}
|
|
25
28
|
else if (notImplemented.is(error)) {
|
|
26
29
|
res.status(501);
|
|
27
30
|
}
|
|
31
|
+
else if (incorrectState.is(error)) {
|
|
32
|
+
res.status(409);
|
|
33
|
+
responseError.data = error.data;
|
|
34
|
+
}
|
|
28
35
|
else {
|
|
29
36
|
if (error.name === 'XapiError') {
|
|
30
37
|
responseError.info = 'This is a XenServer/XCP-ng error, not an XO error';
|
|
@@ -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, Response, Request, Route, Security, Tags } from 'tsoa';
|
|
11
|
+
import { inject } from 'inversify';
|
|
12
|
+
import { provide } from 'inversify-binding-decorators';
|
|
13
|
+
import { network, networkIds, partialNetworks } from '../open-api/oa-examples/network.oa-example.mjs';
|
|
14
|
+
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
15
|
+
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
16
|
+
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
17
|
+
let NetworkController = class NetworkController extends XapiXoController {
|
|
18
|
+
constructor(restApi) {
|
|
19
|
+
super('network', restApi);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @example fields "nbd,name_label,id"
|
|
23
|
+
* @example filter "nbd?"
|
|
24
|
+
* @example limit 42
|
|
25
|
+
*/
|
|
26
|
+
getNetworks(req, fields, filter, limit) {
|
|
27
|
+
return this.sendObjects(Object.values(this.getObjects({ filter, limit })), req);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @example id "9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f"
|
|
31
|
+
*/
|
|
32
|
+
getNetwork(id) {
|
|
33
|
+
return this.getObject(id);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
__decorate([
|
|
37
|
+
Example(networkIds),
|
|
38
|
+
Example(partialNetworks),
|
|
39
|
+
Get(''),
|
|
40
|
+
__param(0, Request()),
|
|
41
|
+
__param(1, Query()),
|
|
42
|
+
__param(2, Query()),
|
|
43
|
+
__param(3, Query())
|
|
44
|
+
], NetworkController.prototype, "getNetworks", null);
|
|
45
|
+
__decorate([
|
|
46
|
+
Example(network),
|
|
47
|
+
Get('{id}'),
|
|
48
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
49
|
+
__param(0, Path())
|
|
50
|
+
], NetworkController.prototype, "getNetwork", null);
|
|
51
|
+
NetworkController = __decorate([
|
|
52
|
+
Route('networks'),
|
|
53
|
+
Security('*'),
|
|
54
|
+
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
55
|
+
Tags('networks'),
|
|
56
|
+
provide(NetworkController),
|
|
57
|
+
__param(0, inject(RestApi))
|
|
58
|
+
], NetworkController);
|
|
59
|
+
export { NetworkController };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export const createdResp = {
|
|
2
|
+
status: 201,
|
|
3
|
+
description: 'Resource created',
|
|
4
|
+
};
|
|
1
5
|
export const actionAsyncroneResp = {
|
|
2
6
|
status: 202,
|
|
3
7
|
description: 'Action executed asynchronously',
|
|
@@ -23,3 +27,11 @@ export const internalServerErrorResp = {
|
|
|
23
27
|
status: 500,
|
|
24
28
|
description: 'Internal server error, XenServer/XCP-ng error',
|
|
25
29
|
};
|
|
30
|
+
export const resourceAlreadyExists = {
|
|
31
|
+
status: 409,
|
|
32
|
+
description: 'Resource already exists',
|
|
33
|
+
};
|
|
34
|
+
export const invalidParameters = {
|
|
35
|
+
status: 422,
|
|
36
|
+
description: 'Invalid parameters',
|
|
37
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const groupIds = [
|
|
2
|
+
'/rest/v0/groups/7d98fee4-3357-41a7-ac3f-9124212badb7',
|
|
3
|
+
'/rest/v0/groups/7981ba62-c395-4546-bfa4-d1261653a77f',
|
|
4
|
+
];
|
|
5
|
+
export const partialGroups = [
|
|
6
|
+
{
|
|
7
|
+
name: 'group 1',
|
|
8
|
+
id: '7d98fee4-3357-41a7-ac3f-9124212badb7',
|
|
9
|
+
users: ['722d17b9-699b-49d2-8193-be1ac573d3de'],
|
|
10
|
+
href: '/rest/v0/groups/7d98fee4-3357-41a7-ac3f-9124212badb7',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
name: 'group 2',
|
|
14
|
+
id: '7981ba62-c395-4546-bfa4-d1261653a77f',
|
|
15
|
+
users: ['722d17b9-699b-49d2-8193-be1ac573d3de', '088124f3-41b6-4258-9653-6eedc7b46111'],
|
|
16
|
+
href: '/rest/v0/groups/7981ba62-c395-4546-bfa4-d1261653a77f',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
export const group = {
|
|
20
|
+
name: 'group 1',
|
|
21
|
+
users: ['722d17b9-699b-49d2-8193-be1ac573d3de'],
|
|
22
|
+
id: '7d98fee4-3357-41a7-ac3f-9124212badb7',
|
|
23
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const networkIds = [
|
|
2
|
+
'/rest/v0/networks/9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
|
|
3
|
+
'/rest/v0/networks/6b6ca0f5-6611-0636-4b0a-1fb1c8e96414',
|
|
4
|
+
];
|
|
5
|
+
export const partialNetworks = [
|
|
6
|
+
{
|
|
7
|
+
nbd: true,
|
|
8
|
+
name_label: 'Host internal management network',
|
|
9
|
+
id: '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
|
|
10
|
+
href: '/rest/v0/networks/9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
nbd: true,
|
|
14
|
+
name_label: 'Lab v2 (VLAN 11)',
|
|
15
|
+
id: '6b6ca0f5-6611-0636-4b0a-1fb1c8e96414',
|
|
16
|
+
href: '/rest/v0/networks/6b6ca0f5-6611-0636-4b0a-1fb1c8e96414',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
export const network = {
|
|
20
|
+
automatic: false,
|
|
21
|
+
bridge: 'xenapi',
|
|
22
|
+
current_operations: {},
|
|
23
|
+
defaultIsLocked: false,
|
|
24
|
+
MTU: 1500,
|
|
25
|
+
name_description: 'Network on which guests will be assigned a private link-local IP address which can be used to talk XenAPI',
|
|
26
|
+
name_label: 'Host internal management network',
|
|
27
|
+
other_config: {
|
|
28
|
+
is_guest_installer_network: 'true',
|
|
29
|
+
is_host_internal_management_network: 'true',
|
|
30
|
+
ip_begin: '169.254.0.1',
|
|
31
|
+
ip_end: '169.254.255.254',
|
|
32
|
+
netmask: '255.255.0.0',
|
|
33
|
+
},
|
|
34
|
+
tags: [],
|
|
35
|
+
PIFs: [],
|
|
36
|
+
VIFs: [
|
|
37
|
+
'2d039fc8-e522-75db-34c9-536b9553bd5a',
|
|
38
|
+
'38623621-d30e-0307-dcef-eb7ed6c69f0c',
|
|
39
|
+
'cc4b090f-5ff1-254b-558f-f7ac237e6fc5',
|
|
40
|
+
'a9f3d042-a2e1-102f-74fc-ff1df41c6eb3',
|
|
41
|
+
],
|
|
42
|
+
nbd: false,
|
|
43
|
+
insecureNbd: false,
|
|
44
|
+
id: '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
|
|
45
|
+
type: 'network',
|
|
46
|
+
uuid: '9fe12ca3-d75d-cfb0-492e-cfd2bc6c568f',
|
|
47
|
+
$pool: 'b7569d99-30f8-178a-7d94-801de3e29b5b',
|
|
48
|
+
$poolId: 'b7569d99-30f8-178a-7d94-801de3e29b5b',
|
|
49
|
+
_xapiRef: 'OpaqueRef:eb906e77-2221-5399-4a26-60f0ad069b61',
|
|
50
|
+
};
|