From 26aaf5f53caaf929c6414d4acde55dc4df5cb181 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Mon, 9 Dec 2013 18:19:55 +0100 Subject: [PATCH] Various fixes. --- src/MappedCollection.coffee | 4 ++-- src/xo.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/MappedCollection.coffee b/src/MappedCollection.coffee index 96b988f28..331d3a536 100644 --- a/src/MappedCollection.coffee +++ b/src/MappedCollection.coffee @@ -283,7 +283,7 @@ class MappedCollection getAll: -> items = {} - for ruleName, ruleItems in @_byRule + for ruleName, ruleItems of @_byRule rule = @_rules[ruleName] # Items of private rules are not exported. @@ -317,7 +317,7 @@ class MappedCollection $_.extend(itemsToRemove, @_byKey) $_.each items, (value, key) => - key = @_key key + key = @_key value, key # If the item already existed. if @_byKey[key] diff --git a/src/xo.js b/src/xo.js index 8c973811a..83d6de971 100644 --- a/src/xo.js +++ b/src/xo.js @@ -227,7 +227,12 @@ Xo.prototype.start = function (data) { // 'VMPP', // 'VTPM', ]; - xo.xobjs = createMappedCollection(require('./spec')); + + // XAPI uses both opaque references and UUIDs, XO uses UUIDs where + // possible. + var refsToUUIDs = {}; + + xo.xobjs = createMappedCollection(require('./spec')(refsToUUIDs)); var connect = function (server) { var pool_id = server.id; @@ -241,9 +246,14 @@ Xo.prototype.start = function (data) { return Q.all(_.map(xclasses, function (xclass) { return xapi.call(xclass +'.get_all_records') .then(function (records) { - _.each(records, function (record) { + _.each(records, function (record, ref) { record.$type = xclass; record.$pool = pool_id; + + if (record.uuid) + { + refsToUUIDs[ref] = record.uuid; + } }); return xobjs.set(records); @@ -271,6 +281,11 @@ Xo.prototype.start = function (data) { } else { + if (record.uuid) + { + refsToUUIDs[ref] = record.uuid; + } + xobjs.set({ref: record}, {remove: false}); } });