feat(vm.revert): can snapshot before (#395)

See vatesfr/xo-web#1445
This commit is contained in:
Julien Fontanet 2016-09-15 14:59:43 +02:00 committed by GitHub
parent fb804e99f0
commit edd606563f
2 changed files with 12 additions and 7 deletions

View File

@ -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 = {

View File

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