Skip to content

Commit

Permalink
Ansible Project to update/delete in Tower
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswnl committed Mar 13, 2017
1 parent a9303cd commit ef933e8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,69 @@ def create_in_provider(manager_id, params)
connection.api.projects.create!(params)
end

refresh(manager)
find_by!(:manager_id => manager.id, :manager_ref => project.id)
end

def create_in_provider_queue(manager_id, params)
manager = ExtManagementSystem.find(manager_id)
queue(manager.my_zone, nil, "create_in_provider", [manager_id, params], "Creating #{name}")
end

def provider_object(connection = nil)
(connection || connection_source.connect).api.projects.find(manager_ref)
end

private

def refresh(manager)
# Get the record in our database
# TODO: This needs to be targeted refresh so it doesn't take too long
task_ids = EmsRefresh.queue_refresh_task(manager)
task_ids.each { |tid| MiqTask.wait_for_taskid(tid) }

find_by!(:manager_id => manager.id, :manager_ref => project.id)
end

def create_in_provider_queue(manager_id, params)
def queue(zone, instance_id, method_name, args, action)
task_opts = {
:action => "Creating Ansible Tower Project",
:action => action,
:userid => "system"
}

manager = ExtManagementSystem.find(manager_id)

queue_opts = {
:args => [manager_id, params],
:class_name => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScriptSource",
:method_name => "create_in_provider",
:args => args,
:class_name => name,
:method_name => method_name,
:priority => MiqQueue::HIGH_PRIORITY,
:role => "ems_operations",
:zone => manager.my_zone
:zone => zone
}

queue_opts[:instance_id] = instance_id if instance_id
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end
end

def provider_object(connection = nil)
(connection || connection_source.connect).api.projects.find(manager_ref)
def update_in_provider(params)
params.delete(:task_id) # in case this is being called through update_in_provider_queue which will stick in a :task_id
manager.with_provider_connection do |connection|
connection.api.projects.find(manager_ref).update_attributes!(params)
end
self.class.send('refresh', manager)
reload!
end

def update_in_provider_queue(params)
self.class.send('queue', manager.my_zone, id, "update_in_provider", [params], "Updating #{self.class.name}")
end

def delete_in_provider
params.delete(:task_id) # in case this is being called through update_in_provider_queue which will stick in a :task_id
manager.with_provider_connection do |connection|
connection.api.projects.find(manager_ref).destroy!
end
self.class.send('refresh', manager)
end

def delete_in_provider_queue
self.class.send('queue', manager.my_zone, id, "delete_in_provider", [], "Deleting #{self.class.name}")
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
it ".create_in_provider_queue" do
EvmSpecHelper.local_miq_server
task_id = described_class.create_in_provider_queue(manager.id, params)
expect(MiqTask.find(task_id)).to have_attributes(:name => "Creating Ansible Tower Project")
expect(MiqTask.find(task_id)).to have_attributes(
:name => "Creating ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScriptSource"
)
expect(MiqQueue.first).to have_attributes(
:args => [manager.id, params],
:class_name => "ManageIQ::Providers::AnsibleTower::AutomationManager::ConfigurationScriptSource",
Expand Down

0 comments on commit ef933e8

Please sign in to comment.