From e8b2c72592b00ce30469b79599f6aa90556da238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 5 Jul 2013 17:11:46 +0200 Subject: [PATCH] Bug #2098: Do not delete VMs that cannot be monitored --- flow/client/bin/appflow | 82 ++++++++++++++----- flow/models/Role.rb | 4 +- .../public/js/apptools-appflow-services.js | 26 ++++-- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/flow/client/bin/appflow b/flow/client/bin/appflow index e04e5676fd..92330ce81b 100755 --- a/flow/client/bin/appflow +++ b/flow/client/bin/appflow @@ -78,60 +78,98 @@ NODE_TABLE = CLIHelper::ShowTable.new(nil, self) do st << "\u2193 " end - st << d['vm_info']['VM']["ID"] + if d['vm_info'].nil? + st << d['deploy_id'].to_s + else + st << d['vm_info']['VM']["ID"] + end + + st end column :NAME, "Name of the Virtual Machine", :left, :size=>23 do |d| - if d['vm_info']['VM']["RESCHED"] == "1" - "*#{d["NAME"]}" + if !d['vm_info'].nil? + if d['vm_info']['VM']["RESCHED"] == "1" + "*#{d["NAME"]}" + else + d['vm_info']['VM']["NAME"] + end else - d['vm_info']['VM']["NAME"] + "" end end column :USER, "Username of the Virtual Machine owner", :left, :size=>8 do |d| - d['vm_info']['VM']["UNAME"] + if !d['vm_info'].nil? + d['vm_info']['VM']["UNAME"] + else + "" + end end column :GROUP, "Group of the Virtual Machine", :left, :size=>8 do |d| - d['vm_info']['VM']["GNAME"] + if !d['vm_info'].nil? + d['vm_info']['VM']["GNAME"] + else + "" + end end column :STAT, "Actual status", :size=>4 do |d,e| - OneVMHelper.state_to_str(d['vm_info']['VM']["STATE"], d['vm_info']['VM']["LCM_STATE"]) + if !d['vm_info'].nil? + OneVMHelper.state_to_str(d['vm_info']['VM']["STATE"], d['vm_info']['VM']["LCM_STATE"]) + else + "" + end end column :UCPU, "CPU percentage used by the VM", :size=>4 do |d| - d['vm_info']['VM']["CPU"] + if !d['vm_info'].nil? + d['vm_info']['VM']["CPU"] + else + "" + end end column :UMEM, "Memory used by the VM", :size=>7 do |d| - OpenNebulaHelper.unit_to_str(d['vm_info']['VM']["MEMORY"].to_i, {}) + if !d['vm_info'].nil? + OpenNebulaHelper.unit_to_str(d['vm_info']['VM']["MEMORY"].to_i, {}) + else + "" + end end column :HOST, "Host where the VM is running", :left, :size=>20 do |d| - if d['vm_info']['VM']['HISTORY_RECORDS'] && d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'] - state_str = VirtualMachine::VM_STATE[d['vm_info']['VM']['STATE'].to_i] - if %w{ACTIVE SUSPENDED}.include? state_str - history = if d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].instance_of?(Array) - d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].last - else - d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'] - end + if !d['vm_info'].nil? + if d['vm_info']['VM']['HISTORY_RECORDS'] && d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'] + state_str = VirtualMachine::VM_STATE[d['vm_info']['VM']['STATE'].to_i] + if %w{ACTIVE SUSPENDED}.include? state_str + history = if d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].instance_of?(Array) + d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'].last + else + d['vm_info']['VM']['HISTORY_RECORDS']['HISTORY'] + end - history['HOSTNAME'] + history['HOSTNAME'] + end end + else + "" end end column :TIME, "Time since the VM was submitted", :size=>10 do |d| - stime = d['vm_info']['VM']["STIME"].to_i - etime = d['vm_info']['VM']["ETIME"]=="0" ? Time.now.to_i : d['vm_info']['VM']["ETIME"].to_i - dtime = etime-stime - OpenNebulaHelper.period_to_str(dtime, false) + if !d['vm_info'].nil? + stime = d['vm_info']['VM']["STIME"].to_i + etime = d['vm_info']['VM']["ETIME"]=="0" ? Time.now.to_i : d['vm_info']['VM']["ETIME"].to_i + dtime = etime-stime + OpenNebulaHelper.period_to_str(dtime, false) + else + "" + end end default :VM_ID, :NAME, :STAT, :UCPU, :UMEM, :HOST, :TIME diff --git a/flow/models/Role.rb b/flow/models/Role.rb index 6aca052194..c87f75bc3e 100644 --- a/flow/models/Role.rb +++ b/flow/models/Role.rb @@ -197,6 +197,8 @@ module OpenNebula success = false node['vm_info'] = nil + + new_nodes << node else node['vm_info'] = vm.to_hash @@ -256,8 +258,6 @@ module OpenNebula 'deploy_id' => vm_id, } - # vm.info is not performed, this creates an empty VM xml - # containing only the ID vm = OpenNebula::VirtualMachine.new_with_id(vm_id, @service.client) rc = vm.info if OpenNebula.is_error?(rc) diff --git a/flow/sunstone/public/js/apptools-appflow-services.js b/flow/sunstone/public/js/apptools-appflow-services.js index 910e8bca4e..3c54f8b5e0 100644 --- a/flow/sunstone/public/js/apptools-appflow-services.js +++ b/flow/sunstone/public/js/apptools-appflow-services.js @@ -1610,17 +1610,25 @@ function updateServiceInfo(request,elem){ if (role.nodes) { $.each(role.nodes, function(){ var vm_info = this.vm_info; - if (vm_info) { - var info = []; - if (this.scale_up) { - info.push(""); - } else if (this.disposed) { - info.push(""); - } else { - info.push(""); - } + var info = []; + if (this.scale_up) { + info.push(""); + } else if (this.disposed) { + info.push(""); + } else { + info.push(""); + } + + if (vm_info) { vms.push(info.concat(vMachineElementArray(vm_info))); + } else { + empty_arr = [ + '', + this.deploy_id, + '', '', '', '', '', '', '', '', '', '' ]; + + vms.push(info.concat(empty_arr)); } });