From 208ea04fd5e1c6d9e8918aa6577b4dbc51b601a5 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 23 Feb 2016 13:11:56 +0100 Subject: [PATCH] resourceSet.set(): better handling of limits. --- src/api/vm.coffee | 5 +++-- src/xo-mixins/resource-sets.js | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/api/vm.coffee b/src/api/vm.coffee index e7d871636..a60e09863 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -69,8 +69,9 @@ create = $coroutine ({ limits = { cpus: template.CPUs.number, + disk: 0, memory: template.memory.static[1], - disk: 0 + vms: 1 } objectIds = [] @@ -384,7 +385,7 @@ set = $coroutine (params) -> yield xapi.call 'VM.set_memory_static_max', ref, "#{memory}" if resourceSet? yield @allocateLimitsInResourceSet({ - memory: memory - memoryVM.memory.size + memory: memory - VM.memory.size }, resourceSet) yield xapi.call 'VM.set_memory_dynamic_max', ref, "#{memory}" diff --git a/src/xo-mixins/resource-sets.js b/src/xo-mixins/resource-sets.js index c53809d3d..abcf1f0ee 100644 --- a/src/xo-mixins/resource-sets.js +++ b/src/xo-mixins/resource-sets.js @@ -125,10 +125,23 @@ export default class { set.objects = objects } if (limits) { - set.limits = map(limits, (quantity, limit) => ({ - available: quantity, - total: quantity - })) + const previousLimits = set.limits + set.limits = map(limits, (quantity, id) => { + const previous = previousLimits[id] + if (!previous) { + return { + available: quantity, + total: quantity + } + } + + const { available, total } = previous + + return { + available: available - total + quantity, + total: quantity + } + }) } await this._save(set)