-
Notifications
You must be signed in to change notification settings - Fork 900
/
Copy pathservice_ansible_tower.rb
63 lines (52 loc) · 2.05 KB
/
service_ansible_tower.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
class ServiceAnsibleTower < Service
include ServiceConfigurationMixin
include ServiceOrchestrationOptionsMixin
alias_method :job_template, :configuration_script
alias_method :job_template=, :configuration_script=
alias_method :job_options, :stack_options
alias_method :job_options=, :stack_options=
def launch_job
@job = ManageIQ::Providers::AnsibleTower::AutomationManager::Job.create_job(job_template, job_options)
add_resource(@job)
@job
ensure
# create options may never be saved before unless they were overridden
save_launch_options
end
def job
@job ||= service_resources.find { |sr| sr.resource.kind_of?(OrchestrationStack) }.try(:resource)
end
def build_stack_options_from_dialog(dialog_options)
{:extra_vars => extra_vars_from_dialog(dialog_options)}.tap do |launch_options|
launch_options[:limit] = dialog_options['dialog_limit'] unless dialog_options['dialog_limit'].blank?
end
end
private
# the method name is required by ServiceOrchestrationOptionMixin
def build_stack_create_options
# job template from dialog_options overrides the one copied from service_template
dialog_options = options[:dialog] || {}
if dialog_options['dialog_job_template']
self.job_template = ConfigurationScript.find(dialog_options['dialog_job_template'])
end
raise _("job template was not set") if job_template.nil?
build_stack_options_from_dialog(dialog_options)
end
def save_launch_options
options[:create_options] = dup_and_process_password(job_options)
save!
end
PARAM_PREFIX = 'dialog_param_'.freeze
PARAM_PREFIX_LEN = PARAM_PREFIX.size
PASSWORD_PREFIX = 'password::dialog_param_'.freeze
PASSWORD_PREFIX_LEN = PASSWORD_PREFIX.size
def extra_vars_from_dialog(dialog_options)
dialog_options.each_with_object({}) do |(attr, val), params|
if attr.start_with?(PARAM_PREFIX)
params[attr[PARAM_PREFIX_LEN..-1]] = val
elsif attr.start_with?(PASSWORD_PREFIX)
params[attr[PASSWORD_PREFIX_LEN..-1]] = MiqPassword.decrypt(val)
end
end
end
end