From 80d0624409d53e83f5bd76934aa51977b3f19e2d Mon Sep 17 00:00:00 2001 From: mathieuRA Date: Mon, 23 Jun 2025 14:56:11 +0200 Subject: [PATCH] feat(@xen-orchestra/rest-api): expose vm suspend --- @vates/types/src/xen-api.mts | 1 + .../rest-api/src/vms/vm.controller.mts | 27 +++++++++++++++++++ CHANGELOG.unreleased.md | 1 + 3 files changed, 29 insertions(+) diff --git a/@vates/types/src/xen-api.mts b/@vates/types/src/xen-api.mts index 3a783da2f0..2afc64b759 100644 --- a/@vates/types/src/xen-api.mts +++ b/@vates/types/src/xen-api.mts @@ -263,6 +263,7 @@ type XenApiVmCallMethods = { (method: 'clean_reboot'): Promise (method: 'hard_reboot'): Promise (method: 'pause'): Promise + (method: 'suspend'): Promise (method: 'record_data_source', dataSource: string): Promise (method: 'forget_data_source_archives', dataSource: string): Promise } diff --git a/@xen-orchestra/rest-api/src/vms/vm.controller.mts b/@xen-orchestra/rest-api/src/vms/vm.controller.mts index 6deb9ba90e..871fcb6934 100644 --- a/@xen-orchestra/rest-api/src/vms/vm.controller.mts +++ b/@xen-orchestra/rest-api/src/vms/vm.controller.mts @@ -309,6 +309,33 @@ export class VmController extends XapiXoController { }) } + /** + * The VM must be running + * + * @example id "f07ab729-c0e8-721c-45ec-f11276377030" + */ + @Example(taskLocation) + @Post('{id}/actions/suspend') + @SuccessResponse(asynchronousActionResp.status, asynchronousActionResp.description, asynchronousActionResp.produce) + @Response(noContentResp.status, noContentResp.description) + @Response(notFoundResp.status, notFoundResp.description) + @Response(internalServerErrorResp.status, internalServerErrorResp.description) + async suspendVm(@Path() id: string, @Query() sync?: boolean): Promise { + const vmId = id as XoVm['id'] + const action = async () => { + await this.getXapiObject(vmId).$callAsync('suspend') + } + + return this.createAction(action, { + sync, + statusCode: noContentResp.status, + taskProperties: { + name: 'suspend VM', + objectId: vmId, + }, + }) + } + /** * @example id "f07ab729-c0e8-721c-45ec-f11276377030" * @example body { "name_label": "my_awesome_snapshot" } diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 890e1d60e8..0ada957e63 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -23,6 +23,7 @@ - [REST API] Expose `GET /rest/v0/sms` and `GET /rest/v0/sms/` (PR [#8696](https://github.com/vatesfr/xen-orchestra/pull/8696)) - [XO5/Tasks] hide pending/successful xo tasks (PR [#8676](https://github.com/vatesfr/xen-orchestra/pull/8676)) - [REST API] Expose `POST /rest/v0/vms//actions/pause` (PR [#8744](https://github.com/vatesfr/xen-orchestra/pull/8744)) +- [REST API] Expose `POST /rest/v0/vms//actions/suspend` (PR [#8744](https://github.com/vatesfr/xen-orchestra/pull/8744)) ### Bug fixes