feat(@xen-orchestra/rest-api): expose vm suspend

This commit is contained in:
mathieuRA
2025-06-23 14:56:11 +02:00
committed by Mathieu
parent 36889b3841
commit 80d0624409
3 changed files with 29 additions and 0 deletions

View File

@@ -263,6 +263,7 @@ type XenApiVmCallMethods = {
(method: 'clean_reboot'): Promise<void>
(method: 'hard_reboot'): Promise<void>
(method: 'pause'): Promise<void>
(method: 'suspend'): Promise<void>
(method: 'record_data_source', dataSource: string): Promise<void>
(method: 'forget_data_source_archives', dataSource: string): Promise<void>
}

View File

@@ -309,6 +309,33 @@ export class VmController extends XapiXoController<XoVm> {
})
}
/**
* 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<void | string> {
const vmId = id as XoVm['id']
const action = async () => {
await this.getXapiObject(vmId).$callAsync('suspend')
}
return this.createAction<void>(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" }

View File

@@ -23,6 +23,7 @@
- [REST API] Expose `GET /rest/v0/sms` and `GET /rest/v0/sms/<sm-id>` (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/<vm-id>/actions/pause` (PR [#8744](https://github.com/vatesfr/xen-orchestra/pull/8744))
- [REST API] Expose `POST /rest/v0/vms/<vm-id>/actions/suspend` (PR [#8744](https://github.com/vatesfr/xen-orchestra/pull/8744))
### Bug fixes