getPoolVmStats returns an object with VM IDs as keys instead of an array

This commit is contained in:
Pierre 2016-02-05 16:42:00 +01:00
parent d21f5f427c
commit 7a884d1f87

View File

@ -138,20 +138,17 @@ class UsageReportPlugin {
const _getPoolVmsStats = async (machine, granularity) => {
const host = await this_._xo.getObject(machine)
const objects = await this_._xo.getObjects()
const vmsOnPool = []
const runningVmsOnPool = []
forEach(objects, (obj) => {
if (obj.type === 'VM' && obj.$poolId === host.$poolId) {
vmsOnPool.push(obj)
if (obj.type === 'VM' && obj.power_state === 'Running' && obj.$poolId === host.$poolId) {
runningVmsOnPool.push(obj)
}
})
const poolVmStats = []
for (const vm of vmsOnPool) {
if (vm.power_state === 'Running') {
const vmStats = await this_._xo.getXapiVmStats(vm, granularity)
poolVmStats.push(vmStats)
}
const vmStats = {}
for (const vm of runningVmsOnPool) {
vmStats[vm.id] = await this_._xo.getXapiVmStats(vm, granularity)
}
return poolVmStats
return vmStats
}
this._unsets.push(this._xo.api.addMethod('generateGlobalVmReport', async ({ machine, granularity }) => {