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 _getPoolVmsStats = async (machine, granularity) => {
const host = await this_._xo.getObject(machine) const host = await this_._xo.getObject(machine)
const objects = await this_._xo.getObjects() const objects = await this_._xo.getObjects()
const vmsOnPool = [] const runningVmsOnPool = []
forEach(objects, (obj) => { forEach(objects, (obj) => {
if (obj.type === 'VM' && obj.$poolId === host.$poolId) { if (obj.type === 'VM' && obj.power_state === 'Running' && obj.$poolId === host.$poolId) {
vmsOnPool.push(obj) runningVmsOnPool.push(obj)
} }
}) })
const poolVmStats = [] const vmStats = {}
for (const vm of vmsOnPool) { for (const vm of runningVmsOnPool) {
if (vm.power_state === 'Running') { vmStats[vm.id] = await this_._xo.getXapiVmStats(vm, granularity)
const vmStats = await this_._xo.getXapiVmStats(vm, granularity)
poolVmStats.push(vmStats)
}
} }
return poolVmStats return vmStats
} }
this._unsets.push(this._xo.api.addMethod('generateGlobalVmReport', async ({ machine, granularity }) => { this._unsets.push(this._xo.api.addMethod('generateGlobalVmReport', async ({ machine, granularity }) => {