Skip to content

Commit

Permalink
Inventory Builder for TargetCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
slemrmartin committed Aug 27, 2018
1 parent 769b757 commit 3cfecc2
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions app/models/manageiq/providers/inventory/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,34 @@ class << self
# parser: ManageIQ::Providers::Amazon::Inventory:Parser::CloudManager
# persister: ManageIQ::Providers::Amazon::Inventory:Persister::CloudManager
def build_inventory(ems, target)
manager_type = ManageIQ::Providers::Inflector.manager_type(target)
case target
when ManagerRefresh::TargetCollection
build_target_collection_inventory(ems, target)
else
manager_type = ManageIQ::Providers::Inflector.manager_type(target)

manager_type = default_manager_type unless allowed_manager_types.include?(manager_type)
manager_type = default_manager_type unless allowed_manager_types.include?(manager_type)

collector_type = "#{collector_class}::#{manager_type}Manager".safe_constantize
persister_type = "#{persister_class}::#{manager_type}Manager".safe_constantize
parser_type = "#{parser_class}::#{manager_type}Manager".safe_constantize
collector_type = "#{collector_class}::#{manager_type}Manager".safe_constantize
persister_type = "#{persister_class}::#{manager_type}Manager".safe_constantize
parser_type = "#{parser_class}::#{manager_type}Manager".safe_constantize

inventory(ems, target, collector_type, persister_type, [parser_type])
inventory(ems, target, collector_type, persister_type, [parser_type])
end
end

def build_target_collection_inventory(ems, target)
parsers = allowed_manager_types.collect do |manager_type|
"#{parser_class}::#{manager_type}Manager".safe_constantize
end

inventory(
ems,
target,
"#{collector_class}::TargetCollection".safe_constantize,
"#{persister_class}::TargetCollection".safe_constantize,
parsers
)
end

protected
Expand Down Expand Up @@ -50,7 +69,7 @@ def allowed_manager_types
# one of allowed_manager_types in name
# Example: 'Cloud'
def default_manager_type
raise NotImplementedError
allowed_manager_types.first
end

# Automatically chooses inventory class based on builder class
Expand All @@ -63,21 +82,21 @@ def inventory_class
end

def collector_class
"#{inventory_class}::Collector".safe_constantize
"#{inventory_class}::Collector".constantize
rescue
ManageIQ::Providers::Inventory::Collector
end

def parser_class
"#{inventory_class}::Parser".safe_constantize
"#{inventory_class}::Parser".constantize
rescue
ManageIQ::Providers::Inventory::Collector
end

def persister_class
"#{inventory_class}::Persister".safe_constantize
"#{inventory_class}::Persister".constantize
rescue
ManageIQ::Providers::Inventory::Collector
end
end
end
end

0 comments on commit 3cfecc2

Please sign in to comment.