From 9ce8a24eead2dc9f06ef1b7552beaf8dc9ecc94a Mon Sep 17 00:00:00 2001 From: Olivier Lambert Date: Fri, 27 May 2016 18:31:09 +0200 Subject: [PATCH] feat(sr): add disconnect and connect all PBDs to a SR (#324) --- src/api/sr.js | 28 ++++++++++++++++++++++++++++ src/xapi-mixins/storage.js | 18 ++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/api/sr.js b/src/api/sr.js index 5605dcdf7..6c9291a96 100644 --- a/src/api/sr.js +++ b/src/api/sr.js @@ -76,6 +76,34 @@ forget.resolve = { // ------------------------------------------------------------------- +export async function connectAllPbds ({SR}) { + await this.getXapi(SR).connectAllSrPbds(SR._xapiId) +} + +connectAllPbds.params = { + id: { type: 'string' } +} + +connectAllPbds.resolve = { + SR: ['id', 'SR', 'administrate'] +} + +// ------------------------------------------------------------------- + +export async function disconnectAllPbds ({SR}) { + await this.getXapi(SR).disconnectAllSrPbds(SR._xapiId) +} + +disconnectAllPbds.params = { + id: { type: 'string' } +} + +disconnectAllPbds.resolve = { + SR: ['id', 'SR', 'administrate'] +} + +// ------------------------------------------------------------------- + export async function createIso ({ host, nameLabel, diff --git a/src/xapi-mixins/storage.js b/src/xapi-mixins/storage.js index 8f1590e62..f21124181 100644 --- a/src/xapi-mixins/storage.js +++ b/src/xapi-mixins/storage.js @@ -3,6 +3,16 @@ import { } from '../utils' export default { + _connectAllSrPbds (sr) { + return Promise.all( + mapToArray(sr.$PBDs, pbd => this._plugPbd(pbd)) + ) + }, + + async connectAllSrPbds (id) { + await this._connectAllSrPbds(this.getObject(id)) + }, + _disconnectAllSrPbds (sr) { return Promise.all( mapToArray(sr.$PBDs, pbd => this._unplugPbd(pbd)) @@ -25,6 +35,14 @@ export default { await this.call('SR.forget', sr.$ref) }, + _plugPbd (pbd) { + return this.call('PBD.plug', pbd.$ref) + }, + + async plugPbd (id) { + await this._plugPbd(this.getObject(id)) + }, + _unplugPbd (pbd) { return this.call('PBD.unplug', pbd.$ref) },