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.
- checksums.yaml +4 -4
- data/README.md +107 -56
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +124 -0
- data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +72 -0
- data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +2 -2
- data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
- data/app/controllers/foreman_acd/app_definitions_controller.rb +46 -9
- data/app/controllers/foreman_acd/app_instances_controller.rb +96 -90
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
- data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
- data/app/controllers/foreman_acd/remote_execution_controller.rb +46 -0
- data/app/controllers/ui_acd_controller.rb +20 -4
- data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +42 -0
- data/app/lib/actions/foreman_acd/run_configurator.rb +41 -0
- data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
- data/app/models/foreman_acd/acd_provider.rb +30 -0
- data/app/models/foreman_acd/ansible_playbook.rb +67 -0
- data/app/models/foreman_acd/app_definition.rb +25 -1
- data/app/models/foreman_acd/app_instance.rb +42 -0
- data/app/models/foreman_acd/foreman_host.rb +23 -0
- data/app/models/foreman_acd/taxonomy_extensions.rb +17 -0
- data/app/services/foreman_acd/app_configurator.rb +54 -0
- data/app/services/foreman_acd/app_deployer.rb +151 -0
- data/app/services/foreman_acd/inventory_creator.rb +54 -0
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +30 -0
- data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
- data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
- data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
- data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
- data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
- data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -20
- data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
- data/app/views/foreman_acd/app_definitions/index.html.erb +10 -6
- data/app/views/foreman_acd/app_instances/_form.html.erb +12 -10
- data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_instances/index.html.erb +87 -9
- data/app/views/foreman_acd/app_instances/report.html.erb +22 -0
- data/app/views/templates/job/run_acd_ansible_playbook.erb +62 -0
- data/app/views/ui_acd/ansible_data.json.rabl +6 -0
- data/app/views/ui_acd/app.json.rabl +6 -2
- data/app/views/ui_acd/app_definition.json.rabl +1 -1
- data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
- data/config/routes.rb +35 -1
- data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
- data/db/migrate/20190625140305_create_app_instances.rb +1 -1
- data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
- data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
- data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
- data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
- data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
- data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
- data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
- data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
- data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
- data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
- data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
- data/db/seeds.d/62_acd_proxy_feature.rb +4 -0
- data/db/seeds.d/75-job_templates.rb +13 -0
- data/lib/foreman_acd/engine.rb +21 -3
- data/lib/foreman_acd/plugin.rb +112 -20
- data/lib/foreman_acd/version.rb +1 -1
- data/locale/en/foreman_acd.edit.po +326 -0
- data/locale/en/foreman_acd.po +232 -2
- data/locale/en/foreman_acd.po.time_stamp +0 -0
- data/locale/foreman_acd.pot +343 -8
- data/package.json +1 -1
- data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +391 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +303 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +15 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +269 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +9 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
- data/webpack/components/ApplicationDefinition/index.js +35 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +451 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +247 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +15 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +309 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +10 -0
- data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
- data/webpack/components/ApplicationInstance/components/Service.js +30 -0
- data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
- data/webpack/components/ApplicationInstance/index.js +37 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +148 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +44 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +42 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +38 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
- data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
- data/webpack/components/ApplicationInstanceReport/index.js +25 -0
- data/webpack/components/ParameterSelection/ParameterSelection.js +131 -192
- data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +87 -110
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
- data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
- data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
- data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
- data/webpack/components/ParameterSelection/index.js +6 -8
- data/webpack/components/common/AddTableEntry.js +30 -0
- data/webpack/components/common/DeleteTableEntry.js +39 -0
- data/webpack/components/common/EasyHeaderFormatter.js +18 -0
- data/webpack/components/common/EditTableEntry.js +50 -0
- data/webpack/components/common/ExtSelect.js +43 -0
- data/webpack/components/common/LockTableEntry.js +60 -0
- data/webpack/components/common/RailsData.js +27 -0
- data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
- data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
- data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
- data/webpack/components/common/__tests__/RailsData.test.js +16 -0
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
- data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
- data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
- data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
- data/webpack/helper.js +20 -0
- data/webpack/index.js +6 -0
- data/webpack/reducer.js +43 -3
- 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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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, :
|
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.
|
13
|
-
|
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
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
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
|
-
|
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
|
-
|
75
|
+
@app_instance.clean_all_hosts if params[:delete_hosts]
|
64
76
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
105
|
-
|
106
|
-
|
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
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
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
|
-
|
145
|
-
|
127
|
+
def find_taxonomy
|
128
|
+
@organization = Organization.current
|
129
|
+
redirect_to '/select_organization?toState=' + request.path and return unless @organization
|
146
130
|
|
147
|
-
|
148
|
-
|
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
|
-
|
151
|
-
|
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
|
-
|
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, :
|
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, :
|
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
|
13
|
-
@
|
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
|
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
|