-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,53 @@ | ||
class TransformationMapping < ApplicationRecord | ||
VM_VALID = N_("OK").freeze | ||
|
||
has_many :transformation_mapping_items, :dependent => :destroy | ||
|
||
validates :name, :presence => true, :uniqueness => true | ||
|
||
def destination(source) | ||
transformation_mapping_items.find_by(:source => source).try(:destination) | ||
end | ||
|
||
def select_vms | ||
valid_list = [] | ||
|
||
Vm.each do |vm| | ||
reason = validate_vm(vm) | ||
valid_list << describe_vm(vm, reason) if reason == VM_VALID | ||
end | ||
|
||
{"valid_vms" => valid_list} | ||
end | ||
|
||
def validate_vm(vm) | ||
invalid_list = [] | ||
invalid_list << "cluster: #{vm.ems_cluster.name}" unless valid_cluster?(vm) | ||
|
||
invalid_storages = validate_storages(vm) | ||
invalid_list << "storages: #{invalid_storages.join(", ")}" if invalid_storages.present? | ||
|
||
invalid_lans = validate_lans(vm) | ||
invalid_list << "lans: #{invalid_lans.join(', ')}" if invalid_lans.present? | ||
|
||
return N_("Not defined source for this migration - #{invalid_list.join('. ')}") if invalid_list.present? | ||
|
||
vm.v2v_migrated? ? N_('VM has been migrated') : VM_VALID | ||
end | ||
|
||
def valid_cluster?(vm) | ||
transformation_mapping_items.where(:source => vm.ems_cluster).present? | ||
end | ||
|
||
# return an empty array if all storages are valid for transformation | ||
# otherwise return an array of invalid datastores | ||
def validate_storages(vm) | ||
vm.datastores - transformation_mapping_items.where(:source => vm.datastores).collect(&:source) | ||
end | ||
|
||
# return an empty array if all lans are valid for transformation | ||
# otherwise return an array of invalid lans | ||
def validate_lans(vm) | ||
vm.lans - transformation_mapping_items.where(:source => vm.lans).collect(&:source) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters