From b823e91126e8d7cb9d1b76b921fb774d766d14b0 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Tue, 13 Nov 2018 11:59:29 -0500 Subject: [PATCH 1/2] Save mappings to options hash when calculated --- ...rvice_template_transformation_plan_task.rb | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/app/models/service_template_transformation_plan_task.rb b/app/models/service_template_transformation_plan_task.rb index 7de38692460..234a0b3d2d8 100644 --- a/app/models/service_template_transformation_plan_task.rb +++ b/app/models/service_template_transformation_plan_task.rb @@ -84,30 +84,14 @@ def transformation_type end def virtv2v_disks - options[:virtv2v_disks] ||= source.hardware.disks.select { |d| d.device_type == 'disk' }.collect do |disk| - source_storage = disk.storage - destination_storage = transformation_destination(disk.storage) - raise "[#{source.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping." if destination_storage.nil? - { - :path => disk.filename, - :size => disk.size, - :percent => 0, - :weight => disk.size.to_f / source.allocated_disk_storage.to_f * 100 - } + options[:virtv2v_disks] ||= calculate_virtv2v_disks.tap do |disks| + update_attributes(:options => options.merge(:virtv2v_disks => disks)) end end def network_mappings - options[:network_mappings] ||= source.hardware.nics.select { |n| n.device_type == 'ethernet' }.collect do |nic| - source_network = nic.lan - destination_network = transformation_destination(source_network) - raise "[#{source.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping." if destination_network.nil? - { - :source => source_network.name, - :destination => destination_network_ref(destination_network), - :mac_address => nic.address, - :ip_address => nic.network.try(:ipaddress) - } + options[:network_mappings] ||= calculate_network_mappings.tap do |mappings| + update_attributes(:options => options.merge(:network_mappings => mappings)) end end @@ -248,6 +232,34 @@ def create_error_status_task(userid, msg) ) end + def calculate_virtv2v_disks + source.hardware.disks.select { |d| d.device_type == 'disk' }.collect do |disk| + source_storage = disk.storage + destination_storage = transformation_destination(disk.storage) + raise "[#{source.name}] Disk #{disk.device_name} [#{source_storage.name}] has no mapping." if destination_storage.nil? + { + :path => disk.filename, + :size => disk.size, + :percent => 0, + :weight => disk.size.to_f / source.allocated_disk_storage.to_f * 100 + } + end + end + + def calculate_network_mappings + source.hardware.nics.select { |n| n.device_type == 'ethernet' }.collect do |nic| + source_network = nic.lan + destination_network = transformation_destination(source_network) + raise "[#{source.name}] NIC #{nic.device_name} [#{source_network.name}] has no mapping." if destination_network.nil? + { + :source => source_network.name, + :destination => destination_network_ref(destination_network), + :mac_address => nic.address, + :ip_address => nic.network.try(:ipaddress) + } + end + end + def conversion_options_source_provider_vmwarews_vddk(_storage) { :vm_name => source.name, From 2698585b938555e598ba88fb0d001ceae78335f8 Mon Sep 17 00:00:00 2001 From: Fabien Dupont Date: Tue, 13 Nov 2018 12:40:08 -0500 Subject: [PATCH 2/2] Better obvious than fancy --- ...ervice_template_transformation_plan_task.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/service_template_transformation_plan_task.rb b/app/models/service_template_transformation_plan_task.rb index 234a0b3d2d8..80fba590a2c 100644 --- a/app/models/service_template_transformation_plan_task.rb +++ b/app/models/service_template_transformation_plan_task.rb @@ -84,15 +84,21 @@ def transformation_type end def virtv2v_disks - options[:virtv2v_disks] ||= calculate_virtv2v_disks.tap do |disks| - update_attributes(:options => options.merge(:virtv2v_disks => disks)) - end + return options[:virtv2v_disks] if options[:virtv2v_disks].present? + + options[:virtv2v_disks] = calculate_virtv2v_disks + save! + + options[:virtv2v_disks] end def network_mappings - options[:network_mappings] ||= calculate_network_mappings.tap do |mappings| - update_attributes(:options => options.merge(:network_mappings => mappings)) - end + return options[:network_mappings] if options[:network_mappings].present? + + options[:network_mappings] = calculate_network_mappings + save! + + options[:network_mappings] end def destination_network_ref(network)