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 = {} object.type === 'VM' &&
object.power_state === 'Running' &&
for (const host of hosts) { object.$container === hostId
const { id } = host )
vms[id] = filter(objects, object =>
object.type === 'VM' &&
object.power_state === 'Running' &&
object.$container === id
)
}
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] = {} this.xo.getXapiVmStats(vm, granularity).then(vmStats => {
vmsStats[vm.id] = {
promises.push( nPoints: vmStats.stats.cpus[0].length,
Promise.all(mapToArray(vms[hostId], vm => stats: vmStats.stats,
this.xo.getXapiVmStats(vm, granularity).then(vmStats => { averages: {}
hostVmsStats[vm.id] = { }
nPoints: vmStats.stats.cpus[0].length, })
stats: vmStats.stats, ))
averages: {}
}
})
))
)
}
await Promise.all(promises)
return vmsStats return vmsStats
} }