foreman_acd 0.0.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -56
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +124 -0
  4. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +72 -0
  5. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +2 -2
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +46 -9
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +96 -90
  9. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
  10. data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
  11. data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
  12. data/app/controllers/foreman_acd/remote_execution_controller.rb +46 -0
  13. data/app/controllers/ui_acd_controller.rb +20 -4
  14. data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +42 -0
  15. data/app/lib/actions/foreman_acd/run_configurator.rb +41 -0
  16. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
  17. data/app/models/foreman_acd/acd_provider.rb +30 -0
  18. data/app/models/foreman_acd/ansible_playbook.rb +67 -0
  19. data/app/models/foreman_acd/app_definition.rb +25 -1
  20. data/app/models/foreman_acd/app_instance.rb +42 -0
  21. data/app/models/foreman_acd/foreman_host.rb +23 -0
  22. data/app/models/foreman_acd/taxonomy_extensions.rb +17 -0
  23. data/app/services/foreman_acd/app_configurator.rb +54 -0
  24. data/app/services/foreman_acd/app_deployer.rb +151 -0
  25. data/app/services/foreman_acd/inventory_creator.rb +54 -0
  26. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +30 -0
  27. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
  28. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  29. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  30. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
  31. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
  32. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
  33. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
  34. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
  35. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
  36. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
  37. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
  38. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
  39. data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -20
  40. data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
  41. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  42. data/app/views/foreman_acd/app_definitions/index.html.erb +10 -6
  43. data/app/views/foreman_acd/app_instances/_form.html.erb +12 -10
  44. data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
  45. data/app/views/foreman_acd/app_instances/index.html.erb +87 -9
  46. data/app/views/foreman_acd/app_instances/report.html.erb +22 -0
  47. data/app/views/templates/job/run_acd_ansible_playbook.erb +62 -0
  48. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  49. data/app/views/ui_acd/app.json.rabl +6 -2
  50. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  51. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  52. data/config/routes.rb +35 -1
  53. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  54. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  55. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  56. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  57. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
  58. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
  59. data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
  60. data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
  61. data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
  62. data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
  63. data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
  64. data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
  65. data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
  66. data/db/seeds.d/62_acd_proxy_feature.rb +4 -0
  67. data/db/seeds.d/75-job_templates.rb +13 -0
  68. data/lib/foreman_acd/engine.rb +21 -3
  69. data/lib/foreman_acd/plugin.rb +112 -20
  70. data/lib/foreman_acd/version.rb +1 -1
  71. data/locale/en/foreman_acd.edit.po +326 -0
  72. data/locale/en/foreman_acd.po +232 -2
  73. data/locale/en/foreman_acd.po.time_stamp +0 -0
  74. data/locale/foreman_acd.pot +343 -8
  75. data/package.json +1 -1
  76. data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
  77. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +391 -0
  78. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  79. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +303 -0
  80. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +15 -0
  81. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  82. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +269 -0
  83. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +9 -0
  84. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  85. data/webpack/components/ApplicationDefinition/index.js +35 -0
  86. data/webpack/components/ApplicationInstance/ApplicationInstance.js +451 -0
  87. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  88. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +247 -0
  89. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +15 -0
  90. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +309 -0
  91. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +10 -0
  92. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  93. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  94. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  95. data/webpack/components/ApplicationInstance/index.js +37 -0
  96. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +148 -0
  97. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +44 -0
  98. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +42 -0
  99. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -0
  100. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +38 -0
  101. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
  102. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  103. data/webpack/components/ApplicationInstanceReport/index.js +25 -0
  104. data/webpack/components/ParameterSelection/ParameterSelection.js +131 -192
  105. data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
  106. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +87 -110
  107. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
  108. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  109. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
  110. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  111. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  112. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  113. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  114. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  115. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  116. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  117. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  118. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  119. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  120. data/webpack/components/ParameterSelection/index.js +6 -8
  121. data/webpack/components/common/AddTableEntry.js +30 -0
  122. data/webpack/components/common/DeleteTableEntry.js +39 -0
  123. data/webpack/components/common/EasyHeaderFormatter.js +18 -0
  124. data/webpack/components/common/EditTableEntry.js +50 -0
  125. data/webpack/components/common/ExtSelect.js +43 -0
  126. data/webpack/components/common/LockTableEntry.js +60 -0
  127. data/webpack/components/common/RailsData.js +27 -0
  128. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  129. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  130. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  131. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  132. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  133. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  134. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  135. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  136. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  137. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  138. data/webpack/helper.js +20 -0
  139. data/webpack/index.js +6 -0
  140. data/webpack/reducer.js +43 -3
  141. metadata +114 -20
