|
1 | | -class ServiceTemplateAnsibleTower < ServiceTemplate |
2 | | - include ServiceConfigurationMixin |
3 | | - include ServiceTemplateAutomationMixin |
| 1 | +ServiceTemplateAwx.include(ActsAsStiLeafClass) |
4 | 2 |
|
5 | | - before_update :remove_invalid_resource |
6 | | - |
7 | | - alias job_template configuration_script |
8 | | - alias job_template= configuration_script= |
9 | | - |
10 | | - def self.create_catalog_item(options, _auth_user = nil) |
11 | | - transaction do |
12 | | - create_from_options(options).tap do |service_template| |
13 | | - config_info = validate_config_info(options) |
14 | | - |
15 | | - service_template.job_template = if config_info[:configuration_script_id] |
16 | | - ConfigurationScript.find(config_info[:configuration_script_id]) |
17 | | - else |
18 | | - config_info[:configuration] |
19 | | - end |
20 | | - |
21 | | - service_template.create_resource_actions(config_info) |
22 | | - end |
23 | | - end |
24 | | - end |
25 | | - |
26 | | - def remove_invalid_resource |
27 | | - # remove the resource from both memory and table |
28 | | - service_resources.to_a.delete_if do |r| |
29 | | - r.reload if r.persisted? |
30 | | - r.destroy if r.resource.blank? |
31 | | - end |
32 | | - end |
33 | | - |
34 | | - def create_subtasks(_parent_service_task, _parent_service) |
35 | | - # no sub task is needed for this service |
36 | | - [] |
37 | | - end |
38 | | - |
39 | | - def self.default_provisioning_entry_point(_service_type) |
40 | | - '/AutomationManagement/AnsibleTower/Service/Provisioning/StateMachines/Provision/CatalogItemInitialization' |
41 | | - end |
42 | | - |
43 | | - def self.default_reconfiguration_entry_point |
44 | | - nil |
45 | | - end |
46 | | - |
47 | | - def self.default_retirement_entry_point |
48 | | - nil |
49 | | - end |
50 | | - |
51 | | - def self.validate_config_info(options) |
52 | | - config_info = options[:config_info] |
53 | | - unless config_info[:configuration_script_id] || config_info[:configuration] |
54 | | - raise _('Must provide configuration_script_id or configuration') |
55 | | - end |
56 | | - |
57 | | - config_info |
58 | | - end |
59 | | - |
60 | | - def my_zone |
61 | | - job_template.manager.try(:my_zone) |
62 | | - end |
63 | | - |
64 | | - private |
65 | | - |
66 | | - def update_service_resources(config_info, _auth_user = nil) |
67 | | - if config_info[:configuration_script_id] && config_info[:configuration_script_id] != job_template.try(:id) |
68 | | - service_resources.find_by(:resource_type => 'ConfigurationScriptBase').destroy |
69 | | - self.job_template = ConfigurationScriptBase.find(config_info[:configuration_script_id]) |
70 | | - elsif config_info[:configuration] && config_info[:configuration] != job_template.try(:id) |
71 | | - service_resources.find_by(:resource_type => 'ConfigurationScriptBase').destroy |
72 | | - self.job_template = config_info[:configuration] |
73 | | - end |
74 | | - end |
75 | | - |
76 | | - def validate_update_config_info(options) |
77 | | - super |
78 | | - return unless options.key?(:config_info) |
79 | | - |
80 | | - self.class.validate_config_info(options) |
81 | | - end |
82 | | - |
83 | | - def construct_config_info |
84 | | - config_info = {} |
85 | | - config_info[:configuration_script_id] = job_template.id if job_template |
86 | | - config_info.merge!(resource_actions_info) |
87 | | - end |
| 3 | +class ServiceTemplateAnsibleTower < ServiceTemplateAwx |
88 | 4 | end |
0 commit comments