diff --git a/src/api.js b/src/api.js index 5f69e666e..60ee050d6 100644 --- a/src/api.js +++ b/src/api.js @@ -272,6 +272,20 @@ export default class Api { try { await checkPermission.call(context, method) + + // API methods are in a namespace. + // Some methods use the namespace or an id parameter like: + // + // vm.detachPci vm= + // vm.ejectCd id= + // + // The goal here is to standardize the calls by always providing + // an id parameter when possible to simplify calls to the API. + if (params && params.id === undefined) { + const namespace = name.slice(0, name.indexOf('.')) + params.id = params[namespace] + } + checkParams(method, params) const resolvedParams = await resolveParams.call(context, method, params) diff --git a/src/api/vm.coffee b/src/api/vm.coffee index 426d198b2..33a986994 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -688,14 +688,14 @@ rollingDeltaBackup = $coroutine ({vm, remote, tag, depth}) -> }) rollingDeltaBackup.params = { - vm: { type: 'string' } + id: { type: 'string' } remote: { type: 'string' } tag: { type: 'string'} depth: { type: ['string', 'number'] } } rollingDeltaBackup.resolve = { - vm: ['vm', ['VM', 'VM-snapshot'], 'administrate'] + vm: ['id', ['VM', 'VM-snapshot'], 'administrate'] } rollingDeltaBackup.permission = 'admin' @@ -726,12 +726,12 @@ exports.importDeltaBackup = importDeltaBackup deltaCopy = ({ vm, sr }) -> @deltaCopyVm(vm, sr) deltaCopy.params = { - vm: { type: 'string' }, + id: { type: 'string' }, sr: { type: 'string' } } deltaCopy.resolve = { - vm: [ 'vm', 'VM', 'operate'], + vm: [ 'id', 'VM', 'operate'], sr: [ 'sr', 'SR', 'operate'] }