From edd606563f28c9d169c3d1fbef000f7bd6149dd0 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Thu, 15 Sep 2016 14:59:43 +0200 Subject: [PATCH] feat(vm.revert): can snapshot before (#395) See vatesfr/xo-web#1445 --- src/api/vm.coffee | 11 ++++------- src/xapi/mixins/vm.js | 8 ++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/api/vm.coffee b/src/api/vm.coffee index cc6e1dad9..864fb1f4d 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -878,15 +878,12 @@ exports.resume = resume #--------------------------------------------------------------------- -# revert a snapshot to its parent VM -revert = $coroutine ({snapshot}) -> - # Attempts a revert from this snapshot to its parent VM - yield @getXapi(snapshot).call 'VM.revert', snapshot._xapiRef - - return true +revert = ({snapshot, snapshotBefore}) -> + return @getXapi(snapshot).revertVm(snapshot._xapiId, snapshotBefore) revert.params = { - id: { type: 'string' } + id: { type: 'string' }, + snapshotBefore: { type: 'boolean', optional: true } } revert.resolve = { diff --git a/src/xapi/mixins/vm.js b/src/xapi/mixins/vm.js index 8fade7f6d..b5c52429c 100644 --- a/src/xapi/mixins/vm.js +++ b/src/xapi/mixins/vm.js @@ -326,5 +326,13 @@ export default { async editVm (id, props) { return /* await */ this._editVm(this.getObject(id), props) + }, + + async revertVm (snapshotId, snapshotBefore = true) { + const snapshot = this.getObject(snapshotId) + if (snapshotBefore) { + await this._snapshotVm(snapshot.$snapshot_of) + } + return this.call('VM.revert', snapshot.$ref) } }