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

B #1699: Do not return datastores containing only SWAP (#2887)

* B #1699: Do not return datastores containing only SWAP

* B #1699: Function, rescue block and comment

* Update vm_template.rb
This commit is contained in:
sergiojvg 2019-02-06 03:19:41 -06:00 committed by Tino Vázquez
parent 65bdfe6e12
commit 2e40c21d26

View File

@ -110,7 +110,7 @@ class Template
:name => template_name,
:spec => clone_spec).wait_for_completion
template_ref = template._ref
rescue Exception => e
rescue StandardError => e
if !e.message.start_with?('DuplicateName')
error = "Could not create the template clone. Reason: #{e.message}"
return error, nil
@ -159,7 +159,7 @@ class Template
if self['config.template']
@item.MarkAsVirtualMachine(:pool => get_rp, :host => self['runtime.host'])
end
rescue Exception => e
rescue StandardError => e
@item.MarkAsTemplate()
error = "Cannot mark the template as a VirtualMachine. Not using linked clones. Reason: #{e.message}/#{e.backtrace}"
use_linked_clones = false
@ -186,7 +186,7 @@ class Template
end
@item.ReconfigVM_Task(:spec => spec).wait_for_completion if !spec[:deviceChange].empty?
rescue Exception => e
rescue StandardError => e
error = "Cannot create the delta disks on top of the template. Reason: #{e.message}."
use_linked_clones = false
return error, use_linked_clones
@ -299,7 +299,7 @@ class Template
end
end
rescue Exception => e
rescue StandardError => e
error = "\n There was an error trying to create an image for disk in vcenter template. Reason: #{e.message}\n#{e.backtrace}"
ensure
unlock
@ -529,7 +529,7 @@ class Template
npool.info_all
end
end
rescue Exception => e
rescue StandardError => e
error = "\n There was an error trying to create a virtual network to repesent a vCenter network for a VM or VM Template. Reason: #{e.message}"
ensure
unlock
@ -826,8 +826,9 @@ class Template
if !@vm_info["datastore"].nil?
!@vm_info["datastore"].last.nil? &&
!@vm_info["datastore"].last._ref.nil?
str << "VCENTER_DS_REF = \"#{@vm_info["datastore"].last._ref}\"\n"
end
ds_ref = vm_template_ds_ref
str << "VCENTER_DS_REF = \"#{ds_ref}\"\n"
end
vnc_port = nil
keymap = VCenterDriver::VIHelper.get_default("VM/TEMPLATE/GRAPHICS/KEYMAP")
@ -879,6 +880,38 @@ class Template
return str
end
#Gets MOREF from Datastore used by the VM. It validates
#the selected DS is not only used to host swap.
def vm_template_ds_ref
begin
ds_ref = nil
if @vm_info["datastore"].length > 1
swap_path = ""
@vm_info["config.extraConfig"].each do |element|
if element.key == "sched.swap.derivedName"
swap_path = element.value
end
end
@vm_info["datastore"].each do |datastore|
path = datastore.summary.url.sub(/ds:\/\/\/*/, "")
if !swap_path.include? path && !datastore._ref.nil?
ds_ref = datastore._ref
break
end
end
else
if !@vm_info["datastore"]._ref.nil?
ds_ref = @vm_info["datastore"]._ref
end
end
return ds_ref
rescue StandardError => e
error = "Could not find DATASTORE for this VM. Reason: #{e.message}"
return error
end
end
def self.template_to_one(template, vc_uuid, ccr_ref, ccr_name, import_name, host_id)
num_cpu, memory, annotation, guest_fullname = template.item.collect("config.hardware.numCPU","config.hardware.memoryMB","config.annotation","guest.guestFullName")
@ -1021,7 +1054,7 @@ class Template
# Get the OpenNebula's template hash
one_tmp[:one] = template_to_one(template, vcenter_uuid, template_ccr_ref, template_ccr_name, import_name, host_id)
return one_tmp
rescue Exception => e
rescue StandardError => e
return nil
end
end