Skip to content
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

Pass event_target and event_name to Ansible #14481

Merged
merged 2 commits into from
Mar 27, 2017

Conversation

mkanoor
Copy link
Contributor

@mkanoor mkanoor commented Mar 23, 2017

Pass event_target and event_name to Ansible playbooks. The event_source is passed in as a slug

https://www.pivotaltracker.com/n/projects/1937537/stories/141706313

screen shot 2017-03-27 at 12 36 31 pm

service_template.provision_request(target_user(rec), options)
dialog_options = { :dialog_hosts => target_hosts(action, rec) }
request_options = { :extra_vars => { 'event_source' => rec.href_slug,
'event_name' => inputs[:event].try(:name) },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use event_type instead of event_name to be consistent with what is normally used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lfu the event_type doesn't have much information since it comes up as Default for most of the miq_event.
screen shot 2017-03-24 at 11 05 14 am

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor What I meant is the field event_name under extra_vars, not the column in event object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lfu The attribute is "name" so why would we call it "event_type"?

@@ -400,8 +400,8 @@ def self.create_from_options(options)
end
private_class_method :create_from_options

def provision_request(user, options = nil)
provision_workflow(user, options).submit_request
def provision_request(user, options = nil, request_options = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def provision_request(user, dialog_options = {}, request_options = {}

My personal preference is a method name starting with a verb, e.g. def make_provision_request. A method name with noun is like a getter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei
#13972 implemented this method to "get" a provision_request from a service template.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. It is not a simple get (read only), it actually makes a request. Since it was introduced not long ago, we can refactor it. It is my recommendation, not a have_to_fix issue.

def provision_workflow(user, options = nil)
options ||= {}
ra_options = { :target => self, :initiator => options[:initiator] }
def provision_workflow(user, dialog_options = nil, request_options = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a private method, we don't need default values for arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei
provision_workflow is not a private method its going to be called by the REST API. This was done intentionally in #13972 so that the REST API can switch overt to using this. From the Rest API they first create a workflow and then submit the request at at later time. In our case when we order the service we want to create the request and immediately submit the request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently provision_workflow is private. If you want to promote it public, you need to move up the code.

create_values_hash.tap { |value| value[:src_id] = @target.id }
create_values_hash.tap do |value|
value[:src_id] = @target.id
value[:request_options] = @request_options if @request_options.any?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value[:request_options] = request_options unless request_options.blank?
You don't need to line 14 @request_opitons = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzwei how would some one set the request_options. I have the attr_accessor method used to set the request _options, which saves it in an instance variable (@request_options)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you already added it as attr_accessor, you can reference it (get or set) through request_options without explicitly using @request_options

end

def request_options_extra_vars
ro = miq_request_task.options[:request_options] || {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

miq_request_task.options.fetch_path(:request_options, :extra_vars) || {}.
:extra_vars needs to be replaced with :manageiq_extra_vars or :extra_vars, 'manageiq' if we agree with the other comment.

:initiator => 'control' }
service_template.provision_request(target_user(rec), options)
dialog_options = { :dialog_hosts => target_hosts(action, rec) }
request_options = { :extra_vars => { 'event_source' => rec.href_slug,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{ :manageiq_extra_vars => { 'event_source' => rec.href_slug, ...
or
{ :extra_vars => { 'manageiq' => {'event_source' => rec.href_slug, ...

@mkanoor mkanoor force-pushed the send_control_info branch from 67a0c86 to 8297933 Compare March 24, 2017 16:50
@gmcculloug
Copy link
Member

@Fryguy @blomquisg Wondering if you have any thoughts on using the term "event_source" here.

I usually think of the event source as the provider, and the object the event is raised for as the target. But I can easily see how the term "source" could be valid here as well.

My only thought is that the event_stream uses the polymorphic target association to point to the object the event was raised for, so I tend to lean toward that term for consistency.

@miq-bot
Copy link
Member

miq-bot commented Mar 25, 2017

This pull request is not mergeable. Please rebase and repush.

@mkanoor
Copy link
Contributor Author

mkanoor commented Mar 27, 2017

@gmcculloug @Fryguy
Changed to event_target after discussion with @gmcculloug and @Fryguy

@mkanoor mkanoor changed the title Pass event_source and event_name to Ansible Pass event_target and event_name to Ansible Mar 27, 2017
@miq-bot
Copy link
Member

miq-bot commented Mar 27, 2017

Checked commits mkanoor/manageiq@e7f0305~...abdc35e with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
7 files checked, 0 offenses detected
Everything looks good. 🏆

@mkanoor
Copy link
Contributor Author

mkanoor commented Mar 27, 2017

@gmcculloug Please review

provision_workflow(user, options, request_options).submit_request
end

def provision_workflow(user, dialog_options = nil, request_options = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor Was there a reason this method was moved out of the private method section?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug It was one of bill's feedback to make the function public since its needed by the REST API

@gmcculloug gmcculloug merged commit 098d59f into ManageIQ:master Mar 27, 2017
@gmcculloug gmcculloug added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants