Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B #2140: reducing useless code on vcenter virtual machine (sunstone r… #2368

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/vmm_mad/remotes/lib/vcenter_driver/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ def self.import_wild(host_id, vm_ref, one_vm, template)
vm_name = vcenter_vm["name"]

wild = true
sunstone = false

type = {:object => "VM", :id => vm_name}
error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool, type, sunstone)
error, template_disks = vcenter_vm.import_vcenter_disks(vc_uuid, dpool, ipool, type)
return OpenNebula::Error.new(error) if !error.empty?

template << template_disks
Expand All @@ -59,7 +58,6 @@ def self.import_wild(host_id, vm_ref, one_vm, template)
hpool,
vc_name,
vm_ref,
sunstone,
vm_name)

if !error.empty?
Expand Down
147 changes: 49 additions & 98 deletions src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,9 @@ def create_delta_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)
def import_vcenter_disks(vc_uuid, dpool, ipool, type)
disk_info = ""
error = ""
sunstone_disk_info = []

begin
lock #Lock import operation, to avoid concurrent creation of images
Expand Down Expand Up @@ -314,51 +313,36 @@ def import_vcenter_disks(vc_uuid, dpool, ipool, type, sunstone=false)
disk_tmp << "IMAGE_ID=\"#{image_import[:one]["ID"]}\",\n"
disk_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
disk_tmp << "]\n"
if sunstone
sunstone_disk = {}
sunstone_disk[:type] = "EXISTING_DISK"
sunstone_disk[:image_tmpl] = disk_tmp
sunstone_disk_info << sunstone_disk
else
disk_info << disk_tmp
end
disk_info << disk_tmp

elsif !image_import[:template].empty?

if sunstone
sunstone_disk = {}
sunstone_disk[:type] = "NEW_DISK"
sunstone_disk[:image_tmpl] = image_import[:template]
sunstone_disk[:ds_id] = datastore_found['ID'].to_i
sunstone_disk_info << sunstone_disk
else
# Then the image is created as it's not in the datastore
one_i = VCenterDriver::VIHelper.new_one_item(OpenNebula::Image)
allocated_images << one_i
rc = one_i.allocate(image_import[:template], datastore_found['ID'].to_i, false)

if OpenNebula.is_error?(rc)
error = " Error creating disk from template: #{rc.message}\n"
break
end
# Then the image is created as it's not in the datastore
one_i = VCenterDriver::VIHelper.new_one_item(OpenNebula::Image)
allocated_images << one_i
rc = one_i.allocate(image_import[:template], datastore_found['ID'].to_i, false)

# Monitor image, we need READY state
one_i.info
start_time = Time.now

while one_i.state_str != "READY" and Time.now - start_time < 300
sleep 1
one_i.info
end
if OpenNebula.is_error?(rc)
error = " Error creating disk from template: #{rc.message}\n"
break
end

# Monitor image, we need READY state
one_i.info
start_time = Time.now

#Add info for One template
while one_i.state_str != "READY" and Time.now - start_time < 300
sleep 1
one_i.info
disk_info << "DISK=[\n"
disk_info << "IMAGE_ID=\"#{one_i["ID"]}\",\n"
disk_info << "OPENNEBULA_MANAGED=\"NO\"\n"
disk_info << "]\n"
end


#Add info for One template
one_i.info
disk_info << "DISK=[\n"
disk_info << "IMAGE_ID=\"#{one_i["ID"]}\",\n"
disk_info << "OPENNEBULA_MANAGED=\"NO\"\n"
disk_info << "]\n"
end
end

Expand All @@ -374,10 +358,7 @@ def import_vcenter_disks(vc_uuid, dpool, ipool, type, sunstone=false)
end
end

return error, sunstone_disk_info, allocated_images if sunstone

return error, disk_info, allocated_images if !sunstone

return error, disk_info, allocated_images
end

def create_ar(nic, with_id = false)
Expand Down Expand Up @@ -454,10 +435,9 @@ def save_ar_ids(network_found, nic, ar_ids, start_ids = false)
end

