From 2d04a112423fe0e48c6f64f5402d55b7e40024b2 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 9 Oct 2017 09:22:21 -0400 Subject: [PATCH 1/2] Add Subnet model and associations --- app/models/host.rb | 1 + app/models/lan.rb | 1 + app/models/manageiq/providers/infra_manager.rb | 1 + app/models/subnet.rb | 7 +++++++ app/models/switch.rb | 1 + 5 files changed, 11 insertions(+) create mode 100644 app/models/subnet.rb diff --git a/app/models/host.rb b/app/models/host.rb index e1eb6e10647..15945ad68de 100644 --- a/app/models/host.rb +++ b/app/models/host.rb @@ -49,6 +49,7 @@ class Host < ApplicationRecord has_many :host_switches, :dependent => :destroy has_many :switches, :through => :host_switches has_many :lans, :through => :switches + has_many :subnets, :through => :lans has_many :networks, :through => :hardware has_many :patches, :dependent => :destroy has_many :system_services, :dependent => :destroy diff --git a/app/models/lan.rb b/app/models/lan.rb index 4dcb9282d13..9e81491c3b7 100644 --- a/app/models/lan.rb +++ b/app/models/lan.rb @@ -1,6 +1,7 @@ class Lan < ApplicationRecord belongs_to :switch + has_many :subnets, :dependent => :destroy has_many :guest_devices has_many :vms_and_templates, -> { distinct }, :through => :guest_devices has_many :vms, -> { distinct }, :through => :guest_devices diff --git a/app/models/manageiq/providers/infra_manager.rb b/app/models/manageiq/providers/infra_manager.rb index 47a0ddc840c..531dda7525b 100644 --- a/app/models/manageiq/providers/infra_manager.rb +++ b/app/models/manageiq/providers/infra_manager.rb @@ -16,6 +16,7 @@ class InfraManager < BaseManager has_many :operating_systems, :through => :vms_and_templates has_many :switches, -> { distinct }, :through => :hosts has_many :lans, -> { distinct }, :through => :hosts + has_many :subnets, -> { distinct }, :through => :lans has_many :networks, :through => :hardwares has_many :guest_devices, :through => :hardwares diff --git a/app/models/subnet.rb b/app/models/subnet.rb new file mode 100644 index 00000000000..14ba80789b6 --- /dev/null +++ b/app/models/subnet.rb @@ -0,0 +1,7 @@ +class Subnet < ApplicationRecord + include NewWithTypeStiMixin + + acts_as_miq_taggable + + belongs_to :lan +end diff --git a/app/models/switch.rb b/app/models/switch.rb index cc72b3c977f..ebc123eac26 100644 --- a/app/models/switch.rb +++ b/app/models/switch.rb @@ -4,6 +4,7 @@ class Switch < ApplicationRecord has_many :guest_devices has_many :lans, :dependent => :destroy + has_many :subnets, :through => :lans acts_as_miq_taggable end From 2649e31768ea20330c3eb600a43eaf0cf6b8fb39 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Mon, 9 Oct 2017 09:23:40 -0400 Subject: [PATCH 2/2] Save Subnets under a cluster --- app/models/ems_refresh/save_inventory_infra.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/ems_refresh/save_inventory_infra.rb b/app/models/ems_refresh/save_inventory_infra.rb index 448088cfd0f..119013822d9 100644 --- a/app/models/ems_refresh/save_inventory_infra.rb +++ b/app/models/ems_refresh/save_inventory_infra.rb @@ -347,7 +347,14 @@ def remove_obsolete_switches end def save_lans_inventory(switch, hashes) - save_inventory_multi(switch.lans, hashes, :use_association, [:uid_ems]) + extra_keys = [:parent] + child_keys = [:subnets] + + save_inventory_multi(switch.lans, hashes, :use_association, [:uid_ems], child_keys, extra_keys) + end + + def save_subnets_inventory(lan, hashes) + save_inventory_multi(lan.subnets, hashes, :use_association, [:ems_ref]) end def save_storage_files_inventory(storage, hashes)