From d7af2a9a86236ed1983f16feb315fff5ed229d8e Mon Sep 17 00:00:00 2001 From: Angel Luis Moya Gonzalez Date: Tue, 12 May 2020 15:17:49 +0200 Subject: [PATCH] F #4302: Change wild detecion method and fix resource pool names (#4708) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Change Wilds detection to old method * Fix error detecting resource pool name * Re-dded disk info to vm monitoring Co-authored-by: mouyaq Co-authored-by: Tino Vázquez --- src/im_mad/remotes/lib/vcenter.rb | 9 ++++++--- .../remotes/vcenter-probes.d/host/system/vcenter.rb | 2 +- .../remotes/vcenter-probes.d/vms/monitor/monitor.rb | 5 +---- src/vmm_mad/remotes/lib/vcenter_driver/host.rb | 10 ++++++++-- .../virtual_machine_monitor/vm_monitor.rb | 12 ++++-------- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/im_mad/remotes/lib/vcenter.rb b/src/im_mad/remotes/lib/vcenter.rb index 0c8a821f9f..7f15e4c3e1 100644 --- a/src/im_mad/remotes/lib/vcenter.rb +++ b/src/im_mad/remotes/lib/vcenter.rb @@ -243,7 +243,7 @@ class VcenterMonitor mem_shares_level = info['config.memoryAllocation.shares.level'] mem_shares = info['config.memoryAllocation.shares.shares'] - rp_name = rp_list.select {|item| item[:ref] == ref }.first[:name] \ + rp_name = @rp_list.select {|item| item[:ref] == ref }.first[:name] \ rescue '' rp_name = 'Resources' if rp_name.empty? @@ -1044,8 +1044,11 @@ class VcenterMonitor one_vms end - def monitor_vms - str_info, last_mon_time = @cluster.monitor_vms(@host_id) + # Return string info for different vm types: + # 'wilds' : VMs in vCenter but not in OpenNebula + # 'ones' : VMs in OpenNebula + def monitor_vms(vm_type) + str_info, last_mon_time = @cluster.monitor_vms(@host_id, vm_type) return str_info end diff --git a/src/im_mad/remotes/vcenter-probes.d/host/system/vcenter.rb b/src/im_mad/remotes/vcenter-probes.d/host/system/vcenter.rb index ce47d353d7..7a0e4356f6 100755 --- a/src/im_mad/remotes/vcenter-probes.d/host/system/vcenter.rb +++ b/src/im_mad/remotes/vcenter-probes.d/host/system/vcenter.rb @@ -59,7 +59,7 @@ begin vcm.retrieve_vms_data # VM wilds info - puts vcm.wilds + puts vcm.monitor_vms('wilds') # Datastore Monitoring puts vcm.monitor_datastores diff --git a/src/im_mad/remotes/vcenter-probes.d/vms/monitor/monitor.rb b/src/im_mad/remotes/vcenter-probes.d/vms/monitor/monitor.rb index 0ba71bd6ec..2d7e15c143 100755 --- a/src/im_mad/remotes/vcenter-probes.d/vms/monitor/monitor.rb +++ b/src/im_mad/remotes/vcenter-probes.d/vms/monitor/monitor.rb @@ -39,10 +39,7 @@ host = ARGV[-1] host_id = ARGV[-2] vcm = VcenterMonitor.new(host, host_id) begin - # Fetch VMs info ( update cache if neccesary ) - # vcm.retrieve_vms_data - # puts vcm.probe_vm_monitor - puts vcm.monitor_vms + puts vcm.monitor_vms('ones') rescue StandardError => e OpenNebula.handle_driver_exception('im probe_vm_monitor', e, host) end \ No newline at end of file diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/host.rb b/src/vmm_mad/remotes/lib/vcenter_driver/host.rb index 6bd4938116..246fdec54f 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/host.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/host.rb @@ -502,7 +502,7 @@ class ClusterComputeResource return host_info end - def monitor_vms(host_id) + def monitor_vms(host_id, vm_type) vc_uuid = @vi_client.vim.serviceContent.about.instanceUuid cluster_name = self["name"] cluster_ref = self["_ref"] @@ -660,7 +660,13 @@ class ClusterComputeResource vm = VCenterDriver::VirtualMachine.new_from_ref(@vi_client, vm_ref, info["name"], opts) id = vm.vm_id - next if id == -1 + if vm_type == 'ones' + next if id == -1 + elsif vm_type == 'wilds' + next if id != -1 + else + next + end #skip if it's already monitored if vm.one_exist? diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_monitor/vm_monitor.rb b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_monitor/vm_monitor.rb index f8edfde694..9505bd6fa1 100644 --- a/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_monitor/vm_monitor.rb +++ b/src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_monitor/vm_monitor.rb @@ -422,10 +422,6 @@ module VirtualMachineMonitor end if @vm_info - # rp_name = @vm_info[:rp_list] - # .select {|item| - # item[:ref] == @vm_info['resourcePool']._ref - # }.first[:name] rescue '' rp_name = @vm_info[:rp_list] .select do |item| item[:ref] == @vm_info['resourcePool']._ref @@ -467,10 +463,10 @@ module VirtualMachineMonitor << vmtools_verst << "\n" str_info << 'VCENTER_RP_NAME="' << rp_name << '" ' << "\n" - # @vm.info_disks.each do |disk| - # str_info << "DISK_#{disk[0]}_ACTUAL_PATH=\"[" << - # disk[1].ds.name << '] ' << disk[1].path << '" ' - # end + info_disks.each do |disk| + str_info << "DISK_#{disk[0]}_ACTUAL_PATH=\"[" << + disk[1].ds.name << '] ' << disk[1].path << '" ' + end str_info end