chore(xen-api): rewrite barrier and createTask
This commit is contained in:
parent
ce4bcbd19d
commit
b34688043f
@ -541,12 +541,10 @@ export class Xapi extends EventEmitter {
|
|||||||
// ensure we have received all events up to this call
|
// ensure we have received all events up to this call
|
||||||
//
|
//
|
||||||
// optionally returns the up to date object for the given ref
|
// optionally returns the up to date object for the given ref
|
||||||
barrier(ref) {
|
async barrier(ref) {
|
||||||
const eventWatchers = this._eventWatchers
|
const eventWatchers = this._eventWatchers
|
||||||
if (eventWatchers === undefined) {
|
if (eventWatchers === undefined) {
|
||||||
return Promise.reject(
|
throw new Error('Xapi#barrier() requires events watching')
|
||||||
new Error('Xapi#barrier() requires events watching')
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const key = `xo:barrier:${Math.random()
|
const key = `xo:barrier:${Math.random()
|
||||||
@ -557,48 +555,34 @@ export class Xapi extends EventEmitter {
|
|||||||
const { promise, resolve } = defer()
|
const { promise, resolve } = defer()
|
||||||
eventWatchers[key] = resolve
|
eventWatchers[key] = resolve
|
||||||
|
|
||||||
return this._sessionCall('pool.add_to_other_config', [
|
await this._sessionCall('pool.add_to_other_config', [poolRef, key, ''])
|
||||||
poolRef,
|
|
||||||
key,
|
|
||||||
'',
|
|
||||||
]).then(() =>
|
|
||||||
promise.then(() => {
|
|
||||||
this._sessionCall('pool.remove_from_other_config', [
|
|
||||||
poolRef,
|
|
||||||
key,
|
|
||||||
]).catch(noop)
|
|
||||||
|
|
||||||
if (ref === undefined) {
|
await promise
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// support legacy params (type, ref)
|
ignoreErrors.call(
|
||||||
if (arguments.length === 2) {
|
this._sessionCall('pool.remove_from_other_config', [poolRef, key])
|
||||||
ref = arguments[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.getObjectByRef(ref)
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (ref !== undefined) {
|
||||||
|
return this.getObjectByRef(ref)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a task and automatically destroy it when settled
|
// create a task and automatically destroy it when settled
|
||||||
//
|
//
|
||||||
// allowed even in read-only mode because it does not have impact on the
|
// allowed even in read-only mode because it does not have impact on the
|
||||||
// XenServer and it's necessary for getResource()
|
// XenServer and it's necessary for getResource()
|
||||||
createTask(nameLabel, nameDescription = '') {
|
async createTask(nameLabel, nameDescription = '') {
|
||||||
const promise = this._sessionCall('task.create', [
|
const taskRef = await this._sessionCall('task.create', [
|
||||||
nameLabel,
|
nameLabel,
|
||||||
nameDescription,
|
nameDescription,
|
||||||
])
|
])
|
||||||
|
|
||||||
promise.then(taskRef => {
|
const destroyTask = () =>
|
||||||
const destroy = () =>
|
ignoreErrors.call(this._sessionCall('task.destroy', [taskRef]))
|
||||||
this._sessionCall('task.destroy', [taskRef]).catch(noop)
|
this.watchTask(taskRef).then(destroyTask, destroyTask)
|
||||||
this.watchTask(taskRef).then(destroy, destroy)
|
|
||||||
})
|
|
||||||
|
|
||||||
return promise
|
return taskRef
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nice getter which returns the object for a given $id (internal to
|
// Nice getter which returns the object for a given $id (internal to
|
||||||
|
Loading…
Reference in New Issue
Block a user