Merge pull request #172 from vatesfr/olivierlambert-vdimove

Allow offline VDI moving. Fix vatesfr/xo-web#591
This commit is contained in:
Julien Fontanet 2015-12-16 10:46:33 +01:00
commit cfcb2d54d8
2 changed files with 29 additions and 3 deletions

View File

@ -77,8 +77,7 @@ exports.set = set
migrate = $coroutine ({vdi, sr}) ->
xapi = @getXAPI vdi
# TODO: check if VDI is attached before
yield xapi.call 'VDI.pool_migrate', vdi._xapiRef, sr._xapiRef, {}
yield xapi.moveVdi(vdi._xapiRef, sr._xapiRef)
return true

View File

@ -1349,7 +1349,7 @@ export default class Xapi extends XapiBase {
// By default a VBD is unpluggable.
const vbdRef = await this.call('VBD.create', {
bootable,
bootable: Boolean(bootable),
empty: false,
mode: readOnly ? 'RO' : 'RW',
other_config: {},
@ -1385,6 +1385,33 @@ export default class Xapi extends XapiBase {
})
}
async moveVdi (vdiId, srId) {
const vdi = this.getObject(vdiId)
const sr = this.getObject(srId)
try {
await this.call('VDI.pool_migrate', vdi.$ref, sr.$ref, {})
} catch (error) {
if (error.code !== 'VDI_NEEDS_VM_FOR_MIGRATE') {
throw error
}
const newVdiref = await this.call('VDI.copy', vdi.$ref, sr.$ref)
const newVdi = await this._getOrWaitObject(newVdiref)
await Promise.all(mapToArray(vdi.$VBDs, async vbd => {
// Remove the old VBD
await this.call('VBD.destroy', vbd.$ref)
// Attach the new VDI to the VM with old VBD settings
await this._createVbd(vbd.$VM, newVdi, {
bootable: vbd.bootable,
position: vbd.userdevice,
type: vbd.type,
readOnly: vbd.mode === 'RO'
})
// Remove the old VDI
await this._deleteVdi(vdi)
}))
}
}
// TODO: check whether the VDI is attached.
async _deleteVdi (vdi) {
await this.call('VDI.destroy', vdi.$ref)