resourceSet.set(): better handling of limits.

This commit is contained in:
Julien Fontanet 2016-02-23 13:11:56 +01:00
parent c6f7290f92
commit 208ea04fd5
2 changed files with 20 additions and 6 deletions

View File

@ -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}"

View File

@ -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)