Skip to content

Commit

Permalink
AnsibleTower::ConfigurationManager is now
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed Jan 25, 2017
1 parent 1d00c06 commit 2f0ef1a
Show file tree
Hide file tree
Showing 94 changed files with 474 additions and 318 deletions.
1 change: 1 addition & 0 deletions app/models/ems_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module EmsRefresh
extend EmsRefresh::SaveInventoryHelper
extend EmsRefresh::SaveInventoryProvisioning
extend EmsRefresh::SaveInventoryConfiguration
extend EmsRefresh::SaveInventoryAutomation
extend EmsRefresh::SaveInventoryOrchestrationStacks
extend EmsRefresh::LinkInventory
extend EmsRefresh::MetadataRelats
Expand Down
1 change: 1 addition & 0 deletions app/models/ems_refresh/save_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def save_ems_inventory(ems, hashes, target = nil)
case ems
when EmsCloud then save_ems_cloud_inventory(ems, hashes, target)
when EmsInfra then save_ems_infra_inventory(ems, hashes, target)
when ManageIQ::Providers::AutomationManager then save_automation_manager_inventory(ems, hashes, target)
when ManageIQ::Providers::ConfigurationManager then save_configuration_manager_inventory(ems, hashes, target)
when ManageIQ::Providers::ContainerManager then save_ems_container_inventory(ems, hashes, target)
when ManageIQ::Providers::NetworkManager then save_ems_network_inventory(ems, hashes, target)
Expand Down
51 changes: 51 additions & 0 deletions app/models/ems_refresh/save_inventory_automation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Calling order
#
# - ems
# - configuration_profiles
# - operating_system_flavor (links)
# - customization_script_ptable (link)
# - customization_script_medium (link)
# - configured_systems
# - operating_system_flavor (links)
# - customization_scripts (links)
## ? use guid?
module EmsRefresh
module SaveInventoryAutomation
def save_automation_manager_inventory(manager, hashes, target = nil)
return if hashes.nil?
save_child_inventory(manager, hashes, [:ems_folders, :configuration_profiles, :configured_systems, :configuration_scripts], target)
manager.save
end

def save_configuration_profiles_inventory(manager, hashes, target)
delete_missing_records = target.nil? || manager == target
save_inventory_assoc(manager.configuration_profiles, hashes, delete_missing_records, [:manager_ref])

link_children_references(manager.configuration_profiles)
end

def save_configured_systems_inventory(manager, hashes, target)
delete_missing_records = target.nil? || manager == target
# these records are cross referenced to the hashes
# get the id out and store in this record
hashes.each do |hash|
hash[:configuration_profile_id] = hash.fetch_path(:configuration_profile, :id)
hash[:inventory_root_group_id] = hash.fetch_path(:inventory_root_group, :id)
end
save_inventory_assoc(manager.configured_systems, hashes, delete_missing_records, [:manager_ref], nil, [:configuration_profile, :inventory_root_group])
end

def save_configuration_scripts_inventory(manager, hashes, target)
delete_missing_records = target.nil? || manager == target
# these records are cross referenced to the hashes
# get the id out and store in this record
hashes.each { |hash| hash[:inventory_root_group_id] = hash.fetch_path(:inventory_root_group, :id) }
save_inventory_assoc(manager.configuration_scripts, hashes, delete_missing_records, [:manager_ref], nil, [:configuration_script, :inventory_root_group])
end

def save_ems_folders_inventory(manager, hashes, target)
delete_missing_records = target.nil? || manager == target
save_inventory_assoc(manager.inventory_groups, hashes, delete_missing_records, [:ems_ref], nil, [:ems_folder])
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager < ManageIQ::Providers::ConfigurationManager
class ManageIQ::Providers::AnsibleTower::AutomationManager < ManageIQ::Providers::ExternalAutomationManager
require_nested :ConfigurationScript
require_nested :ConfiguredSystem
require_nested :Refresher
Expand All @@ -17,15 +17,15 @@ class ManageIQ::Providers::AnsibleTower::ConfigurationManager < ManageIQ::Provid
:to => :provider

def self.ems_type
@ems_type ||= "ansible_tower_configuration".freeze
@ems_type ||= "ansible_tower_automation".freeze
end

def self.description
@description ||= "Ansible Tower Configuration".freeze
@description ||= "Ansible Tower Automation".freeze
end

def image_name
"ansible_tower_configuration"
"ansible_tower_automation"
end

