From 8978f56c90c7da1ffdd2092ab6e076fb3ade26a9 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 3 Jun 2015 14:36:59 +0200 Subject: [PATCH] feature #3782: Display snapshots in oneimage show --- src/cli/one_helper/oneimage_helper.rb | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 068a417a85..72799b8d50 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -292,6 +292,13 @@ class OneImageHelper < OpenNebulaHelper::OneHelper puts str % [e, mask] } + + if image.has_elements?("/IMAGE/SNAPSHOTS") + puts + CLIHelper.print_header(str_h1 % "IMAGE SNAPSHOTS",false) + format_snapshots(image) + end + puts CLIHelper.print_header(str_h1 % "IMAGE TEMPLATE",false) @@ -311,6 +318,44 @@ class OneImageHelper < OpenNebulaHelper::OneHelper end end + def format_snapshots(image) + table=CLIHelper::ShowTable.new(nil, self) do + column :AC , "Is active", :left, :size => 2 do |d| + if d["ACTIVE"] == "YES" + "=>" + else + "" + end + end + column :ID, "Snapshot ID", :size=>3 do |d| + d["ID"] + end + + column :PARENT, "Snapshot Parent ID", :size=>6 do |d| + d["PARENT"] + end + + column :CHILDREN, "Snapshot Children IDs", :size=>10 do |d| + d["CHILDREN"] + end + + column :TAG, "Snapshot Tag", :left, :size=>45 do |d| + d["TAG"] + end + + column :DATE, "Snapshot creation date", :size=>15 do |d| + OpenNebulaHelper.time_to_str(d["DATE"]) + end + + default :AC, :ID, :PARENT, :DATE, :CHILDREN, :TAG + end + + # Convert snapshot data to an array + image_hash = image.to_hash + image_snapshots = [image_hash['IMAGE']['SNAPSHOTS']].flatten.first + table.show(image_snapshots) + end + def self.create_image_variables(options, name) if Array===name names=name