From 9bebffe6a63af1805cd5987a04ff6afa70e66c37 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 23 Jul 2014 15:48:40 +0200 Subject: [PATCH 1/3] feature #3087: add cluster name to onevm show --- src/cli/one_helper/onevm_helper.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index f8086ae136..f6b926a5ba 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -236,6 +236,28 @@ class OneVMHelper < OpenNebulaHelper::OneHelper str_h1="%-80s" str="%-20s: %-20s" + cluster = nil + + if %w{ACTIVE SUSPENDED POWEROFF}.include? vm.state_str + cluster_id = vm['/VM/HISTORY_RECORDS/HISTORY[last()]/CID'] + else + cluster_id = nil + end + + if cluster_id + if cluster_id == "-1" + cluster = "default" + else + clu = OpenNebula::Cluster.new(OpenNebula::Cluster.build_xml(cluster_id), @client) + rc = clu.info + if OpenNebula.is_error?(rc) + cluster = "ERROR" + else + cluster = clu["NAME"] + end + end + end + CLIHelper.print_header( str_h1 % "VIRTUAL MACHINE #{vm['ID']} INFORMATION") puts str % ["ID", vm.id.to_s] @@ -248,9 +270,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper puts str % ["HOST", vm['/VM/HISTORY_RECORDS/HISTORY[last()]/HOSTNAME']] if %w{ACTIVE SUSPENDED POWEROFF}.include? vm.state_str - puts str % ["CLUSTER ID", - vm['/VM/HISTORY_RECORDS/HISTORY[last()]/CID'] ] if - %w{ACTIVE SUSPENDED POWEROFF}.include? vm.state_str + puts str % ["CLUSTER ID", cluster_id ] if cluster_id + puts str % ["CLUSTER", cluster ] if cluster puts str % ["START TIME", OpenNebulaHelper.time_to_str(vm['/VM/STIME'])] puts str % ["END TIME", From b0bcedea5173ba5fad0ae9b06b4a9b739b68ce80 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Wed, 23 Jul 2014 16:22:46 +0200 Subject: [PATCH 2/3] feature #3087: add cluster column to onevm list disabled by default --- src/cli/etc/onevm.yaml | 5 +++++ src/cli/one_helper/onevm_helper.rb | 33 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/cli/etc/onevm.yaml b/src/cli/etc/onevm.yaml index bcc26c199f..348a1696d3 100644 --- a/src/cli/etc/onevm.yaml +++ b/src/cli/etc/onevm.yaml @@ -35,6 +35,11 @@ :size: 10 :left: true +:CLUSTER: + :desc: Cluster where the VM is running + :size: 10 + :left: true + :TIME: :desc: Time since the VM was submitted :size: 10 diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index f6b926a5ba..2574f909db 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -126,6 +126,22 @@ class OneVMHelper < OpenNebulaHelper::OneHelper def format_pool(options) config_file = self.class.table_conf + # Get cluster names to use later in list + cluster_pool = OpenNebula::ClusterPool.new(@client) + rc = cluster_pool.info + + cluster_names = {} + cluster_names["-1"] = "default" + + if !OpenNebula.is_error?(rc) + hash = cluster_pool.to_hash + clusters = [hash["CLUSTER_POOL"]["CLUSTER"]].flatten + + clusters.each do |cluster| + cluster_names[cluster["ID"]] = cluster["NAME"] + end + end + table = CLIHelper::ShowTable.new(config_file, self) do column :ID, "ONE identifier for Virtual Machine", :size=>6 do |d| d["ID"] @@ -171,6 +187,23 @@ class OneVMHelper < OpenNebulaHelper::OneHelper end end + column :CLUSTER, "Cluster where the VM is running", :left, + :size=> 10 do |d| + if d["HISTORY_RECORDS"]["HISTORY"] + history = [d["HISTORY_RECORDS"]["HISTORY"]].flatten + cluster_id = history.last["CID"] + cluster = cluster_names[cluster_id] + + if !cluster + cluster_id + else + cluster + end + else + "NONE" + end + end + column :TIME, "Time since the VM was submitted", :size=>10 do |d| stime = d["STIME"].to_i etime = d["ETIME"]=="0" ? Time.now.to_i : d["ETIME"].to_i From e6e88e154d8838260e8ab4afe15932ebe42f168c Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 24 Jul 2014 22:43:06 +0200 Subject: [PATCH 3/3] feature #3087. build cluster name arrey with each --- src/cli/one_helper/onevm_helper.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 2574f909db..9c6ad497d7 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -134,11 +134,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper cluster_names["-1"] = "default" if !OpenNebula.is_error?(rc) - hash = cluster_pool.to_hash - clusters = [hash["CLUSTER_POOL"]["CLUSTER"]].flatten - - clusters.each do |cluster| - cluster_names[cluster["ID"]] = cluster["NAME"] + cluster_pool.each do |c| + cluster_names[c["ID"]] = c["NAME"] end end