From b68a81c935fb0a938c6c5a6017ea59ae4812b9d0 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 9 Oct 2017 16:06:39 -0400 Subject: [PATCH] Save the Lan parent_id for SCVMM --- app/models/ems_refresh/save_inventory_infra.rb | 7 +++++++ app/models/lan.rb | 3 +++ 2 files changed, 10 insertions(+) diff --git a/app/models/ems_refresh/save_inventory_infra.rb b/app/models/ems_refresh/save_inventory_infra.rb index c378c957fc5..ec338501db7 100644 --- a/app/models/ems_refresh/save_inventory_infra.rb +++ b/app/models/ems_refresh/save_inventory_infra.rb @@ -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) diff --git a/app/models/lan.rb b/app/models/lan.rb index 9e81491c3b7..bf4803f130a 100644 --- a/app/models/lan.rb +++ b/app/models/lan.rb @@ -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