B #5689: allow import wilds with same moref (#1747)

Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
Carlos J. HerreraandTino Vázquez authored and GitHub committed 2022-02-11 12:41:49 +01:00
1 parent 914874baae
commit 1fc5b5afe6
5 files changed
+15 -2

No files matched your search

@@ -712,7 +712,7 @@ module VCenterDriver
# Only take care of VMs, not templates
if !hashed_properties['config.template']
vms[r.obj._ref] = hashed_properties
vms[r.obj._ref + "_" + vc_uuid] = hashed_properties
vm_objects << r.obj
end
end
@@ -117,6 +117,16 @@ module VCenterDriver
return_if_error(rc, item, exit_if_fail)
end
# Since https://github.com/OpenNebula/one/issues/5689
# there two deploy_ids allowed:
# * moref, eg: vm-567
# * moref +"_" + vcenter uuid, eg:
# 2499952a-6c85-480e-b7df-4cbd2137eb69_vm-456
# This function will always return the moref
def self.get_deploy_id(deploy_id)
return deploy_id.split("_")[0]
end
def self.find_by_name(the_class, name, pool = nil, raise_if_fail = true)
pool = one_pool(the_class, raise_if_fail) if pool.nil?
@@ -103,6 +103,7 @@ end
def initialize(vi_client, ref, one_id)
if ref
ref = VCenterDriver::VIHelper.get_deploy_id(ref)
@item = RbVmomi::VIM::VirtualMachine.new(vi_client.vim, ref)
check_item(@item, RbVmomi::VIM::VirtualMachine)
end
@@ -46,6 +46,7 @@ module VCenterDriver
vm_ref = selected['DEPLOY_ID'] || selected[:wild]['DEPLOY_ID']
vm = selected[:one_item] || build
template = selected[:template] || import_tmplt
template = "DEPLOY_ID = #{vm_ref}\n" + template
host_id = selected[:host] || @list.keys[0]
vc_uuid = @vi_client.vim.serviceContent.about.instanceUuid
+2 -1
View File
@@ -75,6 +75,7 @@ deploy[:boot] = drv_action['TEMPLATE/OS/BOOT'] \
begin
retries ||= 0
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
vc_uuid = vi_client.vim.serviceContent.about.instanceUuid
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
if !drv_action.retrieve_xmlelements('USER_TEMPLATE/VCENTER_TAG').empty? &&
@@ -132,7 +133,7 @@ begin
vm.poweron(set_running)
end
puts vm['_ref']
puts vm['_ref'] + "_" + vc_uuid
rescue StandardError => e
message = "Deploy of VM #{vm_id} on vCenter cluster #{cluster_name} " \
"with #{dfile} failed due to \"#{e.message}\"" \