position is now optional for vm.attachDisk().

This commit is contained in:
Julien Fontanet 2015-05-29 11:55:59 +02:00
parent 3befdbc93d
commit 26e8ae4bf3
2 changed files with 39 additions and 20 deletions

View File

@ -842,32 +842,16 @@ exports.import = import_
# FIXME: if position is used, all other disks after this position
# should be shifted.
attachDisk = $coroutine ({vm, vdi, position, mode, bootable}) ->
xapi = @getXAPI vm
VBD_ref = $wait xapi.call 'VBD.create', {
VM: vm.ref
VDI: vdi.ref
mode: mode
type: 'Disk'
userdevice: position
bootable: bootable ? false
empty: false
other_config: {}
qos_algorithm_type: ''
qos_algorithm_params: {}
}
$wait xapi.call 'VBD.plug', VBD_ref
return true
$wait @getXAPI(vm).attachVdiToVm(vdi.id, vm.id, {bootable, mode, position})
return
attachDisk.params = {
bootable: {
type: 'boolean'
optional: true
}
mode: { type: 'string' }
position: { type: 'string' }
mode: { type: 'string', optional: true }
position: { type: 'string', optional: true }
vdi: { type: 'string' }
vm: { type: 'string' }
}

View File

@ -496,6 +496,41 @@ export default class Xapi extends XapiBase {
)
}
async attachVdiToVm (vdiId, vmId, {
bootable = false,
mode = 'RW',
position
} = {}) {
const vdi = this.getObject(vdiId)
const vm = this.getObject(vmId)
if (position == null) {
forEach(vm.$VBDs, vbd => {
const curPos = +vbd.userdevice
if (!(position > curPos)) {
position = curPos
}
})
position = position == null ? 0 : position + 1
}
const vbdRef = await this.call('VBD.create', {
bootable,
empty: false,
mode,
other_config: {},
qos_algorithm_params: {},
qos_algorithm_type: '',
type: 'Disk',
userdevice: String(position),
VDI: vdi.$ref,
VM: vm.$ref
})
await this.call('VBD.plug', vbdRef)
}
// =================================================================
async createVirtualInterface (vmId, networkId, {