@@ -6,33 +6,42 @@ module ForemanAcd
6
6
  include Foreman::Controller::AutoCompleteSearch
7
7
  include ::ForemanAcd::Concerns::AppDefinitionParameters
8
8
 
9
- before_action :find_resource, :only => [:edit, :update, :destroy]
9
+ before_action :find_resource, :only => [:edit, :update, :destroy, :export]
10
+ before_action :read_hostgroups, :only => [:edit, :new, :import]
11
+ before_action :read_ansible_playbooks, :only => [:edit, :new]
12
+ before_action :handle_file_upload, :only => [:create]
10
13
 
11
14
  def index
12
15
  @app_definitions = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
13
16
  end
14
17
 
18
+ def read_ansible_playbooks
19
+ # Only use ansible playbooks for which the user pressed import group vars once.
20
+ @ansible_playbooks = AnsiblePlaybook.where.not(:vars => nil).map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
21
+ end
22
+
15
23
  def read_hostgroups
16
24
  @hostgroups = Hostgroup.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
17
25
  end
18
26
 
19
27
  def new
20
- read_hostgroups
21
28
  @app_definition = AppDefinition.new
22
29
  end
23
30
 
24
31
  def create
25
32
  @app_definition = AppDefinition.new(app_definition_params)
26
- if @app_definition.save
27
- process_success
28
- else
29
- process_error
33
+ begin
34
+ if @app_definition.save!
35
+ process_success
36
+ else
37
+ process_error
38
+ end
39
+ rescue StandardError, ValidationError => e
40
+ redirect_to new_app_definition_path, :flash => { :error => _(e.message) }
30
41
  end
31
42
  end
32
43
 
33
- def edit
34
- read_hostgroups
35
- end
44
+ def edit; end
36
45
 
37
46
  def update
38
47
  if @app_definition.update(app_definition_params)
@@ -49,5 +58,33 @@ module ForemanAcd
49
58
  process_error
50
59
  end
51
60
  end
61
+
62
+ def action_permission
63
+ case params[:action]
64
+ when 'export'
65
+ :export
66
+ when 'import'
67
+ :import
68
+ else
69
+ super
70
+ end
71
+ end
72
+
73
+ def import
74
+ @app_definition = AppDefinition.new
75
+ end
76
+
77
+ def export
78
+ filename = "#{@app_definition.name}.yaml"
79
+ data = JSON.parse(@app_definition.services).to_yaml
80
+ send_data data, :type => 'text/yaml', :disposition => 'attachment', :filename => filename
81
+ end
82
+
83
+ private
84
+
85
+ def handle_file_upload
86
+ return unless params[:foreman_acd_app_definition] && (raw_file = params[:foreman_acd_app_definition][:app_definition_file])
87
+ params[:foreman_acd_app_definition][:services] = YAML.load_file(raw_file.tempfile).to_json
88
+ end
52
89
  end
53
90
  end
@@ -6,45 +6,53 @@ module ForemanAcd
6
6
  include Foreman::Controller::AutoCompleteSearch
7
7
  include ::ForemanAcd::Concerns::AppInstanceParameters
8
8
 
9
- before_action :find_resource, :only => [:edit, :update, :destroy, :deploy]
9
+ before_action :find_resource, :only => [:edit, :update, :destroy_with_hosts, :deploy, :report]
10
+ before_action :read_applications, :only => [:new, :edit]
11
+ before_action :find_taxonomy
12
+ helper_method :collect_hosts_data
10
13
 
11
14
  def index
12
- @app_instances = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
13
- end
14
-
15
- def read_applications
16
- @applications = ForemanAcd::AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
15
+ @app_instances = resource_base.where(:organization => @organization).
16
+ where(:location => @location).
17
+ search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
17
18
  end
18
19
 
19
20
  def new
20
21
  @app_instance = AppInstance.new
21
- read_applications
22
+ @app_instance.organization = @organization
23
+ @app_instance.location = @location
22
24
  end
23
25
 
24
26
  def create
25
27
  @app_instance = AppInstance.new(app_instance_params)
26
- if @app_instance.save
27
- process_success
28
- else
29
- process_error
28
+ begin
29
+ if @app_instance.save!
30
+ app_instance_has_foreman_hosts
31
+ process_success
32
+ else
33
+ process_error
34
+ end
35
+ rescue StandardError, ValidationError => e
36
+ redirect_to new_app_instance_path, :flash => { :error => _(e.message) }
30
37
  end
