Get only the vms stats of the worst host.

This commit is contained in:
wescoeur 2016-02-26 11:57:41 +01:00
parent 087a71367d
commit dee7767427

View File

@ -235,11 +235,12 @@ class Plan {
}) })
// 4. Search bests combinations for the worst host. // 4. Search bests combinations for the worst host.
const optimizations = await this._computeOptimizations(exceededHosts[0], { const toOptimize = exceededHosts[0]
now: avgNow, const optimizations = await this._computeOptimizations(
before: avgBefore, toOptimize,
withRatio: avgWithRatio filter(hosts, host => host.id !== toOptimize.id),
}) avgWithRatio
)
// 5. Apply optimizations if necessary. // 5. Apply optimizations if necessary.
await this._applyOptimizations(optimizations) await this._applyOptimizations(optimizations)
@ -251,10 +252,10 @@ class Plan {
async _computeOptimizations (exceededHost, hostsAverages) { async _computeOptimizations (exceededHost, hostsAverages) {
// Get the vms and stats from exceeded hosts. // Get the vms and stats from exceeded hosts.
const vms = await this._getVms(exceeded) const vms = await this._getVms(exceededHost.id)
const vmsStats = await this._getVmsStats(vms, 'minutes') const vmsStats = await this._getVmsStats(vms, 'minutes')
// TODO
} }
async _applyOptimizations (optimizations) { async _applyOptimizations (optimizations) {
@ -284,44 +285,26 @@ class Plan {
return hostsStats return hostsStats
} }
async _getVms (hosts) { async _getVms (hostId) {
const objects = this.xo.getObjects() return filter(this.xo.getObjects(), object =>
const vms = {}
for (const host of hosts) {
const { id } = host
vms[id] = filter(objects, object =>
object.type === 'VM' && object.type === 'VM' &&
object.power_state === 'Running' && object.power_state === 'Running' &&
object.$container === id object.$container === hostId
) )
} }
return vms
}
async _getVmsStats (vms, granularity) { async _getVmsStats (vms, granularity) {
const promises = []
const vmsStats = {} const vmsStats = {}
for (const hostId in vms) { await Promise.all(mapToArray(vms, vm =>
const hostVmsStats = vmsStats[hostId] = {}
promises.push(
Promise.all(mapToArray(vms[hostId], vm =>
this.xo.getXapiVmStats(vm, granularity).then(vmStats => { this.xo.getXapiVmStats(vm, granularity).then(vmStats => {
hostVmsStats[vm.id] = { vmsStats[vm.id] = {
nPoints: vmStats.stats.cpus[0].length, nPoints: vmStats.stats.cpus[0].length,
stats: vmStats.stats, stats: vmStats.stats,
averages: {} averages: {}
} }
}) })
)) ))
)
}
await Promise.all(promises)
return vmsStats return vmsStats
} }