mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
* B #5531: OpenNebula does not duplicate template/VM images * B #5531: onevcenter images works as expected * B #5531: vcenter imported images adquire proper names (cherry picked from commit a0a2a034d7920f2261d9bc5208f5db29a28af7de)
This commit is contained in:
parent
03c88b75f5
commit
97d4a54a60
@ -327,8 +327,10 @@ get '/vcenter/template/:vcenter_ref/:template_id' do
|
||||
end
|
||||
end
|
||||
|
||||
type = {:object => "template", :id => template_id}
|
||||
|
||||
# Create images or get disks information for template
|
||||
error, template_disks = template.import_vcenter_disks(vc_uuid, dpool, ipool, true, template_id)
|
||||
error, template_disks = template.import_vcenter_disks(vc_uuid, dpool, ipool, type, true)
|
||||
raise error if !error.empty?
|
||||
|
||||
template_moref = template_copy_ref ? template_copy_ref : ref
|
||||
|
@ -68,7 +68,7 @@ class Storage
|
||||
end
|
||||
end
|
||||
|
||||
def self.get_image_import_template(ds_name, image_path, image_type, image_prefix, ipool, template_id)
|
||||
def self.get_image_import_template(ds_name, image_path, image_type, image_prefix, ipool, type, ds_id)
|
||||
one_image = {}
|
||||
one_image[:template] = ""
|
||||
|
||||
@ -77,18 +77,18 @@ class Storage
|
||||
|
||||
# Get image name
|
||||
file_name = File.basename(image_path).gsub(/\.vmdk$/,"")
|
||||
if template_id
|
||||
image_name = "#{file_name} - #{ds_name} [Template #{template_id}]"
|
||||
else
|
||||
image_name = "#{file_name} - #{ds_name}"
|
||||
end
|
||||
|
||||
#Check if the image has already been imported
|
||||
image = VCenterDriver::VIHelper.find_by_name(OpenNebula::ImagePool,
|
||||
image_name,
|
||||
ipool,
|
||||
false)
|
||||
image = VIHelper.find_image_by("SOURCE", OpenNebula::ImagePool, image_path, ds_id, ipool)
|
||||
|
||||
if image.nil?
|
||||
# Generate a name with the reference
|
||||
begin
|
||||
image_name = "#{file_name} - #{ds_name} [#{type[:object]} #{type[:id]}]"
|
||||
rescue
|
||||
image_name = "#{file_name} - #{ds_name}"
|
||||
end
|
||||
|
||||
#Set template
|
||||
one_image[:template] << "NAME=\"#{image_name}\"\n"
|
||||
one_image[:template] << "PATH=\"vcenter://#{image_path}\"\n"
|
||||
@ -616,9 +616,8 @@ class Datastore < Storage
|
||||
one_image << "DEV_PREFIX=\"#{disk_prefix}\"\n"
|
||||
|
||||
# Check image hasn't already been imported
|
||||
vcenter_path = "vcenter://#{image_path}"
|
||||
image_found = VCenterDriver::VIHelper.find_image_by_path(OpenNebula::ImagePool,
|
||||
vcenter_path,
|
||||
image_found = VCenterDriver::VIHelper.find_image_by("SOURCE", OpenNebula::ImagePool,
|
||||
image_path,
|
||||
ds_id,
|
||||
ipool)
|
||||
|
||||
|
@ -34,7 +34,8 @@ def self.import_wild(host_id, vm_ref, one_vm, template)
|
||||
wild = true
|
||||
sunstone = false
|
||||
|
||||
error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool, sunstone)
|
||||
type = {:object => "VM", :id => vm_name}
|
||||
error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool, type, sunstone)
|
||||
return OpenNebula::Error.new(error) if !error.empty?
|
||||
|
||||
template << template_disks
|
||||
@ -427,11 +428,12 @@ def self.import_templates(con_ops, options)
|
||||
template = t[:template] if !template
|
||||
|
||||
|
||||
type = {:object => "template", :id => one_t["ID"]}
|
||||
error, template_disks, allocated_images = template.import_vcenter_disks(vc_uuid,
|
||||
dpool,
|
||||
ipool,
|
||||
false,
|
||||
one_t["ID"])
|
||||
type,
|
||||
false)
|
||||
|
||||
if error.empty?
|
||||
t[:one] << template_disks
|
||||
|
@ -107,10 +107,10 @@ class VIHelper
|
||||
return nil
|
||||
end
|
||||
|
||||
def self.find_image_by_path(the_class, path, ds_id, pool = nil)
|
||||
def self.find_image_by(att, the_class, path, ds_id, pool = nil)
|
||||
pool = one_pool(the_class, false) if pool.nil?
|
||||
element = pool.find{|e|
|
||||
e["PATH"] == path &&
|
||||
e[att] == path &&
|
||||
e["DATASTORE_ID"] == ds_id}
|
||||
return element
|
||||
end
|
||||
|
@ -225,7 +225,12 @@ class Template
|
||||
end
|
||||
end
|
||||
|
||||
def import_vcenter_disks(vc_uuid, dpool, ipool, sunstone=false, template_id=nil)
|
||||
########################################################################
|
||||
# Import vcenter disks
|
||||
# @param type [object] contains the type of the object(:object) and identificator(:id)
|
||||
# @return error, template_disks
|
||||
########################################################################
|
||||
def import_vcenter_disks(vc_uuid, dpool, ipool, type, sunstone=false)
|
||||
disk_info = ""
|
||||
error = ""
|
||||
sunstone_disk_info = []
|
||||
@ -264,7 +269,8 @@ class Template
|
||||
disk[:type],
|
||||
disk[:prefix],
|
||||
ipool,
|
||||
template_id)
|
||||
type,
|
||||
datastore_found["ID"])
|
||||
#Image is already in the datastore
|
||||
if image_import[:one]
|
||||
# This is the disk info
|
||||
|
Loading…
x
Reference in New Issue
Block a user