31
38
  end
32
39
 
33
- def edit
34
- read_applications
35
- end
40
+ def edit; end
36
41
 
37
42
  def update
38
43
  if @app_instance.update(app_instance_params)
44
+ app_instance_has_foreman_hosts
39
45
  process_success
40
46
  else
41
47
  process_error
42
48
  end
43
49
  end
44
50
 
45
- def destroy
51
+ def destroy_with_hosts
52
+ @app_instance = AppInstance.find(params[:id])
53
+ @app_instance.clean_hosts_by_id(params[:foreman_host_ids]) if params[:foreman_host_ids]
46
54
  if @app_instance.destroy
47
- process_success
55
+ redirect_to app_instances_path, :flash => { :success => _('Successfully deleted %s') % @app_instance }
48
56
  else
49
57
  process_error
50
58
  end
@@ -54,105 +62,103 @@ module ForemanAcd
54
62
  case params[:action]
55
63
  when 'deploy'
56
64
  :deploy
65
+ when 'report'
66
+ :report
67
+ when 'destroy_with_hosts'
68
+ :destroy
57
69
  else
58
70
  super
59
71
  end
60
72
  end
61
73
 
62
74
  def deploy
63
- params = host_attributes(set_host_params)
75
+ @app_instance.clean_all_hosts if params[:delete_hosts]
64
76
 
65
- # Print to log for debugging purposes
66
- logger.info("Host creation parameters:\n#{params}\n")
67
-
68
- @host = Host.new(params)
69
- apply_compute_profile(@host)
70
- @host.suggest_default_pxe_loader
71
- @host.save
72
- success _('Successfully initiated host creation')
77
+ logger.info('Run async foreman task to deploy hosts')
78
+ async_task = ForemanTasks.async_task(::Actions::ForemanAcd::DeployAllHosts, @app_instance)
79
+ @app_instance.update!(:last_deploy_task => async_task)
80
+ process_success(:success_msg => _('Started task to deploy hosts for %s') % @app_instance)
73
81
  rescue StandardError => e
74
- logger.error("Failed to initiate host creation: #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}")
75
- ensure
76
- redirect_to app_instances_path
82
+ error_msg = "Error happend while deploying hosts of #{@app_instance}: #{e.message}"
83
+ logger.error("#{error_msg} - #{e.class}\n#{e.backtrace.join($INPUT_RECORD_SEPARATOR)}")
84
+ process_error :error_msg => error_msg
77
85
  end
78
86
 
79
- private
80
-
81
- # Copied from foreman/app/controllers/api/v2/hosts_controller.rb
82
- def apply_compute_profile(host)
83
- host.apply_compute_profile(InterfaceMerge.new(:merge_compute_attributes => true))
84
- host.apply_compute_profile(ComputeAttributeMerge.new)
87
+ def report
88
+ @report_hosts = collect_host_report_data
89
+ logger.debug("app instance host details: #{@report_hosts.inspect}")
85
90
  end
86
91
 
87
- # Copied from foreman/app/controllers/api/v2/hosts_controller.rb
88
- def host_attributes(params, host = nil)
89
- return {} if params.nil?
90
-
91
- params = params.deep_clone
92
- if params[:interfaces_attributes]
93
- # handle both hash and array styles of nested attributes
94
- params[:interfaces_attributes] = params[:interfaces_attributes].values if params[:interfaces_attributes].is_a?(Hash) || params[:interfaces_attributes].is_a?(ActionController::Parameters)
95
- # map interface types
96
- params[:interfaces_attributes] = params[:interfaces_attributes].map do |nic_attr|
97
- interface_attributes(nic_attr, :allow_nil_type => host.nil?)
92
+ def app_instance_has_foreman_hosts
93
+ hosts = JSON.parse(@app_instance.hosts)
94
+ hosts.each do |h|
95
+ if @app_instance.foreman_hosts.where(:hostname => h['hostname']).exists?
96
+ @app_instance.foreman_hosts.where(:hostname => h['hostname']).
97
+ update(:service => h['service'], :description => h['description'],
98
+ :foremanParameters => JSON.dump(h['foremanParameters']), :ansibleParameters => JSON.dump(h['ansibleParameters']))
99
+ else
100
+ @app_instance.foreman_hosts.create(:hostname => h['hostname'], :service => h['service'], :description => h['description'],
101
+ :foremanParameters => JSON.dump(h['foremanParameters']), :ansibleParameters => JSON.dump(h['ansibleParameters']))
98
102
  end
