fix(xen-api): allow UUIDs for ro calls

This commit is contained in:
Julien Fontanet 2018-04-09 13:56:47 +02:00
parent a7068ec166
commit 7990e45095

View File

@ -143,7 +143,9 @@ export const isOpaqueRef = value =>
const RE_READ_ONLY_METHOD = /^[^.]+\.get_/ const RE_READ_ONLY_METHOD = /^[^.]+\.get_/
const isReadOnlyCall = (method, args) => const isReadOnlyCall = (method, args) =>
args.length === 1 && isOpaqueRef(args[0]) && RE_READ_ONLY_METHOD.test(method) args.length === 1 &&
typeof args[0] === 'string' &&
RE_READ_ONLY_METHOD.test(method)
// Prepare values before passing them to the XenAPI: // Prepare values before passing them to the XenAPI:
// //
@ -407,15 +409,15 @@ export class Xapi extends EventEmitter {
return this._readOnly && !isReadOnlyCall(method, args) return this._readOnly && !isReadOnlyCall(method, args)
? Promise.reject(new Error(`cannot call ${method}() in read only mode`)) ? Promise.reject(new Error(`cannot call ${method}() in read only mode`))
: this._sessionCall(`Async.${method}`, args).then(taskRef => { : this._sessionCall(`Async.${method}`, args).then(taskRef => {
$cancelToken.promise.then(() => { $cancelToken.promise.then(() => {
// TODO: do not trigger if the task is already over // TODO: do not trigger if the task is already over
this._sessionCall('task.cancel', [taskRef]).catch(noop) this._sessionCall('task.cancel', [taskRef]).catch(noop)
}) })
return this.watchTask(taskRef)::lastly(() => { return this.watchTask(taskRef)::lastly(() => {
this._sessionCall('task.destroy', [taskRef]).catch(noop) this._sessionCall('task.destroy', [taskRef]).catch(noop)
})
}) })
})
} }
// create a task and automatically destroy it when settled // create a task and automatically destroy it when settled
@ -577,31 +579,31 @@ export class Xapi extends EventEmitter {
// redirection before consuming body // redirection before consuming body
const promise = isStream const promise = isStream
? doRequest({ ? doRequest({
body: '', body: '',
// omit task_id because this request will fail on purpose // omit task_id because this request will fail on purpose
query: 'task_id' in query ? omit(query, 'task_id') : query, query: 'task_id' in query ? omit(query, 'task_id') : query,
maxRedirects: 0, maxRedirects: 0,
}).then( }).then(
response => { response => {
response.req.abort()
return doRequest()
},
error => {
let response
if (error != null && (response = error.response) != null) {
response.req.abort() response.req.abort()
return doRequest()
},
error => {
let response
if (error != null && (response = error.response) != null) {
response.req.abort()
const { headers: { location }, statusCode } = response const { headers: { location }, statusCode } = response
if (statusCode === 302 && location !== undefined) { if (statusCode === 302 && location !== undefined) {
return doRequest(location) return doRequest(location)
}
} }
}
throw error throw error
} }
) )
: doRequest() : doRequest()
return promise.then(response => { return promise.then(response => {