From fb8ab370d16ec6724829ef844df8becdcb4dfed1 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 7 Jul 2011 18:34:41 +0200 Subject: [PATCH] added history printing to onevm show --- src/cli/one_helper/onevm_helper.rb | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 3a1e3fcf2f..9da8c5a99e 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -92,6 +92,13 @@ class OneVMHelper < OpenNebulaHelper::OneHelper CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false) puts vm.template_str + + if vm['/VM/HISTORY_RECORDS/HISTORY'] + puts + + CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE HISTORY",false) + format_history(vm) + end end def format_pool(pool, options, top=false) @@ -147,4 +154,53 @@ class OneVMHelper < OpenNebulaHelper::OneHelper table.show(pool, options) end end + + def format_history(vm) + table=CLIHelper::ShowTable.new(nil, self) do + column :SEQ, "Sequence number", :size=>4 do |d| + d["SEQ"] + end + + column :HOSTNAME, "Host name", :size=>15 do |d| + d["HOSTNAME"] + end + + column :REASON, "VM state change reason", :size=>6 do |d| + VirtualMachine.get_reason d["REASON"] + end + + column :START, "Time when the state changed", :size=>15 do |d| + OpenNebulaHelper.time_to_str(d['STIME']) + end + + column :TIME, "Total time in this state", :size=>11 do |d| + stime = Time.at(d["STIME"].to_i) + etime = d["ETIME"]=="0" ? Time.now : Time.at(d["ETIME"].to_i) + dtime = Time.at(etime-stime).getgm + "%02d %02d:%02d:%02d" % [dtime.yday-1, dtime.hour, + dtime.min, dtime.sec] + end + + column :PTIME, "Prolog time for this state", :size=>11 do |d| + stime = Time.at(d["PSTIME"].to_i) + if d["PSTIME"]=="0" + etime=Time.at(0) + else + etime = d["PETIME"]=="0" ? Time.now : + Time.at(d["PETIME"].to_i) + end + dtime = Time.at(etime-stime).getgm + "%02d %02d:%02d:%02d" % [dtime.yday-1, dtime.hour, + dtime.min, dtime.sec] + end + + default :SEQ, :HOSTNAME, :REASON, :START, :TIME, :PTIME + end + + vm_hash=vm.to_hash + + history=vm_hash['VM']['HISTORY_RECORDS']['HISTORY'] + + table.show(history) + end end \ No newline at end of file