Skip to content

Commit

Permalink
ansible refresh parser as graph refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
durandom committed Jan 27, 2017
1 parent 2bec755 commit 3f21c56
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class ManageIQ::Providers::AnsibleTower::AutomationManager < ManageIQ::Providers
require_nested :ConfigurationScript
require_nested :ConfiguredSystem
require_nested :Refresher
require_nested :RefreshParser
require_nested :RefreshWorker
require_nested :Job

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker < MiqEmsRefreshWorker
require_nested :Collector
require_nested :Parser
require_nested :Runner

def self.ems_class
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker::Collector
def initialize(ems, _options = nil)
@ems = ems
@connection = ems.connect
end

def inventories
@connection.api.inventories.all
end

def hosts
@connection.api.hosts.all
end

def job_templates
@connection.api.job_templates.all
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker::Parser
attr_reader :inventory, :ems

def initialize(ems, target, inventory)
@ems = ems
@target = target
@inventory = inventory
end

def parse
[
inventory_groups,
configured_systems,
configuration_scripts,
]
end

def inventory_groups
@inventory_groups ||= ManagerRefresh::InventoryCollection.new(
ManageIQ::Providers::AutomationManager::InventoryRootGroup,
:association => :inventory_root_groups,
:parent => ems,
).tap do |c|
inventory.inventories.each do |i|
c << c.new_inventory_object(
# to_s should not be necessary, but its needed to resolve lazy find
:ems_ref => i.id.to_s,
:manager => ems,
:name => i.name,
)
end
end
end

def configured_systems
ManagerRefresh::InventoryCollection.new(
ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem,
:association => :configured_systems,
:manager_ref => [:manager_ref],
:parent => ems,
).tap do |c|
inventory.hosts.each do |i|
c << c.new_inventory_object(
:manager_ref => i.id,
:manager => ems,
:hostname => i.name,
# to_s should not be necessary, but its needed to resolve lazy find
:inventory_root_group => inventory_groups.lazy_find(i.inventory_id.to_s),
:virtual_instance_ref => i.instance_id,
# FIXME: dont access db here
:counterpart => Vm.find_by(:uid_ems => i.instance_id)
)
end
end
end

def configuration_scripts
ManagerRefresh::InventoryCollection.new(
ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript,
:association => :configuration_scripts,
:manager_ref => [:manager_ref],
:parent => ems,
).tap do |c|
inventory.job_templates.each do |i|
c << c.new_inventory_object(
:description => i.description,
:inventory_root_group => inventory_groups.lazy_find(i.inventory_id.to_s),
:manager => ems,
:manager_ref => i.id.to_s,
:name => i.name,
:survey_spec => i.survey_spec_hash,
:variables => i.extra_vars_hash,
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,34 @@ module AnsibleTower
class AutomationManager::Refresher < ManageIQ::Providers::BaseManager::Refresher
include ::EmsRefresh::Refreshers::EmsRefresherMixin

def parse_legacy_inventory(automation_manager)
automation_manager.with_provider_connection do |connection|
# TODO clean up with @ems_data
automation_manager.api_version = connection.api.version
automation_manager.save
def collect_inventory_for_targets(ems, targets)
ems.with_provider_connection do |connection|
# FIXME: this should really be somewhere else
ems.api_version = connection.api.version
ems.save
end

ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshParser.automation_manager_inv_to_hashes(automation_manager, refresher_options)
targets.collect do |target|
target_name = target.try(:name)

_log.info "Collecting inventory for #{target.class} [#{target_name}] id: [#{target.id}]..."

inventory = ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker::Collector.new(ems)

_log.info "Collecting inventory...Complete"
[target, inventory]
end
end

def parse_targeted_inventory(ems, target, inventory)
log_header = format_ems_for_logging(ems)
_log.debug "#{log_header} Parsing inventory..."
hashes, = Benchmark.realtime_block(:parse_inventory) do
ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker::Parser.new(ems, target, inventory).parse
end
_log.debug "#{log_header} Parsing inventory...Complete"

hashes
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/manageiq/providers/automation_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ManageIQ::Providers::AutomationManager < ::ExtManagementSystem
has_many :configuration_profiles, :dependent => :destroy, :foreign_key => "manager_id"
has_many :configuration_scripts, :dependent => :destroy, :foreign_key => "manager_id"
has_many :inventory_groups, :dependent => :destroy, :foreign_key => "ems_id", :inverse_of => :manager
has_many :inventory_root_groups, :dependent => :destroy, :foreign_key => "ems_id", :inverse_of => :manager
has_many :configuration_script_sources, :dependent => :destroy, :foreign_key => "manager_id"

virtual_column :total_configuration_profiles, :type => :integer
Expand Down

This file was deleted.

0 comments on commit 3f21c56

Please sign in to comment.