diff --git a/app/models/v2v_mapping.rb b/app/models/v2v_mapping.rb new file mode 100644 index 000000000000..0f2f278ba817 --- /dev/null +++ b/app/models/v2v_mapping.rb @@ -0,0 +1,21 @@ +class V2vMapping < ApplicationRecord + has_many :v2v_mapping_items, dependent: :destroy + + validates :name, :presence => true, :uniqueness => true + + def self.select_mappings(vms) + resources = vms.each_with_object([]) do |vm, array| + array << vm.ems_cluster + array.concat(vm.storages) + # array.concat(vm.networks) # how to get networks? + end.compact.uniq + + select_mappings_by_sources(resources) + end + + def self.select_mappings_by_sources(sources) + all.select do |m| + true if m.mapping_items.where(:source => sources).count == sources.count + end + end +end diff --git a/app/models/v2v_mapping_item.rb b/app/models/v2v_mapping_item.rb new file mode 100644 index 000000000000..e1c3a82a9b01 --- /dev/null +++ b/app/models/v2v_mapping_item.rb @@ -0,0 +1,7 @@ +class V2vMappingItem < ApplicationRecord + belongs_to :v2v_mapping + belongs_to :source, :polymorphic => true + belongs_to :destination, :polymorphic => true + + validates :source_id, :uniqueness => {:scope => [:v2v_mapping_id, :source_type]} +end diff --git a/app/models/vm_or_template.rb b/app/models/vm_or_template.rb index 45e10f70aff7..91ecc47143aa 100644 --- a/app/models/vm_or_template.rb +++ b/app/models/vm_or_template.rb @@ -134,6 +134,7 @@ class VmOrTemplate < ApplicationRecord has_many :connected_shares, -> { where(:resource_type => "VmOrTemplate") }, :foreign_key => :resource_id, :class_name => "Share" has_many :labels, -> { where(:section => "labels") }, :class_name => "CustomAttribute", :as => :resource, :dependent => :destroy + belongs_to :v2v_plan, :class_name => "ServiceTemplate" acts_as_miq_taggable virtual_column :is_evm_appliance, :type => :boolean, :uses => :miq_server