forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_template_provision_request.rb
93 lines (72 loc) · 2.6 KB
/
service_template_provision_request.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class ServiceTemplateProvisionRequest < MiqRequest
TASK_DESCRIPTION = N_('Service_Template_Provisioning')
SOURCE_CLASS_NAME = 'ServiceTemplate'
ACTIVE_STATES = %w[migrated] + base_class::ACTIVE_STATES
SERVICE_ORDER_CLASS = '::ServiceOrderCart'.freeze
validates_inclusion_of :request_state, :in => %w[pending finished] + ACTIVE_STATES, :message => "should be pending, #{ACTIVE_STATES.join(", ")} or finished"
validate :must_have_user
after_create :process_service_order
alias_method :service_template, :source
alias_method :service_template=, :source=
virtual_has_one :picture
virtual_has_one :service_template
virtual_has_one :provision_dialog
virtual_has_one :user
default_value_for(:source_id) { |r| r.get_option(:src_id) }
default_value_for :source_type, SOURCE_CLASS_NAME
default_value_for :process, false
delegate :picture, :to => :service_template, :allow_nil => true
alias_method :user, :get_user
include MiqProvisionQuotaMixin
def process_service_order
if cancel_requested?
do_cancel
return
end
case options[:cart_state]
when ServiceOrder::STATE_ORDERED
ServiceOrder.order_immediately(self, requester)
when ServiceOrder::STATE_CART
ServiceOrder.add_to_cart(self, requester)
end
end
def my_role(action = nil)
action == :create_request_tasks ? 'automate' : 'ems_operations'
end
def my_zone
@my_zone ||= dialog_zone || service_template.my_zone
end
def provision_dialog
request_dialog("Provision")
end
def requested_task_idx
[0]
end
def customize_request_task_attributes(req_task_attrs, idx)
req_task_attrs['options'][:pass] = idx
configuration_script_id = resource_action&.configuration_script_id
return if configuration_script_id.nil?
# If the service_template that we are provisioning is a "generic" provision
# type then we want to execute the request task with embedded_workflows if
# the resource_action has a configuration_script_id
if source.prov_type == "generic"
req_task_attrs['options'][:configuration_script_payload_id] = configuration_script_id
else
req_task_attrs['options'][:parent_configuration_script_payload_id] = configuration_script_id
end
end
def resource_action
resource_action_id = options.dig(:workflow_settings, :resource_action_id)
return if resource_action_id.nil?
ResourceAction.find(resource_action_id)
end
def originating_controller
"service"
end
def my_records
"#{self.class::SOURCE_CLASS_NAME}:#{get_option(:src_id)}"
end
def process_on_create?
false
end
end