private
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript < ConfigurationScript
class ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript < ConfigurationScript
def run(vars = {})
options = vars.merge(merge_extra_vars(vars[:extra_vars]))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem < ::ConfiguredSystem
class ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem < ::ConfiguredSystem
include ProviderObjectMixin

def provider_object(connection = nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::EventCatcher < ManageIQ::Providers::BaseManager::EventCatcher
require_nested :Runner
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Runner < ManageIQ::Providers::BaseManager::EventCatcher::Runner
class ManageIQ::Providers::AnsibleTower::AutomationManager::EventCatcher::Runner < ManageIQ::Providers::BaseManager::EventCatcher::Runner
def stop_event_monitor
event_monitor_handle.stop
end
Expand All @@ -16,15 +16,15 @@ def monitor_events

def queue_event(event)
_log.info "#{log_prefix} Caught event [#{event.id}]"
event_hash = ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventParser.event_to_hash(event, @cfg[:ems_id])
event_hash = ManageIQ::Providers::AnsibleTower::AutomationManager::EventParser.event_to_hash(event, @cfg[:ems_id])
EmsEvent.add_queue('add', @cfg[:ems_id], event_hash)
end

private

def event_monitor_handle
@event_monitor_handle ||= begin
ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Stream.new(
ManageIQ::Providers::AnsibleTower::AutomationManager::EventCatcher::Stream.new(
@ems,
:poll_sleep => worker_settings[:poll]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventCatcher::Stream
class ManageIQ::Providers::AnsibleTower::AutomationManager::EventCatcher::Stream
class ProviderUnreachable < ManageIQ::Providers::BaseManager::EventCatcher::Runner::TemporaryFailure
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module ManageIQ::Providers::AnsibleTower::ConfigurationManager::EventParser
module ManageIQ::Providers::AnsibleTower::AutomationManager::EventParser
def self.event_to_hash(event, ems_id)
{
:event_type => "ansible_tower_#{event.operation}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'ansible_tower_client'
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::Job < ::OrchestrationStack
class ManageIQ::Providers::AnsibleTower::AutomationManager::Job < ::OrchestrationStack
require_nested :Status

belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::ConfigurationManager"
belongs_to :ext_management_system, :foreign_key => :ems_id, :class_name => "ManageIQ::Providers::AutomationManager"
belongs_to :job_template, :foreign_key => :orchestration_template_id, :class_name => "ConfigurationScript"

#
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::AnsibleTower::ConfigurationManager::Job::Status < ::OrchestrationStack::Status
class ManageIQ::Providers::AnsibleTower::AutomationManager::Job::Status < ::OrchestrationStack::Status
def succeeded?
status.casecmp("successful").zero?
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::Playbook < ConfigurationScriptPayload
end
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module ManageIQ::Providers
module AnsibleTower
class ConfigurationManager::RefreshParser
class AutomationManager::RefreshParser
include Vmdb::Logging

def self.configuration_manager_inv_to_hashes(ems, options = nil)
new(ems, options).configuration_manager_inv_to_hashes
def self.automation_manager_inv_to_hashes(ems, options = nil)
new(ems, options).automation_manager_inv_to_hashes
end

def initialize(ems, options = nil)
Expand All @@ -15,8 +15,8 @@ def initialize(ems, options = nil)
@data_index = {}
end

def configuration_manager_inv_to_hashes
log_header = "Collecting data for ConfigurationManager : [#{@ems.name}] id: [#{@ems.id}]"
def automation_manager_inv_to_hashes
log_header = "Collecting data for AutomationManager : [#{@ems.name}] id: [#{@ems.id}]"

_log.info("#{log_header}...")
get_inventories
Expand Down Expand Up @@ -61,7 +61,7 @@ def parse_host(host)
name = uid = host.name

new_result = {
:type => "ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfiguredSystem",
:type => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfiguredSystem",
:manager_ref => host.id.to_s,
:hostname => name,
:inventory_root_group => inventory_root_group,
Expand All @@ -82,7 +82,7 @@ def parse_inventory(inventory)
uid = inventory.id

new_result = {
:type => "ManageIQ::Providers::ConfigurationManager::InventoryRootGroup",
:type => "ManageIQ::Providers::AutomationManager::InventoryRootGroup",
:ems_ref => inventory.id.to_s,
:name => inventory.name,
}
Expand All @@ -100,7 +100,7 @@ def parse_job_template(job_template)
:manager_ref => job_template.id.to_s,
:name => job_template.name,
:survey_spec => job_template.survey_spec_hash,
:type => "ManageIQ::Providers::AnsibleTower::ConfigurationManager::ConfigurationScript",
:type => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScript",
:variables => job_template.extra_vars_hash
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker < MiqEmsRefreshWorker
require_nested :Runner

def self.ems_class
parent
end

def self.settings_name
:ems_refresh_worker_ansible_tower_automation
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshWorker::Runner < ManageIQ::Providers::BaseManager::RefreshWorker::Runner
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ManageIQ::Providers
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
end

ManageIQ::Providers::AnsibleTower::AutomationManager::RefreshParser.automation_manager_inv_to_hashes(automation_manager, refresher_options)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module ManageIQ::Providers::AnsibleTower::AutomationManagerMixin
extend ActiveSupport::Concern

require_nested :ConfigurationScript
require_nested :ConfiguredSystem
require_nested :Refresher
require_nested :RefreshParser
require_nested :RefreshWorker
require_nested :Job

include ProcessTasksMixin
delegate :authentications,
:authentication_check,
:authentication_status,
:authentication_status_ok?,
:connect,
:verify_credentials,
:with_provider_connection,
:to => :provider

module ClassMethods
private

def connection_source(options = {})
options[:connection_source] || self
end
end

def image_name
"ansible_tower_configuration"
end
end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 5 additions & 5 deletions app/models/manageiq/providers/ansible_tower/provider.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ManageIQ::Providers::AnsibleTower::Provider < ::Provider
has_one :configuration_manager,
has_one :automation_manager,
:foreign_key => "provider_id",
:class_name => "ManageIQ::Providers::AnsibleTower::ConfigurationManager",
:class_name => "ManageIQ::Providers::AnsibleTower::AutomationManager",
:dependent => :destroy,
:autosave => true

Expand Down Expand Up @@ -67,8 +67,8 @@ def default_api_path
end

def ensure_managers
build_configuration_manager unless configuration_manager
configuration_manager.name = _("%{name} Configuration Manager") % {:name => name}
configuration_manager.zone_id = zone_id
build_automation_manager unless automation_manager
automation_manager.name = _("%{name} Automation Manager") % {:name => name}
automation_manager.zone_id = zone_id
end
end
25 changes: 25 additions & 0 deletions app/models/manageiq/providers/automation_manager.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class ManageIQ::Providers::AutomationManager < ::ExtManagementSystem
require_nested :InventoryGroup
require_nested :InventoryRootGroup

has_many :configured_systems, :dependent => :destroy, :foreign_key => "manager_id"
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 :configuration_script_sources, :dependent => :destroy, :foreign_key => "manager_id"

virtual_column :total_configuration_profiles, :type => :integer
virtual_column :total_configured_systems, :type => :integer

def self.hostname_required?
false
end

def total_configuration_profiles
Rbac.filtered(configuration_profiles, :match_via_descendants => ConfiguredSystem).count
end

def total_configured_systems
Rbac.filtered(configured_systems, :match_via_descendants => ConfiguredSystem).count
end
end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ManageIQ::Providers::ConfigurationManager::InventoryGroup < EmsFolder
belongs_to :manager, :foreign_key => "ems_id", :class_name => "ManageIQ::Providers::ConfigurationManager"
class ManageIQ::Providers::AutomationManager::InventoryGroup < EmsFolder
belongs_to :manager, :foreign_key => "ems_id", :class_name => "ManageIQ::Providers::AutomationManager"

virtual_column :total_configured_systems, :type => :integer

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class ManageIQ::Providers::ConfigurationManager::InventoryRootGroup < ManageIQ::Providers::ConfigurationManager::InventoryGroup
class ManageIQ::Providers::AutomationManager::InventoryRootGroup < ManageIQ::Providers::AutomationManager::InventoryGroup
has_many :configuration_scripts
has_many :configured_systems

Expand Down
4 changes: 0 additions & 4 deletions app/models/manageiq/providers/configuration_manager.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class ManageIQ::Providers::ConfigurationManager < ::ExtManagementSystem
require_nested :InventoryGroup
require_nested :InventoryRootGroup

has_many :configured_systems, :dependent => :destroy, :foreign_key => "manager_id"
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 :configuration_script_sources, :dependent => :destroy, :foreign_key => "manager_id"

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

0 comments on commit 2f0ef1a

Please sign in to comment.