From cff2bb697bed03482e42fbab06c3b52583f4e299 Mon Sep 17 00:00:00 2001 From: Guillemo Ramos Date: Mon, 20 May 2024 11:11:56 +0200 Subject: [PATCH] F #6053: Fix Ceph restore (#3065) Fix wrong handling of the two datastores involved (backup+ceph) Signed-off-by: Guillermo Ramos --- src/tm_mad/ceph/restore | 15 ++++++++++----- src/tm_mad/lib/datastore.rb | 10 ++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/tm_mad/ceph/restore b/src/tm_mad/ceph/restore index 78d9e506bd..487ba90130 100755 --- a/src/tm_mad/ceph/restore +++ b/src/tm_mad/ceph/restore @@ -77,11 +77,11 @@ begin bk_img = OpenNebula::Image.new_with_id(bk_img_id, action.one) rc = bk_img.info - raise rc.message.to_s if OpenNebula.is_error?(rc) - ds = TransferManager::Datastore.from_image_ds(:image => bk_img, - :client => action.one) + bk_ds = TransferManager::Datastore.from_image_ds(:image => bk_img, + :client => action.one) + # -------------------------------------------------------------------------- # Backup information # sample output: {"0":"rsync://100//0:3ffce7/var/lib/one/datastores/100/1/3ffce7/disk.0.0"} @@ -91,7 +91,7 @@ begin #{bk_img.to_xml} EOS - rc = ds.action("ls -i #{inc_id}", xml_data) + rc = bk_ds.action("ls -i #{inc_id}", xml_data) raise 'cannot list backup contents' unless rc.code == 0 @@ -110,8 +110,13 @@ begin ceph_disk = ceph_disks[id.to_i] randsuffix = SecureRandom.hex(5) + ceph_one_ds = OpenNebula::Datastore.new_with_id( + action.vm["/VM/TEMPLATE/DISK[DISK_ID = #{id}]/DATASTORE_ID"].to_i, action.one + ) + ceph_ds = TransferManager::Datastore.new(:ds => ceph_one_ds, :client => action.one) + info[ceph_disk] = { - :br => ds.pick_bridge, + :br => ceph_ds.pick_bridge, :bak => "#{ceph_disk.rbd_image}.backup.#{randsuffix}", :old => "#{ceph_disk.rbd_image}.old.#{randsuffix}" } diff --git a/src/tm_mad/lib/datastore.rb b/src/tm_mad/lib/datastore.rb index 2c39b71a1f..f349678023 100644 --- a/src/tm_mad/lib/datastore.rb +++ b/src/tm_mad/lib/datastore.rb @@ -76,6 +76,11 @@ module TransferManager @one ||= OpenNebula::Client.new @ds = @options[:ds] + if @ds && @ds['NAME'].nil? + rc = @ds.info(true) + raise rc.message.to_s if OpenNebula.is_error?(rc) + end + @rridx = 0 @mad = self['DS_MAD', ''].upcase @@ -98,7 +103,6 @@ module TransferManager options[:ds] = OpenNebula::Datastore.new_with_id(did, options[:client]) rc = options[:ds].info(true) - raise rc.message.to_s if OpenNebula.is_error?(rc) new(options) @@ -116,7 +120,6 @@ module TransferManager options[:ds] = OpenNebula::Datastore.new_with_id(did, options[:client]) rc = options[:ds].info(true) - raise rc.message.to_s if OpenNebula.is_error?(rc) new(options) @@ -133,6 +136,9 @@ module TransferManager xml = OpenNebula::XMLElement.build_xml(options[:ds_xml], 'DATASTORE') options[:ds] = OpenNebula::Datastore.new(xml, options[:client]) + rc = options[:ds].info(true) + raise rc.message.to_s if OpenNebula.is_error?(rc) + new(options) end