New Xapi#ejectCdFromVm().
This commit is contained in:
parent
21d265d12f
commit
70780fc4ef
@ -130,23 +130,8 @@ exports.delete = delete_
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
ejectCd = $coroutine ({vm}) ->
|
||||
xapi = @getXAPI vm
|
||||
|
||||
# Finds the CD drive.
|
||||
cdDriveRef = null
|
||||
$forEach (@getObjects vm.$VBDs), (VBD) ->
|
||||
if VBD.is_cd_drive
|
||||
cdDriveRef = VBD.ref
|
||||
return false
|
||||
return
|
||||
|
||||
if cdDriveRef
|
||||
yield xapi.call 'VBD.eject', cdDriveRef
|
||||
|
||||
# Silently attempts to destroy the VBD.
|
||||
xapi.call('VBD.destroy', cdDriveRef).catch(->)
|
||||
|
||||
return true
|
||||
yield @getXAPI(vm).ejectCdFromVm(vm)
|
||||
return
|
||||
|
||||
ejectCd.params = {
|
||||
id: { type: 'string' }
|
||||
|
13
src/xapi.js
13
src/xapi.js
@ -717,13 +717,20 @@ export default class Xapi extends XapiBase {
|
||||
}
|
||||
|
||||
_getVmCdDrive (vm) {
|
||||
for (let vbd of vm.$VBDs) {
|
||||
for (const vbd of vm.$VBDs) {
|
||||
if (vbd.type === 'CD') {
|
||||
return vbd
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _ejectCdFromVm (vm) {
|
||||
const cdDrive = this._getVmCdDrive(vm)
|
||||
if (cdDrive) {
|
||||
await this.call('VBD.eject', cdDrive.$ref)
|
||||
}
|
||||
}
|
||||
|
||||
async _insertCdIntoVm (cd, vm, {
|
||||
bootable = false,
|
||||
force = false
|
||||
@ -772,6 +779,10 @@ export default class Xapi extends XapiBase {
|
||||
await this._deleteVdi(this.getObject(vdiId))
|
||||
}
|
||||
|
||||
async ejectCdFromVm (vmId) {
|
||||
await this._ejectCdFromVm(this.getObject(vmId))
|
||||
}
|
||||
|
||||
async insertCdIntoVm (cdId, vmId, opts = undefined) {
|
||||
await this._insertCdIntoVm(
|
||||
this.getObject(cdId),
|
||||
|
Loading…
Reference in New Issue
Block a user