Compare commits

...

1 Commits

Author SHA1 Message Date
Julien Fontanet
42cc6d4dd6 WiP 2024-02-12 13:14:26 +01:00
3 changed files with 52 additions and 0 deletions

View File

@@ -399,6 +399,16 @@ class Vm {
return ref
}
async createFull($defer, { clone = true, boot = false, name_label, name_description, template: templateRef }) {
// Clones the template.
const vmRef = await (
clone
? this.callAsync('VM.clone', templateRef, name_label)
: this.callAsync('VM.copy', templateRef, name_label, '')
).then(extractOpaqueRef)
$defer.onFailure(() => this.VM_destroy(vmRef))
}
async destroy(
vmRef,
{ deleteDisks = true, force = false, bypassBlockedOperation = force, forceDeleteDefaultTemplate = force } = {}
@@ -699,6 +709,7 @@ export default Vm
decorateClass(Vm, {
checkpoint: defer,
create: defer,
createFull: defer,
export: defer,
snapshot: defer,
})

View File

@@ -32,6 +32,9 @@ const methods = {
name_label, // eslint-disable-line camelcase
nameLabel = name_label, // eslint-disable-line camelcase
cloudConfig,
networkConfig,
clone = true,
installRepository = undefined,
vdis = undefined,
@@ -217,6 +220,35 @@ const methods = {
await this.createVgpu(vm, gpuGroup, vgpuType)
}
// create cloud config drive
let cloudConfigVdiUuid
if (params.cloudConfig != null) {
// Find the SR of the first VDI.
let srId
forEach(vm.$VBDs, vbdId => {
const vbd = this.getObject(vbdId)
const vdiId = vbd.VDI
if (!vbd.is_cd_drive && vdiId !== undefined) {
srId = this.getObject(vdiId).$SR
return false
}
})
try {
cloudConfigVdiUuid = params.coreOs
? await xapi.createCoreOsCloudInitConfigDrive(vm.id, srId, params.cloudConfig)
: await xapi.createCloudInitConfigDrive(vm.id, srId, params.cloudConfig, params.networkConfig)
} catch (error) {
log.warn('vm.create', { vmId: vm.id, srId, error })
throw error
}
}
if (params.createVtpm) {
const vtpmRef = await xapi.VTPM_create({ VM: xapiVm.$ref })
$defer.onFailure(() => xapi.call('VTPM.destroy', vtpmRef))
}
// wait for the record with all the VBDs and VIFs
return this.barrier(vm.$ref)
},

View File

@@ -297,6 +297,15 @@ export default class RestApi {
auto_poweron: { type: 'boolean', optional: true },
boot: { type: 'boolean', default: false },
clone: { type: 'boolean', default: true },
cloud_init: {
type: 'object',
default: {},
properties: {
cloud_config: { type: 'string', optional: true },
destroy_after_boot: { type: 'boolean', default: false },
network_config: { type: 'string', optional: true },
},
},
install: {
type: 'object',
optional: true,