From 9c5df507ae3d09d0c35b65cb70412d3ea9c19530 Mon Sep 17 00:00:00 2001 From: badrAZ Date: Tue, 23 May 2017 10:59:22 +0200 Subject: [PATCH] feat(vm.start): with force can bypass blocked operation (#550) See vatesfr/xo-web#2119 --- src/api/vm.coffee | 5 +++-- src/xapi/index.js | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/api/vm.coffee b/src/api/vm.coffee index e33d7163f..c3fcf568d 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -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' } } diff --git a/src/xapi/index.js b/src/xapi/index.js index f70d7a13e..16a6dac55 100644 --- a/src/xapi/index.js +++ b/src/xapi/index.js @@ -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])