1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B #5409: avoid clone disk if there are snapshots (#1822)

(cherry picked from commit 73ffded36cfd60db57dc51bcee5f00e0e39520ae)
This commit is contained in:
Alejandro Huertas Herrero 2022-03-01 17:04:20 +01:00 committed by Tino Vazquez
parent 4874a971ba
commit 5fd0f9a59a
No known key found for this signature in database
GPG Key ID: 14201E424D02047E
3 changed files with 27 additions and 9 deletions

View File

@ -104,7 +104,8 @@ target_path_escaped = VCenterDriver::FileHelper
target_path = VCenterDriver::FileHelper.unescape_path(target_path_escaped)
begin
retries ||= 0
op_retry = true
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
disk_xpath ="TEMPLATE/DISK[SOURCE=\"#{src_path_escaped}\"]"
one_disk = one_vm.retrieve_xmlelements(disk_xpath) rescue nil
@ -113,6 +114,18 @@ begin
raise 'Cannot find disk element in vm template' unless one_disk
vm = VCenterDriver::VirtualMachine.new(vi_client, nil, vm_id)
if vm.snapshots? || vm.one_snapshots?
# If there are snapshots we shouldn't retry
op_retry = false
raise 'Existing sytem snapshots, cannot change disks. ' \
'Please remove all snapshots and try again.'
end
retries ||= 0
disk = VCenterDriver::VirtualMachine::Disk.one_disk(disk_id, one_disk)
new_size = disk.new_size
@ -121,7 +134,6 @@ begin
if !(!disk.managed? || (is_storage_drs && disk.volatile?))
if is_storage_drs
vm = VCenterDriver::VirtualMachine.new(vi_client, nil, vm_id)
# Get a single DS using StoragePod recommendation
# We overwrite the reference in target_ds_ref from the StoragePod
# to the single recommended DS
@ -146,14 +158,20 @@ begin
rescue StandardError => e
message = "Error clone virtual disk #{src_path} in "\
"datastore #{target_ds_name_vc}. "\
"Reason: #{e.message}."
"Reason: #{e.message}." \
"on attempt \##{retries}."
if op_retry && (retries += 1) > CONFIG[:retries]
message << "\nPlease check vCenter logs directly\n"
end
OpenNebula.log_error(message)
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"
end
sleep 60
retry if retries < CONFIG[:retries]
sleep 60 if op_retry
retry if op_retry && retries < CONFIG[:retries]
exit(-1)
ensure

View File

@ -102,7 +102,7 @@ begin
is_disk = path.match(/disk\.\d+$/)
if is_disk
dsid = img_path.split('/')[-3] # get dsid from path
@error_message = "error deleting disk with #{img_path} "\
@error_message = "Error deleting disk with #{img_path} "\
"in datastore #{dsid}"
# Get disk info, destroy it if possible
@ -122,7 +122,7 @@ begin
end
rescue StandardError => e
vi_client.close_connection if vi_client
message = "#{@error_message}. Reason: #{e.message}."
message = "#{@error_message} Reason: #{e.message}."
OpenNebula.log_error(message)
if VCenterDriver::CONFIG[:debug_information]
STDERR.puts "#{message} #{e.backtrace}"

View File

@ -2438,7 +2438,7 @@ end
# https://github.com/OpenNebula/one/issues/5409
if snapshots? || one_snapshots?
error_msg = 'Existing sytem snapshots, cannot change disks. '
error_msg << 'Please remove all snapshots and try again.'
error_msg << 'Please remove all snapshots and try again'
raise error_msg
end
@ -2625,7 +2625,7 @@ end
if snapshots? || one_snapshots?
error_message = 'Existing sytem snapshots, cannot change disks'
error_message << '. Please remove all snapshots and try again.'
error_message << '. Please remove all snapshots and try again'
raise error_message
end