Skip to content

Commit

Permalink
Save the Lan parent_id for SCVMM
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Oct 11, 2017
1 parent f99dff3 commit b68a81c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/ems_refresh/save_inventory_infra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,13 @@ def save_lans_inventory(switch, hashes)
child_keys = [:subnets]

save_inventory_multi(switch.lans, hashes, :use_association, [:uid_ems], child_keys, extra_keys)
store_ids_for_new_records(switch.lans, hashes, :uid_ems)

child_lans = hashes.select { |h| !h[:id].nil? && !h.fetch_path(:parent, :id).nil? }
child_lans.each do |h|
parent_id = h.fetch_path(:parent, :id)
Lan.where(:id => h[:id]).update_all(:parent_id => parent_id)
end
end

def save_subnets_inventory(lan, hashes)
Expand Down
3 changes: 3 additions & 0 deletions app/models/lan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class Lan < ApplicationRecord
has_many :vms, -> { distinct }, :through => :guest_devices
has_many :miq_templates, -> { distinct }, :through => :guest_devices

has_many :lans, :foreign_key => :parent_id
belongs_to :parent, :class_name => "::Lan"

# TODO: Should this go through switch and not guest devices?
has_many :hosts, :through => :guest_devices

Expand Down

0 comments on commit b68a81c

Please sign in to comment.