Xapi#deleteVm(): Correctly remove VDIs with more than one VBD on the same VM.

This commit is contained in:
Julien Fontanet 2016-01-17 12:06:16 +01:00
parent 4edfefa9a2
commit b9082ed838
2 changed files with 15 additions and 4 deletions

View File

@ -77,6 +77,7 @@
"lodash.bind": "^3.0.0",
"lodash.difference": "^3.2.0",
"lodash.endswith": "^3.0.2",
"lodash.every": "^4.0.0",
"lodash.filter": "^3.1.0",
"lodash.find": "^3.0.0",
"lodash.findindex": "^3.0.0",

View File

@ -1,4 +1,5 @@
import createDebug from 'debug'
import every from 'lodash.every'
import fatfs from 'fatfs'
import fatfsBuffer, { init as fatfsBufferInit } from './fatfs-buffer'
import find from 'lodash.find'
@ -1133,17 +1134,26 @@ export default class Xapi extends XapiBase {
}
if (deleteDisks) {
await Promise.all(mapToArray(vm.$VBDs, vbd => {
// Compute the VDIs list without duplicates.
const vdis = {}
forEach(vm.$VBDs, vbd => {
let vdi
if (
// Do not remove CDs and Floppies.
vbd.type === 'Disk' &&
// Ignore VBD without VDI.
(vdi = vbd.$VDI) &&
(vdi = vbd.$VDI)
) {
vdis[vdi.$id] = vdi
}
})
// Do not remove VDI attached to other VMs.
vdi.VBDs.length < 2
await Promise.all(mapToArray(vdis, vdi => {
if (
// Do not remove VBDs attached to other VMs.
vdi.VBDs.length < 2 ||
every(vdi.$VBDs, vbd => vbd.VM === vm.$ref)
) {
return this._deleteVdi(vdi).catch(noop)
}