def import_vcenter_nics(vc_uuid, npool, hpool, vcenter_instance_name,
template_ref, wild, sunstone=false, vm_name=nil, vm_id=nil, dc_name=nil)
template_ref, wild, vm_name=nil, vm_id=nil, dc_name=nil)
nic_info = ""
error = ""
sunstone_nic_info = []
ar_ids = {}
begin
lock #Lock import operation, to avoid concurrent creation of networks
Expand Down Expand Up @@ -511,14 +491,7 @@ def import_vcenter_nics(vc_uuid, npool, hpool, vcenter_instance_name,
nic_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
nic_tmp << "]\n"

if sunstone
sunstone_nic = {}
sunstone_nic[:type] = "EXISTING_NIC"
sunstone_nic[:network_tmpl] = nic_tmp
sunstone_nic_info << sunstone_nic
else
nic_info << nic_tmp
end
nic_info << nic_tmp

# network not found:
else
Expand Down Expand Up @@ -577,50 +550,31 @@ def import_vcenter_nics(vc_uuid, npool, hpool, vcenter_instance_name,
config[:one_object] = one_vnet[:one]
cluster_id = VCenterDriver::VIHelper.get_cluster_id(config[:one_ids])

if sunstone
if !duplicated_networks.include?(nic[:net_name])
sunstone_nic = {}
sunstone_nic[:type] = "NEW_NIC"
sunstone_nic[:network_name] = nic[:net_name]
sunstone_nic[:network_tmpl] = one_vnet[:one]
sunstone_nic[:one_cluster_id] = cluster_id.to_i
sunstone_nic_info << sunstone_nic
duplicated_networks << nic[:net_name]
else
sunstone_nic = {}
sunstone_nic[:type] = "DUPLICATED_NIC"
sunstone_nic[:network_name] = nic[:net_name]
sunstone_nic_info << sunstone_nic
end

# not sunstone:
else
one_vn = VCenterDriver::Network.create_one_network(config)
allocated_networks << one_vn
VCenterDriver::VIHelper.clean_ref_hash()
one_vn.info

nic_tmp = "NIC=[\n"
nic_tmp << "NETWORK_ID=\"#{one_vn.id}\",\n"

if wild?
last_id = save_ar_ids(one_vn, nic, ar_ids)
nic_tmp << "AR_ID=\"#{last_id}\",\n"
nic_tmp << "MAC=\"#{nic[:mac]}\",\n" if nic[:mac]
nic_tmp << "VCENTER_ADDITIONALS_IP4=\"#{nic[:ipv4_additionals]}\",\n" if nic[:ipv4_additionals]
nic_tmp << "VCENTER_IP6=\"#{nic[:ipv6]}\",\n" if nic[:ipv6]
nic_tmp << "IP6_GLOBAL=\"#{nic[:ipv6_global]}\",\n" if nic[:ipv6_global]
nic_tmp << "IP6_ULA=\"#{nic[:ipv6_ula]}\",\n" if nic[:ipv6_ula]
nic_tmp << "VCENTER_ADDITIONALS_IP6=\"#{nic[:ipv6_additionals]}\",\n" if nic[:ipv6_additionals]
end
one_vn = VCenterDriver::Network.create_one_network(config)
allocated_networks << one_vn
VCenterDriver::VIHelper.clean_ref_hash()
one_vn.info

nic_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
nic_tmp << "]\n"
nic_info << nic_tmp
nic_tmp = "NIC=[\n"
nic_tmp << "NETWORK_ID=\"#{one_vn.id}\",\n"

# Refresh npool
npool.info_all
if wild?
last_id = save_ar_ids(one_vn, nic, ar_ids)
nic_tmp << "AR_ID=\"#{last_id}\",\n"
nic_tmp << "MAC=\"#{nic[:mac]}\",\n" if nic[:mac]
nic_tmp << "VCENTER_ADDITIONALS_IP4=\"#{nic[:ipv4_additionals]}\",\n" if nic[:ipv4_additionals]
nic_tmp << "VCENTER_IP6=\"#{nic[:ipv6]}\",\n" if nic[:ipv6]
nic_tmp << "IP6_GLOBAL=\"#{nic[:ipv6_global]}\",\n" if nic[:ipv6_global]
nic_tmp << "IP6_ULA=\"#{nic[:ipv6_ula]}\",\n" if nic[:ipv6_ula]
nic_tmp << "VCENTER_ADDITIONALS_IP6=\"#{nic[:ipv6_additionals]}\",\n" if nic[:ipv6_additionals]
end

nic_tmp << "OPENNEBULA_MANAGED=\"NO\"\n"
nic_tmp << "]\n"
nic_info << nic_tmp

# Refresh npool
npool.info_all
end
end
rescue Exception => e
Expand All @@ -635,9 +589,7 @@ def import_vcenter_nics(vc_uuid, npool, hpool, vcenter_instance_name,
end
end

return error, nic_info, ar_ids, allocated_networks if !sunstone

return error, sunstone_nic_info, ar_ids, allocated_networks if sunstone
return error, nic_info, ar_ids, allocated_networks
end

def get_vcenter_disk_key(unit_number, controller_key)
Expand Down Expand Up @@ -3625,7 +3577,6 @@ def import(selected)
vcenter,
template_moref,
wild,
false,
template["name"],
id,
dc)
Expand Down