fix(Xapi#CreateVm): wait for the cloned vifs to be correctly deleted (#574)

This commit is contained in:
badrAZ 2017-09-04 15:18:42 +02:00 committed by Julien Fontanet
parent f5febef10f
commit cf5f9d4080

View File

@ -111,7 +111,6 @@ export default {
} }
} }
let nVbds = vm.VBDs.length
let hasBootableDisk = !!find(vm.$VBDs, 'bootable') let hasBootableDisk = !!find(vm.$VBDs, 'bootable')
// Inserts the CD if necessary. // Inserts the CD if necessary.
@ -122,8 +121,6 @@ export default {
bootable: true bootable: true
}) })
hasBootableDisk = true hasBootableDisk = true
++nVbds
} }
// Modify existing (previous template) disks if necessary // Modify existing (previous template) disks if necessary
@ -153,56 +150,49 @@ export default {
// TODO: set vm.suspend_SR // TODO: set vm.suspend_SR
if (!isEmpty(vdis)) { if (!isEmpty(vdis)) {
const devices = await this.call('VM.get_allowed_VBD_devices', vm.$ref) const devices = await this.call('VM.get_allowed_VBD_devices', vm.$ref)
await Promise.all(mapToArray(vdis, (vdiDescription, i) => { await Promise.all(mapToArray(vdis, (vdiDescription, i) => this._createVdi(
++nVbds vdiDescription.size, // FIXME: Should not be done in Xapi.
{
return this._createVdi( name_label: vdiDescription.name_label,
vdiDescription.size, // FIXME: Should not be done in Xapi. name_description: vdiDescription.name_description,
{ sr: vdiDescription.sr || vdiDescription.SR
name_label: vdiDescription.name_label, }
name_description: vdiDescription.name_description, )
sr: vdiDescription.sr || vdiDescription.SR .then(ref => this._getOrWaitObject(ref))
} .then(vdi => this._createVbd(vm, vdi, {
) // Either the CD or the 1st disk is bootable (only useful for PV VMs)
.then(ref => this._getOrWaitObject(ref)) bootable: !(hasBootableDisk || i),
.then(vdi => this._createVbd(vm, vdi, { userdevice: devices[i]
// Either the CD or the 1st disk is bootable (only useful for PV VMs) }))
bootable: !(hasBootableDisk || i), ))
userdevice: devices[i]
}))
}))
} }
// Destroys the VIFs cloned from the template. // Destroys the VIFs cloned from the template.
await Promise.all(mapToArray(vm.$VIFs, vif => this._deleteVif(vif))) await Promise.all(mapToArray(vm.$VIFs, vif => this._deleteVif(vif)))
// Creates the VIFs specified by the user. // Creates the VIFs specified by the user.
let nVifs = 0
if (vifs) { if (vifs) {
const devices = await this.call('VM.get_allowed_VIF_devices', vm.$ref) const devices = await this.call('VM.get_allowed_VIF_devices', vm.$ref)
await Promise.all(mapToArray(vifs, (vif, index) => { await Promise.all(mapToArray(vifs, (vif, index) => this._createVif(
++nVifs vm,
this.getObject(vif.network),
return this._createVif( {
vm, ipv4_allowed: vif.ipv4_allowed,
this.getObject(vif.network), ipv6_allowed: vif.ipv6_allowed,
{ device: devices[index],
ipv4_allowed: vif.ipv4_allowed, locking_mode: isEmpty(vif.ipv4_allowed) && isEmpty(vif.ipv6_allowed) ? 'network_default' : 'locked',
ipv6_allowed: vif.ipv6_allowed, mac: vif.mac,
device: devices[index], mtu: vif.mtu
locking_mode: isEmpty(vif.ipv4_allowed) && isEmpty(vif.ipv6_allowed) ? 'network_default' : 'locked', }
mac: vif.mac, )))
mtu: vif.mtu
}
)
}))
} }
// TODO: Assign VGPUs. // TODO: Assign VGPUs.
if (cloudConfig != null) { if (cloudConfig != null) {
// Refresh the record. // Refresh the record.
vm = await this._waitObjectState(vm.$id, vm => vm.VBDs.length === nVbds) await this.barrier('VM', vm.$ref)
vm = this.getObjectByRef(vm.$ref)
// Find the SR of the first VDI. // Find the SR of the first VDI.
let srRef let srRef
@ -221,15 +211,10 @@ export default {
? 'createCoreOsCloudInitConfigDrive' ? 'createCoreOsCloudInitConfigDrive'
: 'createCloudInitConfigDrive' : 'createCloudInitConfigDrive'
await this[method](vm.$id, srRef, cloudConfig) await this[method](vm.$id, srRef, cloudConfig)
++nVbds
} }
// wait for the record with all the VBDs and VIFs // wait for the record with all the VBDs and VIFs
return this._waitObjectState(vm.$id, vm => return this.barrier('VM', vm.$ref)
vm.VBDs.length === nVbds &&
vm.VIFs.length === nVifs
)
}, },
// High level method to edit a VM. // High level method to edit a VM.