From ea481367974ee2e4bde3dfc69dda5b98646ede31 Mon Sep 17 00:00:00 2001 From: badrAZ Date: Mon, 14 Jan 2019 15:01:44 +0100 Subject: [PATCH] feat(xo-server/host): ability to enable/disable multipathing (#3858) See #3659 --- packages/xo-server/src/api/host.js | 16 +++++++++++++-- packages/xo-server/src/xapi/index.js | 30 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/xo-server/src/api/host.js b/packages/xo-server/src/api/host.js index 2b1561584..49c9ecd55 100644 --- a/packages/xo-server/src/api/host.js +++ b/packages/xo-server/src/api/host.js @@ -2,14 +2,22 @@ import { format } from 'json-rpc-peer' // =================================================================== -export function set({ +export async function set({ host, + multipathing, // TODO: use camel case. name_label: nameLabel, name_description: nameDescription, }) { - return this.getXapi(host).setHostProperties(host._xapiId, { + const xapi = this.getXapi(host) + const hostId = host._xapiId + + if (multipathing !== undefined) { + await xapi.setHostMultipathing(hostId, multipathing) + } + + return xapi.setHostProperties(hostId, { nameLabel, nameDescription, }) @@ -27,6 +35,10 @@ set.params = { type: 'string', optional: true, }, + multipathing: { + type: 'boolean', + optional: true, + }, } set.resolve = { diff --git a/packages/xo-server/src/xapi/index.js b/packages/xo-server/src/xapi/index.js index 4a6813044..51c51dc30 100644 --- a/packages/xo-server/src/xapi/index.js +++ b/packages/xo-server/src/xapi/index.js @@ -415,6 +415,36 @@ export default class Xapi extends XapiBase { await this.call('host.enable', this.getObject(hostId).$ref) } + @deferrable.onError(log.warn) + async setHostMultipathing($defer, hostId, multipathing) { + const host = this.getObject(hostId) + + const pluggedPbds = host.$PBDs.filter(pbd => pbd.currently_attached) + await asyncMap(pluggedPbds, async pbd => { + const ref = pbd.$ref + await this.unplugPbd(ref) + $defer(() => this.plugPbd(ref)) + }) + + if (host.enabled) { + await this.disableHost(hostId) + $defer(() => this.enableHost(hostId)) + } + + return this._updateObjectMapProperty( + host, + 'other_config', + multipathing + ? { + multipathing: 'true', + multipathhandle: 'dmp', + } + : { + multipathing: 'false', + } + ) + } + async powerOnHost(hostId) { await this.call('host.power_on', this.getObject(hostId).$ref) }