feat(xo-server/vm.snapshot): add saveMemory param (#3807)

Related to #3795
This commit is contained in:
Julien Fontanet 2018-12-19 10:39:53 +01:00 committed by GitHub
parent 4d4e87aa93
commit 917701e2f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -747,12 +747,18 @@ export { convertToTemplate as convert }
// TODO: implement resource sets
export const snapshot = defer(async function(
$defer,
{ vm, name = `${vm.name_label}_${new Date().toISOString()}` }
{
vm,
name = `${vm.name_label}_${new Date().toISOString()}`,
saveMemory = false,
}
) {
await checkPermissionOnSrs.call(this, vm)
const xapi = this.getXapi(vm)
const { $id: snapshotId } = await xapi.snapshotVm(vm._xapiRef, name)
const { $id: snapshotId } = await (saveMemory
? xapi.checkpointVm(vm._xapiRef, name)
: xapi.snapshotVm(vm._xapiRef, name))
$defer.onFailure(() => xapi.deleteVm(snapshotId))
const { user } = this
@ -765,6 +771,7 @@ export const snapshot = defer(async function(
snapshot.params = {
id: { type: 'string' },
name: { type: 'string', optional: true },
saveMemory: { type: 'boolean', optional: true },
}
snapshot.resolve = {

View File

@ -12,6 +12,16 @@ const XEN_VGA_VALUES = ['std', 'cirrus']
const XEN_VIDEORAM_VALUES = [1, 2, 4, 8, 16]
export default {
// https://xapi-project.github.io/xen-api/classes/vm.html#checkpoint
checkpointVm(vmId, nameLabel) {
const vm = this.getObject(vmId)
return this.asyncCall(
'VM.checkpoint',
vm.$ref,
nameLabel != null ? nameLabel : vm.name_label
)
},
// TODO: clean up on error.
@deferrable
async createVm(