Skip to content

Commit

Permalink
Introduce model changes for v2v
Browse files Browse the repository at this point in the history
  • Loading branch information
bzwei committed Jan 10, 2018
1 parent 805e023 commit 7a47c94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/models/v2v_mapping.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions app/models/v2v_mapping_item.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7a47c94

Please sign in to comment.