From ede7755c12546d6966ae8ac7a0a3c93678e14f12 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Thu, 23 Feb 2017 09:24:00 +0100 Subject: [PATCH 1/2] Pass collector to persistor Pass collector to persistor, before we figure out how to pass references. It will be probably through target. --- app/models/manageiq/providers/amazon/builder.rb | 7 ++++--- .../providers/amazon/inventory/persister.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/manageiq/providers/amazon/builder.rb b/app/models/manageiq/providers/amazon/builder.rb index c4f7c3826..bc6db0043 100644 --- a/app/models/manageiq/providers/amazon/builder.rb +++ b/app/models/manageiq/providers/amazon/builder.rb @@ -56,12 +56,13 @@ def cloud_manager_inventory(ems, target) ) end - def inventory(manager, raw_target, collector_class, target_class, parsers_classes) + def inventory(manager, raw_target, collector_class, persister_class, parsers_classes) collector = collector_class.new(manager, raw_target) - target = target_class.new(manager, raw_target) + # TODO(lsmola) figure out a way to pass collector info, probably via target + persister = persister_class.new(manager, raw_target, collector) ::ManageIQ::Providers::Amazon::Inventory.new( - target, + persister, collector, parsers_classes.map(&:new) ) diff --git a/app/models/manageiq/providers/amazon/inventory/persister.rb b/app/models/manageiq/providers/amazon/inventory/persister.rb index 868843020..17e631fee 100644 --- a/app/models/manageiq/providers/amazon/inventory/persister.rb +++ b/app/models/manageiq/providers/amazon/inventory/persister.rb @@ -3,6 +3,21 @@ class ManageIQ::Providers::Amazon::Inventory::Persister < ManagerRefresh::Invent require_nested :NetworkManager require_nested :TargetCollection + # TODO(lsmola) figure out a way to pass collector info, probably via target, then remove the below + attr_reader :collector + # @param manager [ManageIQ::Providers::BaseManager] A manager object + # @param target [Object] A refresh Target object + # @param target [ManagerRefresh::Inventory::Collector] A Collector object + def initialize(manager, target, collector) + @manager = manager + @target = target + @collector = collector + + @collections = {} + + initialize_inventory_collections + end + protected def cloud From 700dfb60b77c2e845e6c45ddb82e0790d53a2287 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Thu, 23 Feb 2017 09:25:45 +0100 Subject: [PATCH 2/2] Use changed init schema and manager instead of ems Use changed init schema and manager instead of ems --- .../providers/amazon/inventory/collector/target_collection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/manageiq/providers/amazon/inventory/collector/target_collection.rb b/app/models/manageiq/providers/amazon/inventory/collector/target_collection.rb index ee484fbce..b94d76b21 100644 --- a/app/models/manageiq/providers/amazon/inventory/collector/target_collection.rb +++ b/app/models/manageiq/providers/amazon/inventory/collector/target_collection.rb @@ -1,5 +1,5 @@ class ManageIQ::Providers::Amazon::Inventory::Collector::TargetCollection < ManageIQ::Providers::Amazon::Inventory::Collector - def initialize(_ems, _options, _target) + def initialize(_manager, _target) super parse_targets! infer_related_ems_refs! @@ -188,7 +188,7 @@ def infer_related_ems_refs! # ems_refs of every related object. Now this is not very nice fro ma design point of view, but we really want # to see changes in VM's associated objects, so the VM view is always consistent and have fresh data. The partial # reason for this is, that AWS doesn't send all the objects state change, - changed_vms = ems.vms.where(:ems_ref => instances_refs.to_a).includes(:key_pairs, :network_ports, :floating_ips, + changed_vms = manager.vms.where(:ems_ref => instances_refs.to_a).includes(:key_pairs, :network_ports, :floating_ips, :orchestration_stack) changed_vms.each do |vm| stack = vm.orchestration_stack