position is now optional for vm.attachDisk().
This commit is contained in:
parent
3befdbc93d
commit
26e8ae4bf3
@ -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' }
|
||||
}
|
||||
|
35
src/xapi.js
35
src/xapi.js
@ -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, {
|
||||
|
Loading…
Reference in New Issue
Block a user