Get stats for host.

This commit is contained in:
wescoeur 2016-02-24 15:27:11 +01:00
parent 3013fa86b6
commit cb97e37c15

View File

@ -25,7 +25,6 @@ export const configurationSchema = {
properties: { properties: {
plans: { plans: {
type: 'array', type: 'array',
title: 'plans',
description: 'an array of plans', description: 'an array of plans',
items: { items: {
@ -69,7 +68,7 @@ export const configurationSchema = {
pools: { pools: {
type: 'array', type: 'array',
title: 'list of pools id where to apply the policy', description: 'list of pools id where to apply the policy',
items: { items: {
type: 'string', type: 'string',
@ -124,37 +123,57 @@ class Plan {
} }
async execute () { async execute () {
const stats = await this._getStats( const stats = await this._getHostsStatsByPool(
this._getHosts() this._getHostsByPool()
) )
stats // FIXME console.log(stats)
} }
// Compute hosts for each pool. They can change over time. // Compute hosts for each pool. They can change over time.
_getHosts () { _getHostsByPool () {
const objects = filter(this.xo.getObjects(), { type: 'host' }) const objects = filter(this.xo.getObjects(), { type: 'host' })
const hosts = {} const hostsByPool = {}
for (const poolUuid of this._objects) { for (const poolId of this._poolIds) {
hosts[poolUuid] = filter(objects, { uuid: poolUuid }) hostsByPool[poolId] = filter(objects, { '$poolId': poolId })
} }
return hosts return hostsByPool
} }
async _getStats (hosts) { async _getHostsStatsByPool (hostsByPool) {
const promises = [] const promises = []
for (const poolUuid of hosts) { for (const poolId in hostsByPool) {
promises.push(Promise.all( promises.push(
mapToArray(hosts[poolUuid], host => Promise.all(
this.xo.getXapiHostStats(host, 'seconds') mapToArray(hostsByPool[poolId], host =>
) this.xo.getXapiHostStats(host, 'seconds')
)) )
).then(stats => {
const obj = {}
let i = 0
for (const host of hostsByPool[poolId]) {
obj[host.id] = stats[i++]
}
return obj
})
)
} }
return await Promise.all(promises) return Promise.all(promises).then(statsArray => {
const obj = {}
let i = 0
for (const poolId in hostsByPool) {
obj[poolId] = statsArray[i++]
}
return obj
})
} }
} }
@ -199,6 +218,15 @@ class LoadBalancerPlugin {
} }
} }
// TMP
this._addPlan({
name: 'Test plan',
mode: MODE_PERFORMANCE,
behavior: BEHAVIOR_AGGRESSIVE,
poolIds: [ '313624ab-0958-bb1e-45b5-7556a463a10b' ]
})
this._executePlans()
if (enabled) { if (enabled) {
cronJob.start() cronJob.start()
} }