From 290cc146c8af43d76ed4221feb69ab3d5e7ae6f1 Mon Sep 17 00:00:00 2001 From: Olivier Lambert Date: Thu, 11 Aug 2016 16:32:06 +0200 Subject: [PATCH] fix(xapi): allow to unplug VBDs when VM is running --- src/xapi/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/xapi/index.js b/src/xapi/index.js index 17e433fac..38020174d 100644 --- a/src/xapi/index.js +++ b/src/xapi/index.js @@ -1839,9 +1839,16 @@ export default class Xapi extends XapiBase { await this.call('VBD.plug', vbdId) } - _disconnectVbd (vbd) { + async _disconnectVbd (vbd) { // TODO: check if VBD is attached before - return this.call('VBD.unplug_force', vbd.$ref) + try { + await this.call('VBD.unplug_force', vbd.$ref) + } catch (error) { + if (error.code === 'VBD_NOT_UNPLUGGABLE') { + await this.call('VBD.set_unpluggable', vbd.$ref, true) + return this.call('VBD.unplug_force', vbd.$ref) + } + } } async disconnectVbd (vbdId) {