From 86897af299cb3011460463deac7bc0f55dfee636 Mon Sep 17 00:00:00 2001 From: Tino Vazquez Date: Mon, 19 Feb 2018 11:34:53 +0100 Subject: [PATCH] B #1759: Change vCenter cache index Now uses moref + vCenter instance uuid (cherry picked from commit 06443130a230f93e2842e6934097df76d561e474) --- .../remotes/lib/vcenter_driver/vi_helper.rb | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb b/src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb index 9d512c267d..8fc77d253f 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/vi_helper.rb @@ -73,15 +73,28 @@ class VIHelper end end - def self.create_ref_hash(attribute, pool, vcenter_uuid) + def self.get_ref_key(element, attribute) + key = element[attribute] + + tvid = element["TEMPLATE/VCENTER_INSTANCE_ID"] + uvid = element["USER_TEMPLATE/VCENTER_INSTANCE_ID"] + + if tvid + key += tvid + elsif uvid + key += uvid + end + + return key + end + + def self.create_ref_hash(attribute, pool) hash = {} pool.each_element(Proc.new do |e| - vcenter_instance_id = e["TEMPLATE/VCENTER_INSTANCE_ID"] || e["USER_TEMPLATE/VCENTER_INSTANCE_ID"] - next if vcenter_uuid != vcenter_instance_id + refkey = get_ref_key(e, attribute) - ref = e[attribute] - hash[ref] = { + hash[refkey] = { opennebula_object: e, opennebula_managed: e["TEMPLATE/OPENNEBULA_MANAGED"], tvcenter_instance_id: e["TEMPLATE/VCENTER_INSTANCE_ID"], @@ -106,10 +119,14 @@ class VIHelper @ref_hash ||= {} if @ref_hash[attribute].nil? || @ref_hash[attribute] == {} - @ref_hash[attribute] = create_ref_hash(attribute, pool, vcenter_uuid) + @ref_hash[attribute] = create_ref_hash(attribute, pool) end - e = @ref_hash[attribute][ref] + refkey = "" + refkey = ref if ref + refkey += vcenter_uuid if vcenter_uuid + + e = @ref_hash[attribute][refkey] return nil if e.nil?