Try to power on a hosts set. (Performance mode)

This commit is contained in:
wescoeur 2016-04-06 16:00:01 +02:00
parent 3e285d6131
commit f0c28c74d8
3 changed files with 19 additions and 5 deletions

View File

@ -3,9 +3,7 @@ import clone from 'lodash.clonedeep'
import { default as mapToArray } from 'lodash.map'
import Plan from './plan'
import {
debug
} from './utils'
import { debug } from './utils'
// ===================================================================

View File

@ -1,5 +1,6 @@
import filter from 'lodash.filter'
import find from 'lodash.find'
import { default as mapToArray } from 'lodash.map'
import Plan from './plan'
import { debug } from './utils'
@ -36,6 +37,21 @@ export default class PerformancePlan extends Plan {
}
async execute () {
// Try to power on a hosts set.
try {
await Promise.all(
mapToArray(
filter(this._getHosts({ powerState: 'Halted' }), host => host.powerOnMode !== ''),
host => {
const { id } = host
return this.xo.getXapi(id).powerOnHost(id)
}
)
)
} catch (error) {
console.error(error)
}
const results = await this._findHostsToOptimize()
if (!results) {

View File

@ -186,11 +186,11 @@ export default class Plan {
}
// Compute hosts for each pool. They can change over time.
_getHosts () {
_getHosts ({ powerState = 'Running' } = {}) {
return filter(this.xo.getObjects(), object => (
object.type === 'host' &&
includes(this._poolIds, object.$poolId) &&
object.power_state !== 'Halted' &&
object.power_state === powerState &&
!includes(this._excludedHosts, object.id)
))
}