feat(api): rename <namespace> param to id (#305)

This commit is contained in:
ABHAMON Ronan 2016-05-11 14:35:49 +02:00 committed by Julien Fontanet
parent f570492a11
commit 8c0ae892f5
2 changed files with 18 additions and 4 deletions

View File

@ -272,6 +272,20 @@ export default class Api {
try { try {
await checkPermission.call(context, method) await checkPermission.call(context, method)
// API methods are in a namespace.
// Some methods use the namespace or an id parameter like:
//
// vm.detachPci vm=<string>
// vm.ejectCd id=<string>
//
// 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) checkParams(method, params)
const resolvedParams = await resolveParams.call(context, method, params) const resolvedParams = await resolveParams.call(context, method, params)

View File

@ -688,14 +688,14 @@ rollingDeltaBackup = $coroutine ({vm, remote, tag, depth}) ->
}) })
rollingDeltaBackup.params = { rollingDeltaBackup.params = {
vm: { type: 'string' } id: { type: 'string' }
remote: { type: 'string' } remote: { type: 'string' }
tag: { type: 'string'} tag: { type: 'string'}
depth: { type: ['string', 'number'] } depth: { type: ['string', 'number'] }
} }
rollingDeltaBackup.resolve = { rollingDeltaBackup.resolve = {
vm: ['vm', ['VM', 'VM-snapshot'], 'administrate'] vm: ['id', ['VM', 'VM-snapshot'], 'administrate']
} }
rollingDeltaBackup.permission = 'admin' rollingDeltaBackup.permission = 'admin'
@ -726,12 +726,12 @@ exports.importDeltaBackup = importDeltaBackup
deltaCopy = ({ vm, sr }) -> @deltaCopyVm(vm, sr) deltaCopy = ({ vm, sr }) -> @deltaCopyVm(vm, sr)
deltaCopy.params = { deltaCopy.params = {
vm: { type: 'string' }, id: { type: 'string' },
sr: { type: 'string' } sr: { type: 'string' }
} }
deltaCopy.resolve = { deltaCopy.resolve = {
vm: [ 'vm', 'VM', 'operate'], vm: [ 'id', 'VM', 'operate'],
sr: [ 'sr', 'SR', 'operate'] sr: [ 'sr', 'SR', 'operate']
} }