Skip to content

Commit

Permalink
Merge pull request #22511 from agrare/service_order_configuration_scr…
Browse files Browse the repository at this point in the history
…ipts

Allow ConfigurationScripts to be used for ServiceTemplateProvisionTasks
  • Loading branch information
kbrock authored Jul 21, 2023
2 parents 06e9467 + 0a5fb30 commit b6aef66
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
13 changes: 12 additions & 1 deletion app/models/miq_request_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions app/models/service_reconfigure_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}")

Expand Down
7 changes: 2 additions & 5 deletions app/models/service_template_provision_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,14 @@ 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,
:namespace => "Service/Provisioning/StateMachines",
: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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b6aef66

Please sign in to comment.