F #4913: Add reference in VM USER_TEMPLATE for unmanaged disks

This commit is contained in:
mcabrerizo committed 2017-03-18 10:14:23 +01:00
1 parent 8f6485058b
commit 15480d9ad7
2 files changed
+24 -3

No files matched your search

@@ -412,6 +412,22 @@ class VirtualMachine
clone_parameters
end
def reference_imported_disks
# Add info for existing disks in template in vm xml
xpath = "TEMPLATE/DISK[OPENNEBULA_MANAGED=\"NO\"]"
non_managed_disks = one_item.retrieve_xmlelements(xpath)
return if non_managed_disks.empty?
# Update VM's one_item so it can use the recent attributes
vcenter_disks = get_vcenter_disks
vcenter_disks.each_with_index do |disk, index|
rc = one_item.update("VCENTER_TEMPLATE_DISK_#{non_managed_disks[index]["DISK_ID"]} = \"#{disk[:path]}\"", true)
raise "Could not update VCENTER_TEMPLATE_DISK elements" if OpenNebula.is_error?(rc)
end
one_item.info
end
def reconfigure
extraconfig = []
+8 -3
View File
@@ -53,8 +53,13 @@ begin
# VM is new
vm = VCenterDriver::VirtualMachine.new
# Clone from template
vm.clone_vm(drv_action, vi_client)
# Clone the VM
vm.clone_vm(drv_action, vi_client) # Clone from template
# Set reference to template disks in VM template
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
vm.one_item = one_vm
vm.reference_imported_disks
end
vm.reconfigure
@@ -68,5 +73,5 @@ rescue Exception => e
"with #{dfile} failed due to \"#{e.message}\"\n#{e.backtrace}"
exit -1
ensure
vi_client.close_connection
vi_client.close_connection if vi_client
end