diff --git a/src/api/host.coffee b/src/api/host.coffee index b9a525f56..2d65e1bf2 100644 --- a/src/api/host.coffee +++ b/src/api/host.coffee @@ -14,10 +14,17 @@ startsWith = require 'lodash.startswith' #===================================================================== -set = (params) -> - host = extractProperty(params, 'host') +set = ({ + host, - return @getXAPI(host).setHostProperties(host._xapiId, params) + # TODO: use camel case. + name_label: nameLabel, + name_description: nameDescription +}) -> + return @getXAPI(host).setHostProperties(host._xapiId, { + nameLabel, + nameDescription + }) set.description = 'changes the properties of an host' diff --git a/src/api/pool.js b/src/api/pool.js index 11e83ad43..3cc87d7f6 100644 --- a/src/api/pool.js +++ b/src/api/pool.js @@ -1,12 +1,18 @@ import {JsonRpcError} from '../api-errors' -import {extractProperty} from '../utils' // =================================================================== -export async function set (params) { - const pool = extractProperty(params, 'pool') +export async function set ({ + pool, - await this.getXAPI(pool).setPoolProperties(params) + // TODO: use camel case. + name_description: nameDescription, + name_label: nameLabel +}) { + await this.getXAPI(pool).setPoolProperties({ + nameDescription, + nameLabel + }) } set.params = { diff --git a/src/api/sr.js b/src/api/sr.js index c05df379f..12eeeb4b2 100644 --- a/src/api/sr.js +++ b/src/api/sr.js @@ -1,16 +1,22 @@ import { ensureArray, - extractProperty, forEach, parseXml } from '../utils' // =================================================================== -export async function set (params) { - const sr = extractProperty(params, 'sr') +export async function set ({ + sr, - await this.getXAPI(sr).setSrProperties(sr._xapiId, params) + // TODO: use camel case. + name_description: nameDescription, + name_label: nameLabel +}) { + await this.getXAPI(sr).setSrProperties(sr._xapiId, { + nameDescription, + nameLabel + }) } set.params = { diff --git a/src/xapi.js b/src/xapi.js index fb4c20839..f50ed8359 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -234,32 +234,52 @@ export default class Xapi extends XapiBase { } async setHostProperties (id, { - name_label, - name_description + nameLabel, + nameDescription }) { await this._setObjectProperties(this.getObject(id), { - name_label, - name_description + nameLabel, + nameDescription }) } async setPoolProperties ({ - name_label, - name_description + autoPowerOn, + nameLabel, + nameDescription }) { - await this._setObjectProperties(this.pool, { - name_label, - name_description - }) + const { pool } = this + + const promises = [ + this._setObjectProperties(pool, { + nameLabel, + nameDescription + }) + ] + + // TODO: mutualize this code. + if (autoPowerOn != null) { + let p = this.call('pool.remove_from_other_config', pool.$ref, 'auto_poweron') + + if (autoPowerOn) { + p = p + .catch(noop) + .then(() => this.call('pool.add_to_other_config', pool.$ref, 'auto_poweron', 'true')) + } + + promises.push(p) + } + + await Promise.all(promises) } async setSrProperties (id, { - name_label, - name_description + nameLabel, + nameDescription }) { await this._setObjectProperties(this.getObject(id), { - name_label, - name_description + nameLabel, + nameDescription }) }