feat(vm.start): with force can bypass blocked operation (#550)

See vatesfr/xo-web#2119
This commit is contained in:
badrAZ 2017-05-23 10:59:22 +02:00 committed by Julien Fontanet
parent 90be44738d
commit 9c5df507ae
2 changed files with 12 additions and 5 deletions

View File

@ -892,10 +892,11 @@ exports.rollingDrCopy = rollingDrCopy
#---------------------------------------------------------------------
start = ({vm}) ->
return @getXapi(vm).startVm(vm._xapiId)
start = ({vm, force}) ->
return @getXapi(vm).startVm(vm._xapiId, force)
start.params = {
force: { type: 'boolean', optional: true}
id: { type: 'string' }
}

View File

@ -1433,9 +1433,15 @@ export default class Xapi extends XapiBase {
await this._updateObjectMapProperty(vm, 'VCPUs_params', {weight})
}
_startVm (vm) {
async _startVm (vm, force) {
debug(`Starting VM ${vm.name_label}`)
if (force) {
await this._updateObjectMapProperty(vm, 'blocked_operations', {
start: null
})
}
return this.call(
'VM.start',
vm.$ref,
@ -1444,9 +1450,9 @@ export default class Xapi extends XapiBase {
)
}
async startVm (vmId) {
async startVm (vmId, force) {
try {
await this._startVm(this.getObject(vmId))
await this._startVm(this.getObject(vmId), force)
} catch (e) {
if (e.code === 'OPERATION_BLOCKED') {
throw forbiddenOperation('Start', e.params[1])