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