feat(rest-api): add createVtpm parameter to VM creation endpoint (#9412)

This commit is contained in:
Mathieu
2026-01-21 15:25:03 +01:00
committed by GitHub
parent 927561123a
commit caba00a2b9
4 changed files with 10 additions and 1 deletions

View File

@@ -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<string, unknown>; task?: boolean | XenApiTask['$ref'] }
): Promise<{ body: Readable }>
isHyperThreadingEnabled(hostId: XoHost['id']): Promise<boolean | null>
VTPM_create(params: { VM: XenApiVm['$ref']; is_unique?: boolean; contents?: string }): Promise<XenApiVtpm['$ref']>
}

View File

@@ -25,6 +25,7 @@ export type CreateVmAfterCreateParams = {
network_config?: string
boot?: boolean
destroy_cloud_config_vdi?: boolean
createVtpm?: boolean
}
export type CreateVmBody = Omit<
CreateVmParams,

View File

@@ -56,7 +56,7 @@ export class VmService {
template: XoVmTemplate['uuid']
}
): Promise<XoVm['id']> {
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<XoVm>(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, {

View File

@@ -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