chore(Xapi#exportDeltaVm): make it cancelable

This commit is contained in:
Julien Fontanet 2017-06-27 11:16:34 +02:00
parent 7bcece7f76
commit bc853da09a
2 changed files with 7 additions and 4 deletions

View File

@ -770,8 +770,9 @@ export default class Xapi extends XapiBase {
}
// Create a snapshot of the VM and returns a delta export object.
@cancellable
@deferrable.onFailure
async exportDeltaVm ($onFailure, vmId, baseVmId = undefined, {
async exportDeltaVm ($onFailure, $cancelToken, vmId, baseVmId = undefined, {
snapshotNameLabel = undefined,
// Contains a vdi.$id set of vmId.
fullVdisRequired = [],

View File

@ -3,6 +3,7 @@ import escapeStringRegexp from 'escape-string-regexp'
import eventToPromise from 'event-to-promise'
import execa from 'execa'
import splitLines from 'split-lines'
import { CancelToken } from 'promise-toolbox'
import { createParser as createPairsParser } from 'parse-pairs'
import { createReadStream, readdir, stat } from 'fs'
import { satisfies as versionSatisfies } from 'semver'
@ -416,11 +417,12 @@ export default class {
// 2. Copy.
let size = 0
const dstVm = await (async () => {
const delta = await srcXapi.exportDeltaVm(srcVm.$id, localBaseUuid, {
const { cancel, token } = CancelToken.source()
const delta = await srcXapi.exportDeltaVm(token, srcVm.$id, localBaseUuid, {
snapshotNameLabel: `XO_DELTA_EXPORT: ${targetSr.name_label} (${targetSr.uuid})`
})
$onFailure(() => srcXapi.deleteVm(delta.vm.uuid)::pCatch(noop))
forEach(delta.streams, stream => $onFailure(stream.cancel))
$onFailure(() => srcXapi.deleteVm(delta.vm.uuid))
$onFailure(cancel)
delta.vm.name_label += ` (${shortDate(Date.now())})`