Xapi#getObject()

This commit is contained in:
Julien Fontanet 2015-05-06 14:06:17 +02:00
parent 5838c56c4e
commit 9222733243

View File

@ -212,6 +212,23 @@ export class Xapi extends EventEmitter {
return this._sessionCall(method, args)
}
// Nice getter which returns the object for a given $id (internal to
// this lib), UUID (unique identifier that some objects have) or
// opaque reference (internal to XAPI).
getObject (idOrUuidOrRef, defaultValue) {
const object = (
// if there is an UUID, it is also the $id.
this.objects.all[idOrUuidOrRef] ||
this._objectsByRefs[idOrUuidOrRef]
)
if (object) return object
if (arguments.length > 1) return defaultValue
throw new Error('there is not object can be matched to ' + idOrUuidOrRef)
}
getObjectByRef (ref, defaultValue) {
const {
_objectsByRefs: objectsByRefs