fix(Xapi#editVm): XS 7.3 support for memory (#634)

Fixes vatesfr/xo-web#2540
This commit is contained in:
Julien Fontanet 2017-12-28 15:22:03 +01:00 committed by GitHub
commit 5fe03f2934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,5 @@
import deferrable from 'golike-defer'
import { ignoreErrors } from 'promise-toolbox'
import { catchPlus as pCatch, ignoreErrors } from 'promise-toolbox'
import {
find,
gte,
@ -319,13 +319,40 @@ export default {
memoryMax: {
addToLimits: true,
limitName: 'memory',
constraints: {
memoryMin: lte,
memoryStaticMax: gte,
},
get: vm => +vm.memory_dynamic_max,
preprocess: parseSize,
set: 'memory_dynamic_max',
set (dynamicMax, vm) {
const { $ref } = vm
const dynamicMin = Math.min(vm.memory_dynamic_min, dynamicMax)
if (isVmRunning(vm)) {
return this.call(
'VM.set_memory_dynamic_range',
$ref,
dynamicMin,
dynamicMax
)
}
const staticMin = Math.min(vm.memory_static_min, dynamicMax)
return this.call(
'VM.set_memory_limits',
$ref,
staticMin,
Math.max(dynamicMax, vm.memory_static_max),
dynamicMin,
dynamicMax
)::pCatch({ code: 'MEMORY_CONSTRAINT_VIOLATION' }, () =>
this.call(
'VM.set_memory_limits',
$ref,
staticMin,
dynamicMax,
dynamicMax,
dynamicMax
)
)
},
},
memoryStaticMax: {