diff --git a/app/models/miq_request_task.rb b/app/models/miq_request_task.rb index 9cf570dd977..ae1fe5e85af 100644 --- a/app/models/miq_request_task.rb +++ b/app/models/miq_request_task.rb @@ -139,7 +139,9 @@ def deliver_queue(req_type = request_type, zone = nil) _log.info("Queuing #{request_class::TASK_DESCRIPTION}: [#{description}]...") - if self.class::AUTOMATE_DRIVES + if resource_action&.configuration_script_payload + resource_action.configuration_script_payload.run(dialog_values, get_user.userid) + elsif self.class::AUTOMATE_DRIVES deliver_to_automate(req_type, zone) else execute_queue @@ -218,6 +220,11 @@ def execute end end + def resource_action + # Override in child class if the source has resource_actions + nil + end + def self.display_name(number = 1) n_('Request Task', 'Request Tasks', number) end @@ -251,4 +258,8 @@ def validate_state def valid_states %w(pending finished) + request_class::ACTIVE_STATES end + + def dialog_values + options[:dialog] || {} + end end diff --git a/app/models/service_reconfigure_task.rb b/app/models/service_reconfigure_task.rb index e4ac7a8e231..e146e865620 100644 --- a/app/models/service_reconfigure_task.rb +++ b/app/models/service_reconfigure_task.rb @@ -16,9 +16,7 @@ def after_request_task_create end def deliver_to_automate(req_type = request_type, zone = nil) - dialog_values = options[:dialog] || {} - - ra = source.service_template.resource_actions.find_by(:action => 'Reconfigure') + ra = resource_action if ra dialog_values["request"] = req_type args = { @@ -50,6 +48,10 @@ def deliver_to_automate(req_type = request_type, zone = nil) end end + def resource_action + @resource_action ||= source.service_template.resource_actions.find_by(:action => 'Reconfigure') + end + def after_ae_delivery(ae_result) _log.info("ae_result=#{ae_result.inspect}") diff --git a/app/models/service_template_provision_task.rb b/app/models/service_template_provision_task.rb index 36f248aab28..54e46c351a6 100644 --- a/app/models/service_template_provision_task.rb +++ b/app/models/service_template_provision_task.rb @@ -117,9 +117,6 @@ def do_post_provision end def deliver_to_automate(req_type = request_type, _zone = nil) - dialog_values = options[:dialog] || {} - dialog_values["request"] = req_type - args = { :object_type => self.class.name, :object_id => id, @@ -127,7 +124,7 @@ def deliver_to_automate(req_type = request_type, _zone = nil) :class_name => "ServiceProvision_Template", :instance_name => req_type, :automate_message => "create", - :attrs => dialog_values + :attrs => dialog_values.merge("request" => req_type) } # Automate entry point overrides from the resource_action @@ -158,7 +155,7 @@ def deliver_to_automate(req_type = request_type, _zone = nil) end def resource_action - source.resource_actions.detect { |ra| ra.action == 'Provision' } if source.respond_to?(:resource_actions) + @resource_action ||= source.resource_actions.find_by(:action => 'Provision') if source.respond_to?(:resource_actions) end def service_resource