From c8dbd9ae7993e9e713458197e2e7ab091c1ced32 Mon Sep 17 00:00:00 2001 From: ArnauGabrielAtienza <97285545+ArnauGabrielAtienza@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:14:44 +0200 Subject: [PATCH] F OpenNebula/one#6624: Add list list-disk-snapshots (#3228) in onevm for a specific disk Signed-off-by: ArnauGabrielAtienza (cherry picked from commit 263cba67494e817ae1ee686b0589145ea64b8dc0) --- src/cli/one_helper/onevm_helper.rb | 2 ++ src/cli/onevm | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index 7ccfabfd50..dcd10bd9c8 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -1398,6 +1398,8 @@ class OneVMHelper < OpenNebulaHelper::OneHelper table.show(history) end + public + def format_snapshots(vm) table = CLIHelper::ShowTable.new(nil, self) do column :AC, 'Is active', :left, :size => 2 do |d| diff --git a/src/cli/onevm b/src/cli/onevm index 04cad32c98..1326e82b58 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -1282,6 +1282,33 @@ CommandParser::CmdParser.new(ARGV) do helper.show_resource(args[0], options) end + disk_snapshot_list_desc = <<-EOT.unindent + Lists the snapshots of a disk + EOT + + command :"disk-snapshot-list", disk_snapshot_list_desc, :vmid, :diskid do + vm = helper.retrieve_resource(args[0]) + vm.info + + filtered = [] + vm_hash = vm.to_hash + vm_snapshots = [vm_hash['VM']['SNAPSHOTS']].flatten + + vm_snapshots.each do |snap| + if snap['DISK_ID'] == args[1] + filtered << snap + end + end + + vm_hash['VM']['SNAPSHOTS'] = filtered + + if vm.has_elements?('/VM/SNAPSHOTS') + CLIHelper.print_header('VM DISK SNAPSHOTS'.ljust(80), false) + helper.format_snapshots(vm_hash) + end + 0 + end + top_desc = <<-EOT.unindent Lists Images continuously EOT