mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
B #5288: Support spaces in VMDK names and dirnames
This commit is contained in:
parent
029f5366c4
commit
33fa9c9dde
@ -37,9 +37,11 @@ drv_action.initialize_xml(Base64.decode64(drv_action_enc), 'DS_DRIVER_ACTION_DAT
|
||||
|
||||
target_ds_ref = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_REF"]
|
||||
ds_image_dir = drv_action["/DS_DRIVER_ACTION_DATA/DATASTORE/TEMPLATE/VCENTER_DS_IMAGE_DIR"] || "one"
|
||||
src_path = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/PATH"]
|
||||
src_path_escaped = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/PATH"]
|
||||
src_img_id = drv_action["/DS_DRIVER_ACTION_DATA/IMAGE/CLONING_ID"]
|
||||
|
||||
src_path = VCenterDriver::FileHelper.unescape_path(src_path_escaped)
|
||||
|
||||
check_valid src_img_id, "cloning id"
|
||||
check_valid src_path, "image path"
|
||||
check_valid target_ds_ref, "target ds ref"
|
||||
|
@ -50,7 +50,9 @@ check_valid img_path, "img_path"
|
||||
|
||||
# if image is already in a vCenter datastore return the path
|
||||
if img_path.start_with? "vcenter://"
|
||||
puts img_path.sub("vcenter://","")
|
||||
img_path = img_path.sub("vcenter://", "")
|
||||
img_path = VCenterDriver::FileHelper.escape_path(img_path)
|
||||
puts img_path
|
||||
exit(0)
|
||||
end
|
||||
|
||||
|
@ -50,7 +50,9 @@ check_valid source_ds_id, "source_ds_id"
|
||||
target_ds_id = dst.split("/")[-3]
|
||||
disk_id = dst.split(".")[-1]
|
||||
|
||||
src_path = src.split(":")[-1]
|
||||
src_path_escaped = src.split(":")[-1]
|
||||
src_path = VCenterDriver::FileHelper.unescape_path(src_path_escaped)
|
||||
|
||||
hostname = dst.split(":").first
|
||||
|
||||
# Get host ID
|
||||
@ -71,14 +73,18 @@ check_valid target_ds_ref, "target_ds"
|
||||
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vm_id)
|
||||
|
||||
# calculate target path
|
||||
target_path = VCenterDriver::FileHelper.get_img_name_from_path(src_path,
|
||||
target_path_escaped = VCenterDriver::FileHelper.get_img_name_from_path(src_path_escaped,
|
||||
vm_id,
|
||||
disk_id)
|
||||
|
||||
target_path = VCenterDriver::FileHelper.unescape_path(target_path_escaped)
|
||||
|
||||
begin
|
||||
vi_client = VCenterDriver::VIClient.new_from_host(host_id)
|
||||
|
||||
# Find disk info
|
||||
disk = one_vm.retrieve_xmlelements("TEMPLATE/DISK[SOURCE=\"#{src_path}\"]").first rescue nil
|
||||
disk = one_vm.retrieve_xmlelements("TEMPLATE/DISK[SOURCE=\"#{src_path_escaped}\"]").first rescue nil
|
||||
|
||||
raise "Cannot find disk element in vm template" if !disk
|
||||
|
||||
new_size = nil
|
||||
@ -102,7 +108,7 @@ begin
|
||||
# Let's check if the disk is really unmanaged
|
||||
|
||||
if one_vm["TEMPLATE/CLONING_TEMPLATE_ID"]
|
||||
# In this case we're not cloning the disk, althought the disk
|
||||
# In this case we're not cloning the disk, although the disk
|
||||
# is unmanaged, the disk is treated as persistent until the
|
||||
# vm is terminated. That way the disk added to the new vcenter
|
||||
# template is the one that OpenNebula created when the OpenNebula
|
||||
@ -115,7 +121,11 @@ begin
|
||||
# What's the ID of the image and the source
|
||||
image_id = disk["IMAGE_ID"]
|
||||
one_image = VCenterDriver::VIHelper.one_item(OpenNebula::Image, image_id)
|
||||
one_source = one_image["SOURCE"]
|
||||
|
||||
one_source_escaped = one_image["SOURCE"]
|
||||
one_source = VCenterDriver::FileHelper.unescape_path(one_source_escaped)
|
||||
|
||||
# TODO: review this with disk clone
|
||||
|
||||
# Let's inspect the disks inside the template
|
||||
# if we found that the image source of the disk matches one of
|
||||
|
@ -89,7 +89,9 @@ begin
|
||||
source_ds_ref = disk_hash[:datastore]._ref
|
||||
else
|
||||
# Get image source path
|
||||
src_path = VCenterDriver::FileHelper.get_img_name(disk, vmid, vm['name'])
|
||||
src_path_escaped = VCenterDriver::FileHelper.get_img_name(disk, vmid, vm['name'])
|
||||
src_path = VCenterDriver::FileHelper.unescape_path(src_path_escaped)
|
||||
|
||||
source_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, source_ds_id)
|
||||
source_ds_ref = source_ds['TEMPLATE/VCENTER_DS_REF']
|
||||
##source_ds_ref = disk["VCENTER_DS_REF"]
|
||||
|
@ -26,7 +26,9 @@ class FileHelper
|
||||
end
|
||||
end
|
||||
|
||||
# REMOVE: no need to change...
|
||||
def self.get_img_name_from_path(path, vm_id, disk_id)
|
||||
# Note: This will probably fail if the basename contains '.'
|
||||
return "#{path.split(".").first}-#{vm_id}-#{disk_id}.vmdk"
|
||||
end
|
||||
|
||||
@ -133,6 +135,14 @@ class FileHelper
|
||||
end
|
||||
end
|
||||
|
||||
def self.escape_path(path)
|
||||
return path.gsub(" ", "%20")
|
||||
end
|
||||
|
||||
def self.unescape_path(path)
|
||||
return path.gsub("%20", " ")
|
||||
end
|
||||
|
||||
end # class FileHelper
|
||||
|
||||
end # module VCenterDriver
|
@ -1302,7 +1302,8 @@ class VirtualMachine < Template
|
||||
|
||||
# Try to find index of disks in template disks
|
||||
unmanaged_disks.each do |unmanaged_disk|
|
||||
index = template_disks_vector.index(unmanaged_disk["SOURCE"])
|
||||
unmanaged_disk_source = VCenterDriver::FileHelper.unescape_path(unmanaged_disk["SOURCE"])
|
||||
index = template_disks_vector.index(unmanaged_disk_source)
|
||||
if index
|
||||
reference = {}
|
||||
reference[:key] = "opennebula.disk.#{unmanaged_disk["DISK_ID"]}"
|
||||
@ -1886,12 +1887,19 @@ class VirtualMachine < Template
|
||||
if unmanaged_keys.key?("opennebula.disk.#{disk["DISK_ID"]}")
|
||||
device_key = unmanaged_keys["opennebula.disk.#{disk["DISK_ID"]}"].to_i
|
||||
disk_hash = get_device_filename_and_ds_from_key(device_key, vc_disks)
|
||||
onevm_disks_vector << disk_hash[:path_wo_ds] if disk_hash
|
||||
next
|
||||
end
|
||||
|
||||
img_name = VCenterDriver::FileHelper.get_img_name(disk, one_item['ID'], self['name'], instantiated_as_persistent?)
|
||||
onevm_disks_vector << "#{img_name}"
|
||||
if disk_hash
|
||||
onevm_disks_vector << disk_hash[:path_wo_ds]
|
||||
end
|
||||
else
|
||||
img_name_escaped = VCenterDriver::FileHelper.get_img_name(
|
||||
disk,
|
||||
one_item['ID'],
|
||||
self['name'],
|
||||
instantiated_as_persistent?)
|
||||
img_name = VCenterDriver::FileHelper.unescape_path(img_name_escaped)
|
||||
onevm_disks_vector << img_name
|
||||
end
|
||||
end
|
||||
|
||||
return onevm_disks_vector
|
||||
@ -1936,6 +1944,7 @@ class VirtualMachine < Template
|
||||
def device_detach_disks(onevm_disks_vector, unmanaged_keys, vc_disks)
|
||||
detach_disk_array = []
|
||||
extra_config = []
|
||||
|
||||
ipool = VCenterDriver::VIHelper.one_pool(OpenNebula::ImagePool)
|
||||
if ipool.respond_to?(:message)
|
||||
raise "Could not get OpenNebula ImagePool: #{ipool.message}"
|
||||
@ -1945,7 +1954,9 @@ class VirtualMachine < Template
|
||||
if !onevm_disks_vector.index(d[:path_wo_ds])
|
||||
|
||||
# If disk to be detached is not persistent detach and destroy it
|
||||
persistent = VCenterDriver::VIHelper.find_persistent_image_by_source(d[:path_wo_ds], ipool)
|
||||
source = VCenterDriver::FileHelper.escape_path(d[:path_wo_ds])
|
||||
persistent = VCenterDriver::VIHelper.find_persistent_image_by_source(source, ipool)
|
||||
|
||||
if !persistent
|
||||
detach_disk_array << {
|
||||
:fileOperation => :destroy,
|
||||
@ -2069,8 +2080,11 @@ class VirtualMachine < Template
|
||||
vm.config.hardware.device.each do |disk|
|
||||
if is_disk_or_cdrom?(disk)
|
||||
# Let's try to find if disks is persistent
|
||||
source = disk.backing.fileName.sub(/^\[(.*?)\] /, "")
|
||||
source_unescaped = disk.backing.fileName.sub(/^\[(.*?)\] /, "")
|
||||
source = VCenterDriver::FileHelper.escape_path(source_unescaped)
|
||||
|
||||
persistent = VCenterDriver::VIHelper.find_persistent_image_by_source(source, ipool)
|
||||
|
||||
if persistent
|
||||
spec_hash[:deviceChange] << {
|
||||
:operation => :remove,
|
||||
@ -2134,22 +2148,24 @@ class VirtualMachine < Template
|
||||
|
||||
# Get vcenter device representing DISK object (hotplug)
|
||||
def disk_attached_to_vm(disk, unmanaged_keys, vc_disks)
|
||||
|
||||
img_name = ""
|
||||
device_found = nil
|
||||
disk_id = disk["DISK_ID"]
|
||||
unmanaged_key = unmanaged_keys["opennebula.disk.#{disk_id}"]
|
||||
|
||||
img_name_escaped = VCenterDriver::FileHelper.get_img_name(
|
||||
disk,
|
||||
one_item['ID'],
|
||||
self['name'],
|
||||
instantiated_as_persistent?)
|
||||
|
||||
img_name = VCenterDriver::FileHelper.unescape_path(img_name_escaped)
|
||||
|
||||
vc_disks.each do |d|
|
||||
# Check if we are dealing with the unmanaged disks present in the template when cloned
|
||||
key_matches = (unmanaged_key && d[:key] == unmanaged_key.to_i)
|
||||
path_matches = (d[:path_wo_ds] == img_name)
|
||||
|
||||
if unmanaged_keys.key?("opennebula.disk.#{disk_id}") && d[:key] == unmanaged_keys["opennebula.disk.#{disk_id}"].to_i
|
||||
device_found = d
|
||||
break
|
||||
end
|
||||
|
||||
# Alright let's see if we can find other devices only with the expected image name
|
||||
img_name = VCenterDriver::FileHelper.get_img_name(disk, one_item['ID'], self['name'], instantiated_as_persistent?)
|
||||
if d[:path_wo_ds] == "#{img_name}"
|
||||
if key_matches || path_matches
|
||||
device_found = d
|
||||
break
|
||||
end
|
||||
@ -2159,7 +2175,14 @@ class VirtualMachine < Template
|
||||
end
|
||||
|
||||
def calculate_add_disk_spec(disk, position=0)
|
||||
img_name = VCenterDriver::FileHelper.get_img_name(disk, one_item['ID'], self['name'],instantiated_as_persistent?)
|
||||
img_name_escaped = VCenterDriver::FileHelper.get_img_name(
|
||||
disk,
|
||||
one_item['ID'],
|
||||
self['name'],
|
||||
instantiated_as_persistent?)
|
||||
|
||||
img_name = VCenterDriver::FileHelper.unescape_path(img_name_escaped)
|
||||
|
||||
type = disk["TYPE"]
|
||||
size_kb = disk["SIZE"].to_i * 1024
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user