From a224d863736e28d811f6f8d0c8a765035211412b Mon Sep 17 00:00:00 2001 From: Angel Luis Moya Gonzalez Date: Thu, 7 May 2020 15:02:10 +0200 Subject: [PATCH] F #4302: Fix error when return is empty (#4675) * Change get id way * Fix error when return is empty Co-authored-by: mouyaq --- src/im_mad/remotes/lib/vcenter.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/im_mad/remotes/lib/vcenter.rb b/src/im_mad/remotes/lib/vcenter.rb index f852fa9571..5787ab6912 100644 --- a/src/im_mad/remotes/lib/vcenter.rb +++ b/src/im_mad/remotes/lib/vcenter.rb @@ -949,21 +949,16 @@ class VcenterMonitor view.DestroyView # Destroy the view # # Get one vms from database - # one_vms = @db.select_one_vms + one_vms = @db.select_one_vms vms = [] vms_hash.each do |vm_ref, info| next if info['name'].match(/^one-(\d*)(-(.*))?$/) one_uuid = "#{vm_ref}#{@vc_uuid}" - vm = VCenterDriver::VirtualMachine.new_from_ref(@vi_client, - vm_ref, - info['name'], - opts) - one_id = vm.vm_id vm = { :uuid => one_uuid, - :id => one_id, + :id => one_id(one_uuid, one_vms), :name => "#{info['name']} - #{@cluster.item.name}", :deploy_id => vm_ref, :state => vm_state(info['summary.runtime.powerState']), @@ -1174,7 +1169,7 @@ class InstanceCache raise "There is more than one CCR_REF for host_id = #{host_id}" \ if result.length > 1 - result[0][0] + result.empty? ? nil : result[0][0] end def select_one_vms