@xen-orchestra/rest-api 0.11.0 → 0.13.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/dist/abstract-classes/base-controller.mjs +2 -2
- package/dist/alarms/alarm.controller.mjs +10 -60
- package/dist/alarms/alarm.service.mjs +67 -0
- package/dist/backup-repositories/backup-repositories.controller.mjs +61 -0
- package/dist/groups/group.controller.mjs +95 -3
- package/dist/groups/group.type.mjs +1 -0
- package/dist/helpers/object-wrapper.helper.mjs +8 -1
- package/dist/helpers/utils.helper.mjs +74 -1
- package/dist/hosts/host.controller.mjs +57 -2
- package/dist/hosts/host.service.mjs +78 -0
- package/dist/ioc/ioc.mjs +25 -1
- package/dist/messages/message.controller.mjs +1 -1
- package/dist/middlewares/generic-error-handler.middleware.mjs +4 -3
- package/dist/networks/network.controller.mjs +34 -2
- package/dist/open-api/common/response.common.mjs +4 -0
- package/dist/open-api/oa-examples/alarm.oa-example.mjs +12 -0
- package/dist/open-api/oa-examples/backup-repository.oa-example.mjs +31 -0
- package/dist/open-api/oa-examples/group.oa-example.mjs +3 -0
- package/dist/open-api/oa-examples/pool.oa-example.mjs +201 -0
- package/dist/open-api/oa-examples/user.oa-example.mjs +1 -0
- package/dist/open-api/routes/routes.js +943 -116
- package/dist/pifs/pif.controller.mjs +34 -2
- package/dist/pools/pool.controller.mjs +70 -3
- package/dist/pools/pool.service.mjs +212 -0
- package/dist/rest-api/rest-api.mjs +6 -1
- package/dist/srs/sr.controller.mjs +34 -2
- package/dist/users/user.controller.mjs +74 -3
- package/dist/users/user.type.mjs +1 -0
- package/dist/vbds/vbd.controller.mjs +34 -2
- package/dist/vdi-snapshots/vdi-snapshot.controller.mjs +34 -2
- package/dist/vdis/vdi.controller.mjs +34 -2
- package/dist/vifs/vif.controller.mjs +34 -2
- package/dist/vm-controller/vm-controller.controller.mjs +34 -2
- package/dist/vm-snapshots/vm-snapshot.controller.mjs +34 -2
- package/dist/vm-templates/vm-template.controller.mjs +34 -2
- package/dist/vms/vm.controller.mjs +34 -2
- package/dist/vms/vm.service.mjs +40 -0
- package/dist/xoa/xoa.service.mjs +96 -110
- package/open-api/spec/swagger.json +4302 -1417
- package/package.json +3 -3
|
@@ -10,13 +10,18 @@ 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 { provide } from 'inversify-binding-decorators';
|
|
13
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
13
14
|
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
14
15
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
15
16
|
import { partialVdiSnapshots, vdiSnapshot, vdiSnapshotIds } from '../open-api/oa-examples/vdi-snapshot.oa-example.mjs';
|
|
16
17
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
18
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
19
|
+
import { AlarmService } from '../alarms/alarm.service.mjs';
|
|
17
20
|
let VdiSnapshotController = class VdiSnapshotController extends XapiXoController {
|
|
18
|
-
|
|
21
|
+
#alarmService;
|
|
22
|
+
constructor(restApi, alarmService) {
|
|
19
23
|
super('VDI-snapshot', restApi);
|
|
24
|
+
this.#alarmService = alarmService;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* @example fields "uuid,snapshot_time,$snapshot_of"
|
|
@@ -32,6 +37,20 @@ let VdiSnapshotController = class VdiSnapshotController extends XapiXoController
|
|
|
32
37
|
getVdiSnapshot(id) {
|
|
33
38
|
return this.getObject(id);
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @example id "d2727772-735b-478f-b6f9-11e7db56dfd0"
|
|
42
|
+
* @example fields "id,time"
|
|
43
|
+
* @example filter "time:>1747053793"
|
|
44
|
+
* @example limit 42
|
|
45
|
+
*/
|
|
46
|
+
getVdiSnapshotAlarms(req, id, fields, ndjson, filter, limit) {
|
|
47
|
+
const vdiSnapshot = this.getObject(id);
|
|
48
|
+
const alarms = this.#alarmService.getAlarms({
|
|
49
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vdiSnapshot.uuid}`,
|
|
50
|
+
limit,
|
|
51
|
+
});
|
|
52
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
53
|
+
}
|
|
35
54
|
};
|
|
36
55
|
__decorate([
|
|
37
56
|
Example(vdiSnapshotIds),
|
|
@@ -49,12 +68,25 @@ __decorate([
|
|
|
49
68
|
Response(notFoundResp.status, notFoundResp.description),
|
|
50
69
|
__param(0, Path())
|
|
51
70
|
], VdiSnapshotController.prototype, "getVdiSnapshot", null);
|
|
71
|
+
__decorate([
|
|
72
|
+
Example(genericAlarmsExample),
|
|
73
|
+
Get('{id}/alarms'),
|
|
74
|
+
Tags('alarms'),
|
|
75
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
76
|
+
__param(0, Request()),
|
|
77
|
+
__param(1, Path()),
|
|
78
|
+
__param(2, Query()),
|
|
79
|
+
__param(3, Query()),
|
|
80
|
+
__param(4, Query()),
|
|
81
|
+
__param(5, Query())
|
|
82
|
+
], VdiSnapshotController.prototype, "getVdiSnapshotAlarms", null);
|
|
52
83
|
VdiSnapshotController = __decorate([
|
|
53
84
|
Route('vdi-snapshots'),
|
|
54
85
|
Security('*'),
|
|
55
86
|
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
56
87
|
Tags('vdis'),
|
|
57
88
|
provide(VdiSnapshotController),
|
|
58
|
-
__param(0, inject(RestApi))
|
|
89
|
+
__param(0, inject(RestApi)),
|
|
90
|
+
__param(1, inject(AlarmService))
|
|
59
91
|
], VdiSnapshotController);
|
|
60
92
|
export { VdiSnapshotController };
|
|
@@ -10,13 +10,18 @@ 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 { provide } from 'inversify-binding-decorators';
|
|
13
|
+
import { AlarmService } from '../alarms/alarm.service.mjs';
|
|
14
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
15
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
13
16
|
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
14
17
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
15
18
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
16
19
|
import { partialVdis, vdi, vdiIds } from '../open-api/oa-examples/vdi.oa-example.mjs';
|
|
17
20
|
let VdiController = class VdiController extends XapiXoController {
|
|
18
|
-
|
|
21
|
+
#alarmService;
|
|
22
|
+
constructor(restApi, alarmService) {
|
|
19
23
|
super('VDI', restApi);
|
|
24
|
+
this.#alarmService = alarmService;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* @example fields "*"
|
|
@@ -32,6 +37,20 @@ let VdiController = class VdiController extends XapiXoController {
|
|
|
32
37
|
getVdi(id) {
|
|
33
38
|
return this.getObject(id);
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @example id "c77f9955-c1d2-4b39-aa1c-73cdb2dacb7e"
|
|
42
|
+
* @example fields "id,time"
|
|
43
|
+
* @example filter "time:>1747053793"
|
|
44
|
+
* @example limit 42
|
|
45
|
+
*/
|
|
46
|
+
getVdiAlarms(req, id, fields, ndjson, filter, limit) {
|
|
47
|
+
const vdi = this.getObject(id);
|
|
48
|
+
const alarms = this.#alarmService.getAlarms({
|
|
49
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vdi.uuid}`,
|
|
50
|
+
limit,
|
|
51
|
+
});
|
|
52
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
53
|
+
}
|
|
35
54
|
};
|
|
36
55
|
__decorate([
|
|
37
56
|
Example(vdiIds),
|
|
@@ -49,12 +68,25 @@ __decorate([
|
|
|
49
68
|
Response(notFoundResp.status, notFoundResp.description),
|
|
50
69
|
__param(0, Path())
|
|
51
70
|
], VdiController.prototype, "getVdi", null);
|
|
71
|
+
__decorate([
|
|
72
|
+
Example(genericAlarmsExample),
|
|
73
|
+
Get('{id}/alarms'),
|
|
74
|
+
Tags('alarms'),
|
|
75
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
76
|
+
__param(0, Request()),
|
|
77
|
+
__param(1, Path()),
|
|
78
|
+
__param(2, Query()),
|
|
79
|
+
__param(3, Query()),
|
|
80
|
+
__param(4, Query()),
|
|
81
|
+
__param(5, Query())
|
|
82
|
+
], VdiController.prototype, "getVdiAlarms", null);
|
|
52
83
|
VdiController = __decorate([
|
|
53
84
|
Route('vdis'),
|
|
54
85
|
Security('*'),
|
|
55
86
|
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
56
87
|
Tags('vdis'),
|
|
57
88
|
provide(VdiController),
|
|
58
|
-
__param(0, inject(RestApi))
|
|
89
|
+
__param(0, inject(RestApi)),
|
|
90
|
+
__param(1, inject(AlarmService))
|
|
59
91
|
], VdiController);
|
|
60
92
|
export { VdiController };
|
|
@@ -9,14 +9,19 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
|
|
11
11
|
import { inject } from 'inversify';
|
|
12
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
12
13
|
import { provide } from 'inversify-binding-decorators';
|
|
13
14
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
14
15
|
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
15
16
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
16
17
|
import { partialVifs, vif, vifIds } from '../open-api/oa-examples/vif.oa-example.mjs';
|
|
18
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
19
|
+
import { AlarmService } from '../alarms/alarm.service.mjs';
|
|
17
20
|
let VifController = class VifController extends XapiXoController {
|
|
18
|
-
|
|
21
|
+
#alarmService;
|
|
22
|
+
constructor(restApi, alarmService) {
|
|
19
23
|
super('VIF', restApi);
|
|
24
|
+
this.#alarmService = alarmService;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* @example fields "attached,id,device"
|
|
@@ -32,6 +37,20 @@ let VifController = class VifController extends XapiXoController {
|
|
|
32
37
|
getVif(id) {
|
|
33
38
|
return this.getObject(id);
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @example id "f028c5d4-578a-332c-394e-087aaca32dd3"
|
|
42
|
+
* @example fields "id,time"
|
|
43
|
+
* @example filter "time:>1747053793"
|
|
44
|
+
* @example limit 42
|
|
45
|
+
*/
|
|
46
|
+
getVifAlarms(req, id, fields, ndjson, filter, limit) {
|
|
47
|
+
const vif = this.getObject(id);
|
|
48
|
+
const alarms = this.#alarmService.getAlarms({
|
|
49
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vif.uuid}`,
|
|
50
|
+
limit,
|
|
51
|
+
});
|
|
52
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
53
|
+
}
|
|
35
54
|
};
|
|
36
55
|
__decorate([
|
|
37
56
|
Example(vifIds),
|
|
@@ -49,12 +68,25 @@ __decorate([
|
|
|
49
68
|
Response(notFoundResp.status, notFoundResp.description),
|
|
50
69
|
__param(0, Path())
|
|
51
70
|
], VifController.prototype, "getVif", null);
|
|
71
|
+
__decorate([
|
|
72
|
+
Example(genericAlarmsExample),
|
|
73
|
+
Get('{id}/alarms'),
|
|
74
|
+
Tags('alarms'),
|
|
75
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
76
|
+
__param(0, Request()),
|
|
77
|
+
__param(1, Path()),
|
|
78
|
+
__param(2, Query()),
|
|
79
|
+
__param(3, Query()),
|
|
80
|
+
__param(4, Query()),
|
|
81
|
+
__param(5, Query())
|
|
82
|
+
], VifController.prototype, "getVifAlarms", null);
|
|
52
83
|
VifController = __decorate([
|
|
53
84
|
Route('vifs'),
|
|
54
85
|
Security('*'),
|
|
55
86
|
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
56
87
|
Tags('vifs'),
|
|
57
88
|
provide(VifController),
|
|
58
|
-
__param(0, inject(RestApi))
|
|
89
|
+
__param(0, inject(RestApi)),
|
|
90
|
+
__param(1, inject(AlarmService))
|
|
59
91
|
], VifController);
|
|
60
92
|
export { VifController };
|
|
@@ -11,12 +11,17 @@ import { inject } from 'inversify';
|
|
|
11
11
|
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
|
+
import { AlarmService } from '../alarms/alarm.service.mjs';
|
|
15
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
16
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
14
17
|
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
15
18
|
import { provide } from 'inversify-binding-decorators';
|
|
16
19
|
import { partialVmControllers, vmController, vmControllerIds, } from '../open-api/oa-examples/vm-controller.oa-example.mjs';
|
|
17
20
|
let VmControllerController = class VmControllerController extends XapiXoController {
|
|
18
|
-
|
|
21
|
+
#alarmService;
|
|
22
|
+
constructor(restApi, alarmService) {
|
|
19
23
|
super('VM-controller', restApi);
|
|
24
|
+
this.#alarmService = alarmService;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
*
|
|
@@ -33,6 +38,20 @@ let VmControllerController = class VmControllerController extends XapiXoControll
|
|
|
33
38
|
getVmController(id) {
|
|
34
39
|
return this.getObject(id);
|
|
35
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* @example id "9b4775bd-9493-490a-9afa-f786a44caa4f"
|
|
43
|
+
* @example fields "id,time"
|
|
44
|
+
* @example filter "time:>1747053793"
|
|
45
|
+
* @example limit 42
|
|
46
|
+
*/
|
|
47
|
+
getVmControllerAlarms(req, id, fields, ndjson, filter, limit) {
|
|
48
|
+
const vmController = this.getObject(id);
|
|
49
|
+
const alarms = this.#alarmService.getAlarms({
|
|
50
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vmController.uuid}`,
|
|
51
|
+
limit,
|
|
52
|
+
});
|
|
53
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
54
|
+
}
|
|
36
55
|
};
|
|
37
56
|
__decorate([
|
|
38
57
|
Example(vmControllerIds),
|
|
@@ -50,12 +69,25 @@ __decorate([
|
|
|
50
69
|
Response(notFoundResp.status, notFoundResp.description),
|
|
51
70
|
__param(0, Path())
|
|
52
71
|
], VmControllerController.prototype, "getVmController", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
Example(genericAlarmsExample),
|
|
74
|
+
Get('{id}/alarms'),
|
|
75
|
+
Tags('alarms'),
|
|
76
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
77
|
+
__param(0, Request()),
|
|
78
|
+
__param(1, Path()),
|
|
79
|
+
__param(2, Query()),
|
|
80
|
+
__param(3, Query()),
|
|
81
|
+
__param(4, Query()),
|
|
82
|
+
__param(5, Query())
|
|
83
|
+
], VmControllerController.prototype, "getVmControllerAlarms", null);
|
|
53
84
|
VmControllerController = __decorate([
|
|
54
85
|
Route('vm-controllers'),
|
|
55
86
|
Security('*'),
|
|
56
87
|
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
57
88
|
Tags('vms'),
|
|
58
89
|
provide(VmControllerController),
|
|
59
|
-
__param(0, inject(RestApi))
|
|
90
|
+
__param(0, inject(RestApi)),
|
|
91
|
+
__param(1, inject(AlarmService))
|
|
60
92
|
], VmControllerController);
|
|
61
93
|
export { VmControllerController };
|
|
@@ -9,14 +9,19 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
9
9
|
};
|
|
10
10
|
import { Example, Get, Path, Query, Request, Response, Route, Security, Tags } from 'tsoa';
|
|
11
11
|
import { inject } from 'inversify';
|
|
12
|
+
import { AlarmService } from '../alarms/alarm.service.mjs';
|
|
13
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
14
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
12
15
|
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
13
16
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
14
17
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
15
18
|
import { provide } from 'inversify-binding-decorators';
|
|
16
19
|
import { partialVmSnapshots, vmSnapshot, vmSnapshotIds } from '../open-api/oa-examples/vm-snapshot.oa-example.mjs';
|
|
17
20
|
let VmSnapshotController = class VmSnapshotController extends XapiXoController {
|
|
18
|
-
|
|
21
|
+
#alarmService;
|
|
22
|
+
constructor(restApi, alarmService) {
|
|
19
23
|
super('VM-snapshot', restApi);
|
|
24
|
+
this.#alarmService = alarmService;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
*
|
|
@@ -33,6 +38,20 @@ let VmSnapshotController = class VmSnapshotController extends XapiXoController {
|
|
|
33
38
|
getVmSnapshot(id) {
|
|
34
39
|
return this.getObject(id);
|
|
35
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* @example id "d68fca2c-41e6-be87-d790-105c1642a090"
|
|
43
|
+
* @example fields "id,time"
|
|
44
|
+
* @example filter "time:>1747053793"
|
|
45
|
+
* @example limit 42
|
|
46
|
+
*/
|
|
47
|
+
getVmSnapshotAlarms(req, id, fields, ndjson, filter, limit) {
|
|
48
|
+
const vmSnapshot = this.getObject(id);
|
|
49
|
+
const alarms = this.#alarmService.getAlarms({
|
|
50
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vmSnapshot.uuid}`,
|
|
51
|
+
limit,
|
|
52
|
+
});
|
|
53
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
54
|
+
}
|
|
36
55
|
};
|
|
37
56
|
__decorate([
|
|
38
57
|
Example(vmSnapshotIds),
|
|
@@ -50,12 +69,25 @@ __decorate([
|
|
|
50
69
|
Response(notFoundResp.status, notFoundResp.description),
|
|
51
70
|
__param(0, Path())
|
|
52
71
|
], VmSnapshotController.prototype, "getVmSnapshot", null);
|
|
72
|
+
__decorate([
|
|
73
|
+
Example(genericAlarmsExample),
|
|
74
|
+
Get('{id}/alarms'),
|
|
75
|
+
Tags('alarms'),
|
|
76
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
77
|
+
__param(0, Request()),
|
|
78
|
+
__param(1, Path()),
|
|
79
|
+
__param(2, Query()),
|
|
80
|
+
__param(3, Query()),
|
|
81
|
+
__param(4, Query()),
|
|
82
|
+
__param(5, Query())
|
|
83
|
+
], VmSnapshotController.prototype, "getVmSnapshotAlarms", null);
|
|
53
84
|
VmSnapshotController = __decorate([
|
|
54
85
|
Route('vm-snapshots'),
|
|
55
86
|
Security('*'),
|
|
56
87
|
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
57
88
|
Tags('vms'),
|
|
58
89
|
provide(VmSnapshotController),
|
|
59
|
-
__param(0, inject(RestApi))
|
|
90
|
+
__param(0, inject(RestApi)),
|
|
91
|
+
__param(1, inject(AlarmService))
|
|
60
92
|
], VmSnapshotController);
|
|
61
93
|
export { VmSnapshotController };
|
|
@@ -10,13 +10,18 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
10
10
|
import { Example, Get, Security, Query, Request, Response, Route, Tags, Path } from 'tsoa';
|
|
11
11
|
import { inject } from 'inversify';
|
|
12
12
|
import { provide } from 'inversify-binding-decorators';
|
|
13
|
+
import { AlarmService } from '../alarms/alarm.service.mjs';
|
|
14
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
15
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
13
16
|
import { notFoundResp, unauthorizedResp } from '../open-api/common/response.common.mjs';
|
|
14
17
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
15
18
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
16
19
|
import { partialVmTemplates, vmTemplate, vmTemplateIds } from '../open-api/oa-examples/vm-template.oa-example.mjs';
|
|
17
20
|
let VmTemplateController = class VmTemplateController extends XapiXoController {
|
|
18
|
-
|
|
21
|
+
#alarmService;
|
|
22
|
+
constructor(restApi, alarmService) {
|
|
19
23
|
super('VM-template', restApi);
|
|
24
|
+
this.#alarmService = alarmService;
|
|
20
25
|
}
|
|
21
26
|
/**
|
|
22
27
|
* @example fields "id,isDefaultTemplate,name_label"
|
|
@@ -32,6 +37,20 @@ let VmTemplateController = class VmTemplateController extends XapiXoController {
|
|
|
32
37
|
getVmTemplate(id) {
|
|
33
38
|
return this.getObject(id);
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @example id "b7569d99-30f8-178a-7d94-801de3e29b5b-f873abe0-b138-4995-8f6f-498b423d234d"
|
|
42
|
+
* @example fields "id,time"
|
|
43
|
+
* @example filter "time:>1747053793"
|
|
44
|
+
* @example limit 42
|
|
45
|
+
*/
|
|
46
|
+
getVmTemplateAlarms(req, id, fields, ndjson, filter, limit) {
|
|
47
|
+
const vmTemplate = this.getObject(id);
|
|
48
|
+
const alarms = this.#alarmService.getAlarms({
|
|
49
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vmTemplate.uuid}`,
|
|
50
|
+
limit,
|
|
51
|
+
});
|
|
52
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
53
|
+
}
|
|
35
54
|
};
|
|
36
55
|
__decorate([
|
|
37
56
|
Example(vmTemplateIds),
|
|
@@ -49,12 +68,25 @@ __decorate([
|
|
|
49
68
|
Response(notFoundResp.status, notFoundResp.description),
|
|
50
69
|
__param(0, Path())
|
|
51
70
|
], VmTemplateController.prototype, "getVmTemplate", null);
|
|
71
|
+
__decorate([
|
|
72
|
+
Example(genericAlarmsExample),
|
|
73
|
+
Get('{id}/alarms'),
|
|
74
|
+
Tags('alarms'),
|
|
75
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
76
|
+
__param(0, Request()),
|
|
77
|
+
__param(1, Path()),
|
|
78
|
+
__param(2, Query()),
|
|
79
|
+
__param(3, Query()),
|
|
80
|
+
__param(4, Query()),
|
|
81
|
+
__param(5, Query())
|
|
82
|
+
], VmTemplateController.prototype, "getVmTemplateAlarms", null);
|
|
52
83
|
VmTemplateController = __decorate([
|
|
53
84
|
Route('vm-templates'),
|
|
54
85
|
Security('*'),
|
|
55
86
|
Response(unauthorizedResp.status, unauthorizedResp.description),
|
|
56
87
|
Tags('vms'),
|
|
57
88
|
provide(VmTemplateController),
|
|
58
|
-
__param(0, inject(RestApi))
|
|
89
|
+
__param(0, inject(RestApi)),
|
|
90
|
+
__param(1, inject(AlarmService))
|
|
59
91
|
], VmTemplateController);
|
|
60
92
|
export { VmTemplateController };
|
|
@@ -11,16 +11,21 @@ import { Example, Get, Path, Post, Query, Request, Response, Route, Security, Ta
|
|
|
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 { AlarmService } from '../alarms/alarm.service.mjs';
|
|
14
15
|
import { asynchronousActionResp, createdResp, internalServerErrorResp, noContentResp, notFoundResp, unauthorizedResp, } from '../open-api/common/response.common.mjs';
|
|
15
16
|
import { BASE_URL } from '../index.mjs';
|
|
17
|
+
import { escapeUnsafeComplexMatcher } from '../helpers/utils.helper.mjs';
|
|
18
|
+
import { genericAlarmsExample } from '../open-api/oa-examples/alarm.oa-example.mjs';
|
|
16
19
|
import { partialVms, vm, vmIds, vmStatsExample } from '../open-api/oa-examples/vm.oa-example.mjs';
|
|
17
20
|
import { RestApi } from '../rest-api/rest-api.mjs';
|
|
18
21
|
import { taskLocation } from '../open-api/oa-examples/task.oa-example.mjs';
|
|
19
22
|
import { XapiXoController } from '../abstract-classes/xapi-xo-controller.mjs';
|
|
20
23
|
const IGNORED_VDIS_TAG = '[NOSNAP]';
|
|
21
24
|
let VmController = class VmController extends XapiXoController {
|
|
22
|
-
|
|
25
|
+
#alarmService;
|
|
26
|
+
constructor(restApi, alarmService) {
|
|
23
27
|
super('VM', restApi);
|
|
28
|
+
this.#alarmService = alarmService;
|
|
24
29
|
}
|
|
25
30
|
/**
|
|
26
31
|
*
|
|
@@ -294,6 +299,20 @@ let VmController = class VmController extends XapiXoController {
|
|
|
294
299
|
},
|
|
295
300
|
});
|
|
296
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* @example id "f07ab729-c0e8-721c-45ec-f11276377030"
|
|
304
|
+
* @example fields "id,time"
|
|
305
|
+
* @example filter "time:>1747053793"
|
|
306
|
+
* @example limit 42
|
|
307
|
+
*/
|
|
308
|
+
getVmAlarms(req, id, fields, ndjson, filter, limit) {
|
|
309
|
+
const vm = this.getObject(id);
|
|
310
|
+
const alarms = this.#alarmService.getAlarms({
|
|
311
|
+
filter: `${escapeUnsafeComplexMatcher(filter) ?? ''} object:uuid:${vm.uuid}`,
|
|
312
|
+
limit,
|
|
313
|
+
});
|
|
314
|
+
return this.sendObjects(Object.values(alarms), req, 'alarms');
|
|
315
|
+
}
|
|
297
316
|
};
|
|
298
317
|
__decorate([
|
|
299
318
|
Example(vmIds),
|
|
@@ -433,6 +452,18 @@ __decorate([
|
|
|
433
452
|
__param(1, Body()),
|
|
434
453
|
__param(2, Query())
|
|
435
454
|
], VmController.prototype, "snapshotVm", null);
|
|
455
|
+
__decorate([
|
|
456
|
+
Example(genericAlarmsExample),
|
|
457
|
+
Get('{id}/alarms'),
|
|
458
|
+
Tags('alarms'),
|
|
459
|
+
Response(notFoundResp.status, notFoundResp.description),
|
|
460
|
+
__param(0, Request()),
|
|
461
|
+
__param(1, Path()),
|
|
462
|
+
__param(2, Query()),
|
|
463
|
+
__param(3, Query()),
|
|
464
|
+
__param(4, Query()),
|
|
465
|
+
__param(5, Query())
|
|
466
|
+
], VmController.prototype, "getVmAlarms", null);
|
|
436
467
|
VmController = __decorate([
|
|
437
468
|
Route('vms'),
|
|
438
469
|
Security('*'),
|
|
@@ -442,6 +473,7 @@ VmController = __decorate([
|
|
|
442
473
|
// It automatically bind the class to the IOC container that handles dependency injection
|
|
443
474
|
,
|
|
444
475
|
provide(VmController),
|
|
445
|
-
__param(0, inject(RestApi))
|
|
476
|
+
__param(0, inject(RestApi)),
|
|
477
|
+
__param(1, inject(AlarmService))
|
|
446
478
|
], VmController);
|
|
447
479
|
export { VmController };
|
package/dist/vms/vm.service.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createLogger } from '@xen-orchestra/log';
|
|
2
2
|
import { defer } from 'golike-defer';
|
|
3
3
|
import { Task } from '@vates/task';
|
|
4
|
+
import { VM_POWER_STATE, } from '@vates/types';
|
|
4
5
|
const log = createLogger('xo:rest-api:vm-service');
|
|
5
6
|
export class VmService {
|
|
6
7
|
#restApi;
|
|
@@ -44,4 +45,43 @@ export class VmService {
|
|
|
44
45
|
return xoVm.id;
|
|
45
46
|
}
|
|
46
47
|
create = defer(this.#create);
|
|
48
|
+
getVmsStatus(opts) {
|
|
49
|
+
const vms = this.#restApi.getObjectsByType('VM', opts);
|
|
50
|
+
let nRunning = 0;
|
|
51
|
+
let nPaused = 0;
|
|
52
|
+
let nSuspended = 0;
|
|
53
|
+
let nHalted = 0;
|
|
54
|
+
let nUnknown = 0;
|
|
55
|
+
let total = 0;
|
|
56
|
+
for (const id in vms) {
|
|
57
|
+
total++;
|
|
58
|
+
const vm = vms[id];
|
|
59
|
+
switch (vm.power_state) {
|
|
60
|
+
case VM_POWER_STATE.RUNNING:
|
|
61
|
+
nRunning++;
|
|
62
|
+
break;
|
|
63
|
+
case VM_POWER_STATE.HALTED:
|
|
64
|
+
nHalted++;
|
|
65
|
+
break;
|
|
66
|
+
case VM_POWER_STATE.PAUSED:
|
|
67
|
+
nPaused++;
|
|
68
|
+
break;
|
|
69
|
+
case VM_POWER_STATE.SUSPENDED:
|
|
70
|
+
nSuspended++;
|
|
71
|
+
break;
|
|
72
|
+
default:
|
|
73
|
+
log.warn('Invalid VM power_state', vm.id, vm.power_state);
|
|
74
|
+
nUnknown++;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
running: nRunning,
|
|
80
|
+
halted: nHalted,
|
|
81
|
+
paused: nPaused,
|
|
82
|
+
suspended: nSuspended,
|
|
83
|
+
unknown: nUnknown,
|
|
84
|
+
total,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
47
87
|
}
|