-
Notifications
You must be signed in to change notification settings - Fork 900
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
Conversation
app/models/miq_action.rb
Outdated
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) }, |
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.
Can we use event_type
instead of event_name
to be consistent with what is normally used?
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.
@lfu the event_type doesn't have much information since it comes up as Default for most of the miq_event.
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.
@mkanoor What I meant is the field event_name
under extra_vars
, not the column in event object.
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.
@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) |
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.
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.
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.
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.
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.
app/models/service_template.rb
Outdated
def provision_workflow(user, options = nil) | ||
options ||= {} | ||
ra_options = { :target => self, :initiator => options[:initiator] } | ||
def provision_workflow(user, dialog_options = nil, request_options = nil) |
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.
Since this is a private method, we don't need default values for arguments.
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.
@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.
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.
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? |
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.
value[:request_options] = request_options unless request_options.blank?
You don't need to line 14 @request_opitons = {}
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.
@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)?
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.
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] || {} |
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.
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.
app/models/miq_action.rb
Outdated
: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, |
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.
{ :manageiq_extra_vars => { 'event_source' => rec.href_slug, ...
or
{ :extra_vars => { 'manageiq' => {'event_source' => rec.href_slug, ...
67a0c86
to
8297933
Compare
@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 |
This pull request is not mergeable. Please rebase and repush. |
8297933
to
e7f0305
Compare
@gmcculloug @Fryguy |
Checked commits mkanoor/manageiq@e7f0305~...abdc35e with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@gmcculloug Please review |
provision_workflow(user, options, request_options).submit_request | ||
end | ||
|
||
def provision_workflow(user, dialog_options = nil, request_options = nil) |
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.
@mkanoor Was there a reason this method was moved out of the private
method section?
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.
@gmcculloug It was one of bill's feedback to make the function public since its needed by the REST API
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