Performance and density mode work.

This commit is contained in:
wescoeur 2016-03-24 11:44:23 +01:00
parent 06f60b7d92
commit 42cef0da88
3 changed files with 38 additions and 10 deletions

View File

@ -54,6 +54,12 @@ export default class DensityPlan extends Plan {
continue continue
} }
// A host to optimize needs the ability to be restarted.
if (hostToOptimize.powerOnMode === '') {
debug(`Host (${hostId}) does not have a power on mode.`)
continue
}
let poolMaster // Pool master. let poolMaster // Pool master.
const poolHosts = [] // Without master. const poolHosts = [] // Without master.
const masters = [] // Without the master of this loop. const masters = [] // Without the master of this loop.
@ -99,7 +105,7 @@ export default class DensityPlan extends Plan {
hostsAverages = simulResults.hostsAverages hostsAverages = simulResults.hostsAverages
// Migrate. // Migrate.
await this._migrate(simulResults.moves) await this._migrate(hostId, simulResults.moves)
optimizationsCount++ optimizationsCount++
} }
} }
@ -115,6 +121,13 @@ export default class DensityPlan extends Plan {
const vms = await this._getVms(hostId) const vms = await this._getVms(hostId)
const vmsAverages = await this._getVmsAverages(vms, host) const vmsAverages = await this._getVmsAverages(vms, host)
for (const vm of vms) {
if (!vm.xenTools) {
debug(`VM (${vm.id}) of Host (${hostId}) does not support pool migration.`)
return
}
}
// Sort vms by amount of memory. (+ -> -) // Sort vms by amount of memory. (+ -> -)
vms.sort((a, b) => vms.sort((a, b) =>
vmsAverages[b.id].memory - vmsAverages[a.id].memory vmsAverages[b.id].memory - vmsAverages[a.id].memory
@ -180,6 +193,7 @@ export default class DensityPlan extends Plan {
continue continue
} }
// Move ok. Update stats.
destinationAverages.cpu += vmAverages.cpu destinationAverages.cpu += vmAverages.cpu
destinationAverages.memoryFree -= vmAverages.memory destinationAverages.memoryFree -= vmAverages.memory
@ -191,17 +205,29 @@ export default class DensityPlan extends Plan {
} }
} }
async _migrate (moves) { // Migrate the VMs of one host.
// Try to shutdown the VMs host.
async _migrate (hostId, moves) {
const xapiSrc = this.xo.getXapi(hostId)
await Promise.all( await Promise.all(
mapToArray(moves, move => { mapToArray(moves, move => {
const { const {
vm, vm,
destination destination
} = move } = move
const xapiSrc = this.xo.getXapi(destination) const xapiDest = this.xo.getXapi(destination)
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${vm.$container}).`) debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${vm.$container}).`)
// xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId) return xapiDest.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId)
}) })
) )
debug(`Shutdown Host (${hostId}).`)
try {
await xapiSrc.shutdownHost(hostId)
} catch (error) {
debug(`Unable to shutdown Host (${hostId}).`, error)
}
} }
} }

View File

@ -99,9 +99,9 @@ export default class PerformancePlan extends Plan {
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++ optimizationsCount++
// promises.push( promises.push(
// xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId) xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId)
// ) )
} }
await Promise.all(promises) await Promise.all(promises)

View File

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