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

Save mappings to options hash when calculated #18194

Merged
merged 2 commits into from
Nov 13, 2018
Merged
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
62 changes: 40 additions & 22 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,21 @@ 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
}
end
return options[:virtv2v_disks] if options[:virtv2v_disks].present?

options[:virtv2v_disks] = calculate_virtv2v_disks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you would need to do self.options[...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually no need. the reference is unambiguous enough to hitting the record's attribute

save!

options[:virtv2v_disks]
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)
}
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)
Expand Down Expand Up @@ -248,6 +238,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,
Expand Down