-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create/Update/Delete Ansible Tower Projects and Credentials via queue #14305
Changes from 4 commits
a9303cd
ef933e8
013f57c
0ea77c4
144c8de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,36 +8,68 @@ 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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same basic comment. The |
||
end | ||
|
||
def delete_in_provider | ||
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}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -8,32 +8,64 @@ def create_in_provider(manager_id, params) | |||
connection.api.credentials.create!(params) | ||||
end | ||||
|
||||
refresh(manager) | ||||
find_by!(:resource_id => manager.id, :manager_ref => credential.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}") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
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!(:resource_id => manager.id, :manager_ref => credential.id) | ||||
end | ||||
|
||||
def create_in_provider_queue(manager_id, params) | ||||
def queue(zone, instance_id, method_name, args, action) | ||||
task_opts = { | ||||
:action => "Creating #{name}", | ||||
:action => action, | ||||
:userid => "system" | ||||
} | ||||
|
||||
manager = ExtManagementSystem.find(manager_id) | ||||
|
||||
queue_opts = { | ||||
:args => [manager_id, params], | ||||
:args => args, | ||||
:class_name => name, | ||||
:method_name => "create_in_provider", | ||||
:method_name => method_name, | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work for the instance methods. You'll have to pass in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See here: manageiq/app/models/miq_task.rb Line 210 in db29ce2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes!!! |
||||
: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 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 | ||||
resource.with_provider_connection do |connection| | ||||
connection.api.credentials.find(manager_ref).update_attributes!(params) | ||||
end | ||||
self.class.send('refresh', resource) | ||||
reload | ||||
end | ||||
|
||||
def update_in_provider_queue(params) | ||||
self.class.send('queue', resource.my_zone, id, "update_in_provider", [params], "Updating #{self.class.name}") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
end | ||||
|
||||
def delete_in_provider | ||||
resource.with_provider_connection do |connection| | ||||
connection.api.credentials.find(manager_ref).destroy! | ||||
end | ||||
self.class.send('refresh', resource) | ||||
end | ||||
|
||||
def delete_in_provider_queue | ||||
self.class.send('queue', resource.my_zone, id, "delete_in_provider", [], "Deleting #{self.class.name}") | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
end | ||||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last argument will be logged when creating the Queue item. Can you change that to include the
ems_ref
for the project being created? Something like"Creating #{name} with name #{params['name']}"
maybe...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@blomquisg
name
ormanager_ref
(the native Tower ID), orid
(vmdb record ID), which one is better?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So ended up using
name
here because this object is not created yet. Theupdate/delete
are usingmanager_ref
now. Done!