99
103
  end
100
- params = host.apply_inherited_attributes(params) if host
101
- params
102
- end
103
104
 
104
- # Copied from foreman/app/controllers/api/v2/hosts_controller.rb
105
- def interface_attributes(params, allow_nil_type: false)
106
- params[:type] = InterfaceTypeMapper.map(params[:type]) if params.key?(:type) || allow_nil_type
107
- params
105
+ # Delete record if json hosts are deleted
106
+ deleted_json_hosts = @app_instance.foreman_hosts.pluck('hostname') - hosts.pluck('hostname')
107
+ @app_instance.foreman_hosts.where(:hostname => deleted_json_hosts).destroy_all if deleted_json_hosts
108
108
  end
109
109
 
110
- def hardcoded_params
111
- result = {}
112
- result['managed'] = true
113
- result['enabled'] = true
114
- result['build'] = true
115
- result['compute_attributes'] = { 'start' => '1' }
116
- result['host_parameters_attributes'] = []
117
- result
110
+ def collect_hosts_data
111
+ hosts_data = []
112
+ @app_instance.foreman_hosts.each do |h|
113
+ hosts_data << {
114
+ :id => h.id,
115
+ :hostname => h.hostname,
116
+ :service => h.service,
117
+ :description => h.description,
118
+ :foremanParameters => JSON.parse(h.foremanParameters),
119
+ :ansibleParameters => JSON.parse(h.ansibleParameters)
120
+ }
121
+ end
122
+ hosts_data
118
123
  end
119
124
 
120
- def set_host_params
121
- result = hardcoded_params
122
- result['hostgroup_id'] = @app_instance.app_definition.hostgroup_id
123
- JSON.parse(@app_instance.parameters).each do |param|
124
- case param['type']
125
-
126
- when 'computeprofile'
127
- result['compute_profile_id'] = param['value']
128
-
129
- when 'domain'
130
- result['domain_id'] = param['value']
131
-
132
- when 'hostname'
133
- result['name'] = param['value']
134
-
135
- when 'hostparam'
136
- result['host_parameters_attributes'].push(:name => param['name'], :value => param['value'])
137
-
138
- when 'ip'
139
- result['ip'] = param['value']
140
-
141
- when 'lifecycleenv'
142
- result['content_facet_attributes'] = { 'lifecycle_environment_id' => param['value'] }
125
+ private
143
126
 
144
- when 'ptable'
145
- result['ptable_id'] = param['value']
127
+ def find_taxonomy
128
+ @organization = Organization.current
129
+ redirect_to '/select_organization?toState=' + request.path and return unless @organization
146
130
 
147
- when 'puppetenv'
148
- result['environment_id'] = param['value']
131
+ @location = Location.current
132
+ redirect_to root_path, :error => 'Select a location to show App Instances' and return unless @location
133
+ end
149
134
 
150
- when 'password'
151
- result['root_pass'] = param['value']
135
+ def read_applications
136
+ @applications = AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
137
+ end
152
138
 
139
+ def collect_host_report_data
140
+ report_data = []
141
+
142
+ @app_instance.foreman_hosts.each do |foreman_host|
143
+ a_host = {
144
+ :id => nil,
145
+ :name => foreman_host.hostname,
146
+ :build => nil,
147
+ :hostUrl => nil,
148
+ :progress_report => foreman_host.last_progress_report.empty? ? [] : JSON.parse(foreman_host.last_progress_report)
149
+ }
150
+
151
+ if foreman_host.host.present?
152
+ a_host.update({
153
+ :id => foreman_host.host.id,
154
+ :build => foreman_host.host.build,
155
+ :hostUrl => host_path(foreman_host.host),
156
+ :powerStatusUrl => power_api_host_path(foreman_host.host)
157
+ })
153
158
  end
159
+ report_data << a_host
154
160
  end
155
- result
161
+ report_data
156
162
  end
157
163
  end
