Xapi#deleteVm(): Correctly remove VDIs with more than one VBD on the same VM.
This commit is contained in:
parent
4edfefa9a2
commit
b9082ed838
@ -77,6 +77,7 @@
|
|||||||
"lodash.bind": "^3.0.0",
|
"lodash.bind": "^3.0.0",
|
||||||
"lodash.difference": "^3.2.0",
|
"lodash.difference": "^3.2.0",
|
||||||
"lodash.endswith": "^3.0.2",
|
"lodash.endswith": "^3.0.2",
|
||||||
|
"lodash.every": "^4.0.0",
|
||||||
"lodash.filter": "^3.1.0",
|
"lodash.filter": "^3.1.0",
|
||||||
"lodash.find": "^3.0.0",
|
"lodash.find": "^3.0.0",
|
||||||
"lodash.findindex": "^3.0.0",
|
"lodash.findindex": "^3.0.0",
|
||||||
|
18
src/xapi.js
18
src/xapi.js
@ -1,4 +1,5 @@
|
|||||||
import createDebug from 'debug'
|
import createDebug from 'debug'
|
||||||
|
import every from 'lodash.every'
|
||||||
import fatfs from 'fatfs'
|
import fatfs from 'fatfs'
|
||||||
import fatfsBuffer, { init as fatfsBufferInit } from './fatfs-buffer'
|
import fatfsBuffer, { init as fatfsBufferInit } from './fatfs-buffer'
|
||||||
import find from 'lodash.find'
|
import find from 'lodash.find'
|
||||||
@ -1133,17 +1134,26 @@ export default class Xapi extends XapiBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (deleteDisks) {
|
if (deleteDisks) {
|
||||||
await Promise.all(mapToArray(vm.$VBDs, vbd => {
|
// Compute the VDIs list without duplicates.
|
||||||
|
const vdis = {}
|
||||||
|
forEach(vm.$VBDs, vbd => {
|
||||||
let vdi
|
let vdi
|
||||||
if (
|
if (
|
||||||
// Do not remove CDs and Floppies.
|
// Do not remove CDs and Floppies.
|
||||||
vbd.type === 'Disk' &&
|
vbd.type === 'Disk' &&
|
||||||
|
|
||||||
// Ignore VBD without VDI.
|
// Ignore VBD without VDI.
|
||||||
(vdi = vbd.$VDI) &&
|
(vdi = vbd.$VDI)
|
||||||
|
) {
|
||||||
|
vdis[vdi.$id] = vdi
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Do not remove VDI attached to other VMs.
|
await Promise.all(mapToArray(vdis, vdi => {
|
||||||
vdi.VBDs.length < 2
|
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)
|
return this._deleteVdi(vdi).catch(noop)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user