feat(xapi/VTPM): ability to create, destroy VTPM (#7074)
This commit is contained in:
parent
bea771ca90
commit
2e634a9d1c
@ -5,3 +5,4 @@ export { default as VBD } from './vbd.mjs'
|
||||
export { default as VDI } from './vdi.mjs'
|
||||
export { default as VIF } from './vif.mjs'
|
||||
export { default as VM } from './vm.mjs'
|
||||
export { default as VTPM } from './vtpm.mjs'
|
||||
|
37
@xen-orchestra/xapi/vtpm.mjs
Normal file
37
@xen-orchestra/xapi/vtpm.mjs
Normal file
@ -0,0 +1,37 @@
|
||||
import upperFirst from 'lodash/upperFirst.js'
|
||||
import { incorrectState } from 'xo-common/api-errors.js'
|
||||
|
||||
export default class Vtpm {
|
||||
async create({ is_unique = false, VM }) {
|
||||
const pool = this.pool
|
||||
|
||||
// If VTPM.create is called on a pool that doesn't support VTPM, the errors aren't explicit.
|
||||
// See https://github.com/xapi-project/xen-api/issues/5186
|
||||
if (pool.restrictions.restrict_vtpm !== 'false') {
|
||||
throw incorrectState({
|
||||
actual: pool.restrictions.restrict_vtpm,
|
||||
expected: 'false',
|
||||
object: pool.uuid,
|
||||
property: 'restrictions.restrict_vtpm',
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.call('VTPM.create', VM, is_unique)
|
||||
} catch (error) {
|
||||
const { code, params } = error
|
||||
if (code === 'VM_BAD_POWER_STATE') {
|
||||
const [, expected, actual] = params
|
||||
// In `VM_BAD_POWER_STATE` errors, the power state is lowercased
|
||||
throw incorrectState({
|
||||
actual: upperFirst(actual),
|
||||
expected: upperFirst(expected),
|
||||
object: await this.getField('VM', VM, 'uuid'),
|
||||
property: 'power_state',
|
||||
})
|
||||
}
|
||||
|
||||
throw error
|
||||
}
|
||||
}
|
||||
}
|
29
packages/xo-server/src/api/vtpm.mjs
Normal file
29
packages/xo-server/src/api/vtpm.mjs
Normal file
@ -0,0 +1,29 @@
|
||||
export async function create({ vm }) {
|
||||
const xapi = this.getXapi(vm)
|
||||
const vtpmRef = await xapi.VTPM_create({ VM: vm._xapiRef })
|
||||
return xapi.getField('VTPM', vtpmRef, 'uuid')
|
||||
}
|
||||
|
||||
create.description = 'create a VTPM'
|
||||
|
||||
create.params = {
|
||||
id: { type: 'string' },
|
||||
}
|
||||
|
||||
create.resolve = {
|
||||
vm: ['id', 'VM', 'administrate'],
|
||||
}
|
||||
|
||||
export async function destroy({ vtpm }) {
|
||||
await this.getXapi(vtpm).call('VTPM.destroy', vtpm._xapiRef)
|
||||
}
|
||||
|
||||
destroy.description = 'destroy a VTPM'
|
||||
|
||||
destroy.params = {
|
||||
id: { type: 'string' },
|
||||
}
|
||||
|
||||
destroy.resolve = {
|
||||
vtpm: ['id', 'VTPM', 'administrate'],
|
||||
}
|
@ -118,6 +118,7 @@ const TRANSFORMS = {
|
||||
},
|
||||
suspendSr: link(obj, 'suspend_image_SR'),
|
||||
zstdSupported: obj.restrictions.restrict_zstd_export === 'false',
|
||||
vtpmSupported: obj.restrictions.restrict_vtpm === 'false',
|
||||
|
||||
// TODO
|
||||
// - ? networks = networksByPool.items[pool.id] (network.$pool.id)
|
||||
@ -413,6 +414,7 @@ const TRANSFORMS = {
|
||||
suspendSr: link(obj, 'suspend_SR'),
|
||||
tags: obj.tags,
|
||||
VIFs: link(obj, 'VIFs'),
|
||||
VTPMs: link(obj, 'VTPMs'),
|
||||
virtualizationMode: domainType,
|
||||
|
||||
// deprecated, use pvDriversVersion instead
|
||||
@ -841,6 +843,14 @@ const TRANSFORMS = {
|
||||
vgpus: link(obj, 'VGPUs'),
|
||||
}
|
||||
},
|
||||
|
||||
vtpm(obj) {
|
||||
return {
|
||||
type: 'VTPM',
|
||||
|
||||
vm: link(obj, 'VM'),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user