Optimize hosts in order priority.

This commit is contained in:
wescoeur 2016-03-17 11:21:15 +01:00
parent da0c1cec22
commit 12e0759711

View File

@ -438,20 +438,26 @@ class PerformancePlan extends Plan {
toOptimize
} = results
const exceededHost = searchObject(toOptimize, (a, b) => {
toOptimize.sort((a, b) => {
a = averages[a.id]
b = averages[b.id]
return (b.cpu - a.cpu) || (a.memoryFree - b.memoryFree)
})
for (const exceededHost of toOptimize) {
const { id } = exceededHost
debug(`Try to optimize Host (${exceededHost.id}).`)
// Search bests combinations for the worst host.
await this._optimize({
exceededHost,
hosts: filter(hosts, host => host.id !== exceededHost.id),
hosts: filter(hosts, host => host.id !== id),
hostsAverages: averages
})
}
}
async _optimize ({ exceededHost, hosts, hostsAverages }) {
const vms = await this._getVms(exceededHost.id)
@ -466,6 +472,7 @@ class PerformancePlan extends Plan {
const promises = []
const xapiSrc = this.xo.getXapi(exceededHost)
let optimizationsCount = 0
for (const vm of vms) {
// Search host with lower cpu usage.
@ -489,7 +496,8 @@ class PerformancePlan extends Plan {
exceededAverages.memoryFree += vmAverages.memory
destinationAverages.memoryFree -= vmAverages.memory
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id})`)
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id}).`)
optimizationsCount++
// promises.push(
// xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId)
@ -497,6 +505,7 @@ class PerformancePlan extends Plan {
}
await Promise.all(promises)
debug(`${optimizationsCount} optimizations for Host (${exceededHost.id}).`)
return
}