158
164
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ module Concerns
5
+ # Parameters for AnsiblePlaybooks
6
+ module AnsiblePlaybookParameters
7
+ extend ActiveSupport::Concern
8
+
9
+ class_methods do
10
+ def ansible_playbook_params_filter
11
+ Foreman::ParameterFilter.new(::ForemanAcd::AnsiblePlaybook).tap do |filter|
12
+ filter.permit(:name, :description, :scm_type, :path, :playfile, :location_ids => [], :organization_ids => [])
13
+ end
14
+ end
15
+ end
16
+
17
+ def ansible_playbook_params
18
+ param_name = parameter_filter_context.api? ? 'ansible_playbook' : 'foreman_acd_ansible_playbook'
19
+ self.class.ansible_playbook_params_filter.filter_params(params, parameter_filter_context, param_name)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -9,7 +9,7 @@ module ForemanAcd
9
9
  class_methods do
10
10
  def app_definition_params_filter
11
11
  Foreman::ParameterFilter.new(::ForemanAcd::AppDefinition).tap do |filter|
12
- filter.permit(:name, :description, :hostgroup_id, :parameters)
12
+ filter.permit(:name, :description, :acd_ansible_playbook_id, :services, :ansible_vars_all, :location_ids => [], :organization_ids => [])
13
13
  end
14
14
  end
15
15
  end
@@ -9,7 +9,7 @@ module ForemanAcd
9
9
  class_methods do
10
10
  def app_instance_params_filter
11
11
  Foreman::ParameterFilter.new(::ForemanAcd::AppInstance).tap do |filter|
12
- filter.permit(:name, :app_definition_id, :description, :parameters)
12
+ filter.permit(:name, :app_definition_id, :description, :hosts, :ansible_vars_all, :organization_id, :location_id)
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ # Class to run remote execution jobs
5
+ class RemoteExecutionController < JobInvocationsController
6
+ def new
7
+ jobs = init_configuration
8
+ @composer = jobs.first
9
+ end
10
+
11
+ def create
12
+ customize_first = params[:customize] || false
13
+ jobs = init_configuration
14
+
15
+ if jobs.count == 1 && customize_first == false
16
+ @composer = jobs.first
17
+ @composer.trigger!
18
+ redirect_to job_invocation_path(@composer.job_invocation)
19
+ elsif customize_first == false
20
+ jobs.each(&:trigger)
21
+ redirect_to job_invocations_path
22
+ else
23
+ # redirect to the job itself if we want to customize the job
24
+ @composer = jobs.first
25
+ render :action => 'new'
26
+ end
27
+ end
28
+
29
+ # to overcome the isolated namespace engine difficulties with paths
30
+ helper Rails.application.routes.url_helpers
31
+ def _routes
32
+ Rails.application.routes
33
+ end
34
+
35
+ private
36
+
37
+ def init_configuration
38
+ app_instance = ForemanAcd::AppInstance.find_by(:id => params[:id])
39
+ app_configurator = ForemanAcd::AppConfigurator.new(app_instance)
40
+
41
+ jobs = app_configurator.configure
42
+ logger.debug("Creating #{jobs.count} job(s) to configure the app #{app_instance}. Customize first: #{params[:customize]}")
43
+ jobs
44
+ end
45
+ end
46
+ end
@@ -6,16 +6,28 @@ class UiAcdController < ::Api::V2::BaseController
6
6
  @app_data = {}
7
7
  app_definition = ForemanAcd::AppDefinition.find(params[:id])
8
8
  @app_data['app_definition'] = app_definition
9
- @app_data['fdata'] = collect_fdata(app_definition.hostgroup_id)
10
9
  end
11
10
 
12
- def fdata
13
- @fdata = collect_fdata(params['id'])
11
+ def foreman_data
12
+ @foreman_data = collect_foreman_data(params['id'])
13
+ end
14
+
15
+ def ansible_data
16
+ @ansible_data = collect_ansible_data(params['id'])
17
+ end
18
+
19
+ def action_permission
20
+ case params[:action]
21
+ when 'app', 'foreman_data', 'ansible_data'
22
+ :view
23
+ else
24
+ super
25
+ end
14
26
  end
15
27
 
16
28
  private
17
29
 
18
- def collect_fdata(hostgroup_id)
30
+ def collect_foreman_data(hostgroup_id)
19
31
  hg = Hostgroup.find(hostgroup_id)
20
32
  fdata = OpenStruct.new(
21
33
  :environments => Environment.all,
@@ -27,4 +39,8 @@ class UiAcdController < ::Api::V2::BaseController
27
39
  )
28
40
  fdata
29
41
  end
42
+
43
+ def collect_ansible_data(playbook_id)
44
+ ForemanAcd::AnsiblePlaybook.find(playbook_id).as_unified_structobj
45
+ end
30
46
  end