diff --git a/@vates/types/src/lib/xen-orchestra-xapi.mts b/@vates/types/src/lib/xen-orchestra-xapi.mts index f14fd78a33..34c98c2cba 100644 --- a/@vates/types/src/lib/xen-orchestra-xapi.mts +++ b/@vates/types/src/lib/xen-orchestra-xapi.mts @@ -9,6 +9,7 @@ import { XenApiVdi, XenApiVm, XenApiVmWrapped, + XenApiVtpm, } from '../xen-api.mjs' import type { OPAQUE_REF_NULL, VBD_MODE, VBD_TYPE } from '../common.mjs' import type { PassThrough, Readable } from 'node:stream' @@ -222,4 +223,5 @@ export interface Xapi { params?: { host?: XenApiHost; query?: Record; task?: boolean | XenApiTask['$ref'] } ): Promise<{ body: Readable }> isHyperThreadingEnabled(hostId: XoHost['id']): Promise + VTPM_create(params: { VM: XenApiVm['$ref']; is_unique?: boolean; contents?: string }): Promise } diff --git a/@xen-orchestra/rest-api/src/pools/pool.type.mts b/@xen-orchestra/rest-api/src/pools/pool.type.mts index 527725ec08..600d5b5e7a 100644 --- a/@xen-orchestra/rest-api/src/pools/pool.type.mts +++ b/@xen-orchestra/rest-api/src/pools/pool.type.mts @@ -25,6 +25,7 @@ export type CreateVmAfterCreateParams = { network_config?: string boot?: boolean destroy_cloud_config_vdi?: boolean + createVtpm?: boolean } export type CreateVmBody = Omit< CreateVmParams, diff --git a/@xen-orchestra/rest-api/src/vms/vm.service.mts b/@xen-orchestra/rest-api/src/vms/vm.service.mts index e6a8a92a94..7123198b9e 100644 --- a/@xen-orchestra/rest-api/src/vms/vm.service.mts +++ b/@xen-orchestra/rest-api/src/vms/vm.service.mts @@ -56,7 +56,7 @@ export class VmService { template: XoVmTemplate['uuid'] } ): Promise { - const { pool, template, cloud_config, boot, destroy_cloud_config_vdi, network_config, ...rest } = params + const { pool, template, cloud_config, boot, destroy_cloud_config_vdi, network_config, createVtpm, ...rest } = params const xoApp = this.#restApi.xoApp const xapi = xoApp.getXapi(pool) const currentUser = this.#restApi.getCurrentUser() @@ -65,6 +65,11 @@ export class VmService { $defer.onFailure(() => xapi.VM_destroy(xapiVm.$ref)) const xoVm = this.#restApi.getObject(xapiVm.uuid as XoVm['id'], 'VM') + if (createVtpm) { + const vtpmRef = await xapi.VTPM_create({ VM: xapiVm.$ref }) + $defer.onFailure(() => xapi.call('VTPM.destroy', vtpmRef)) + } + let cloudConfigVdi: XenApiVdiWrapped | undefined if (cloud_config !== undefined) { const cloudConfigVdiUuid = await xapi.VM_createCloudInitConfig(xapiVm.$ref, cloud_config, { diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 8749a58be5..d0c21fae49 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -20,6 +20,7 @@ - [VM] Add "Change state" button on VM view (PR [#9317](https://github.com/vatesfr/xen-orchestra/pull/9317)) - [REST API] Add `POST /vbds` endpoint to create a VBD (attach a VDI to a VM) (PR [#9391](https://github.com/vatesfr/xen-orchestra/pull/9391)) - [TreeView] Scroll to current item in list view (PR [#9268](https://github.com/vatesfr/xen-orchestra/pull/9268)) +- [REST API] Add `createVtpm` parameter to VM creation endpoint (PR [#9412](https://github.com/vatesfr/xen-orchestra/pull/9412)) ### Bug fixes