From 15aec7da7e79f0a80598ba0c6e9f80b3562c3d02 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Fri, 20 Nov 2015 16:19:33 +0100 Subject: [PATCH] vm.clone() requires permissions on SRs. --- src/api/vm.coffee | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/api/vm.coffee b/src/api/vm.coffee index 6d65dd360..aadcb5c3f 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -27,7 +27,7 @@ startsWith = require 'lodash.startswith' #===================================================================== -checkPermissionsForSnapshot = (vm) -> ( +checkPermissionOnSrs = (vm, permission = 'operate') -> ( permissions = [] forEach(vm.$VBDs, (vbdId) => vbd = @getObject(vbdId, 'VBD') @@ -38,7 +38,7 @@ checkPermissionsForSnapshot = (vm) -> ( permissions.push([ @getObject(vdiId, 'VDI').$SR, - 'operate' + permission ]) ) @@ -390,7 +390,9 @@ exports.restart = restart #--------------------------------------------------------------------- -clone = ({vm, name, full_copy}) -> +clone = $coroutine ({vm, name, full_copy}) -> + yield checkPermissionOnSrs.call(this, vm) + return @getXAPI(vm).cloneVm(vm._xapiRef, { nameLabel: name, fast: not full_copy @@ -419,7 +421,7 @@ copy = $coroutine ({ }) -> if vm.$pool == sr.$pool if vm.power_state is 'Running' - yield checkPermissionsForSnapshot.call(this, vm) + yield checkPermissionOnSrs.call(this, vm) return @getXAPI(vm).copyVm(vm._xapiId, sr._xapiId, { nameLabel @@ -470,7 +472,7 @@ exports.convert = convert #--------------------------------------------------------------------- snapshot = $coroutine ({vm, name}) -> - yield checkPermissionsForSnapshot.call(this, vm) + yield checkPermissionOnSrs.call(this, vm) snapshot = yield @getXAPI(vm).snapshotVm(vm._xapiRef, name) return snapshot.$id @@ -488,7 +490,7 @@ exports.snapshot = snapshot #--------------------------------------------------------------------- rollingSnapshot = $coroutine ({vm, tag, depth}) -> - yield checkPermissionsForSnapshot.call(this, vm) + yield checkPermissionOnSrs.call(this, vm) yield @rollingSnapshotVm(vm, tag, depth) rollingSnapshot.params = { @@ -711,7 +713,7 @@ handleExport = (req, res, { stream }) -> # TODO: integrate in xapi.js export_ = $coroutine ({vm, compress, onlyMetadata}) -> if vm.power_state is 'Running' - yield checkPermissionsForSnapshot.call(this, vm) + yield checkPermissionOnSrs.call(this, vm) stream = yield @getXAPI(vm).exportVm(vm._xapiId, { compress: compress ? true,