foreman_acd 0.0.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
- data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +54 -0
- data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
- data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
- data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
- data/app/controllers/foreman_acd/app_definitions_controller.rb +35 -4
- data/app/controllers/foreman_acd/app_instances_controller.rb +43 -87
- 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/ui_acd_controller.rb +11 -4
- data/app/models/foreman_acd/ansible_playbook.rb +50 -0
- data/app/models/foreman_acd/app_definition.rb +2 -1
- data/app/models/foreman_acd/app_instance.rb +7 -0
- data/app/services/foreman_acd/app_configurator.rb +70 -0
- data/app/services/foreman_acd/app_deployer.rb +143 -0
- data/app/services/foreman_acd/inventory_creator.rb +67 -0
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
- data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -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 +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
- data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
- data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
- data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
- data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
- data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
- data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
- data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
- data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
- data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
- data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -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 +31 -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 +5 -0
- data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
- data/db/seeds.d/75-job_templates.rb +8 -0
- data/lib/foreman_acd/engine.rb +3 -0
- data/lib/foreman_acd/plugin.rb +72 -4
- data/lib/foreman_acd/version.rb +1 -1
- data/package.json +2 -1
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +376 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
- data/webpack/components/ApplicationDefinition/index.js +33 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +412 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -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 +35 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
- data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
- data/webpack/components/ApplicationInstanceReport/index.js +27 -0
- data/webpack/components/ParameterSelection/ParameterSelection.js +96 -183
- data/webpack/components/ParameterSelection/ParameterSelection.scss +10 -3
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +72 -104
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +14 -19
- data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +100 -83
- 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/ExtSelect.js +43 -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 +85 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 63b0fc4a685be137bfd8d72d166d0c157081dc4c2ad34cbde4ac7e75faed4e1a
|
|
4
|
+
data.tar.gz: 9484df12c6738faa15f1b6d76721992b74a5ae0a795bbe6fc1f20cb08d3e7edd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 18caaab55b04561db5addf6d8376d37a4d7b043ccf7bba5cc98bb3d4fbc4b163b1a72416a5cffae556fa08626377dfa94608a0946d7009fd34a89989e96e9679
|
|
7
|
+
data.tar.gz: 7f00242c823cf86a6a315885009d19ed05b8215fbfd3b2d973a819aad716dfe576fdc719b8d3b1ea3f5c869fed1eb4b3647aa264aedcca8c6a0dc24fc237085f
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAcd
|
|
4
|
+
# Ansible Playbook Controller
|
|
5
|
+
class AnsiblePlaybooksController < ::ForemanAcd::ApplicationController
|
|
6
|
+
include Foreman::Controller::AutoCompleteSearch
|
|
7
|
+
include ::ForemanAcd::Concerns::AnsiblePlaybookParameters
|
|
8
|
+
|
|
9
|
+
before_action :find_resource, :only => [:edit, :update, :destroy, :import_vars]
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
@ansible_playbooks = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new
|
|
16
|
+
@ansible_playbook = AnsiblePlaybook.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create
|
|
20
|
+
@ansible_playbook = AnsiblePlaybook.new(ansible_playbook_params)
|
|
21
|
+
if @ansible_playbook.save
|
|
22
|
+
process_success
|
|
23
|
+
else
|
|
24
|
+
process_error
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def edit
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def update
|
|
32
|
+
if @ansible_playbook.update(ansible_playbook_params)
|
|
33
|
+
process_success
|
|
34
|
+
else
|
|
35
|
+
process_error
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def destroy
|
|
40
|
+
if @ansible_playbook.destroy
|
|
41
|
+
process_success
|
|
42
|
+
else
|
|
43
|
+
process_error
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def action_permission
|
|
48
|
+
case params[:action]
|
|
49
|
+
when 'import_vars'
|
|
50
|
+
:import_vars
|
|
51
|
+
else
|
|
52
|
+
super
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# We need to move these to a smart_proxy_acd
|
|
57
|
+
def extract_variables(playbook_path)
|
|
58
|
+
errors = []
|
|
59
|
+
vars = {}
|
|
60
|
+
|
|
61
|
+
unless File.directory?(playbook_path) || File.directory?("#{playbook_path}/group_vars")
|
|
62
|
+
errors << "Playbook path '#{playbook_path}' or '#{playbook_path}/group_vars' doesn't exist"
|
|
63
|
+
return vars, errors
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
everything_empty = true
|
|
67
|
+
|
|
68
|
+
vars_files = Dir.glob("#{playbook_path}/group_vars/**/*")
|
|
69
|
+
vars_files.each do |vars_file|
|
|
70
|
+
loaded_yaml = {}
|
|
71
|
+
next if File.directory?(vars_file)
|
|
72
|
+
|
|
73
|
+
begin
|
|
74
|
+
loaded_yaml = YAML.load_file(vars_file)
|
|
75
|
+
rescue Psych::SyntaxError
|
|
76
|
+
err = "#{vars_file} is not YAML file"
|
|
77
|
+
logger.error(err)
|
|
78
|
+
errors << err
|
|
79
|
+
end
|
|
80
|
+
unless loaded_yaml.is_a? Hash
|
|
81
|
+
err = "Could not parse YAML file #{vars_file}"
|
|
82
|
+
logger.error(err)
|
|
83
|
+
errors << err
|
|
84
|
+
end
|
|
85
|
+
everything_empty = false unless loaded_yaml.empty?
|
|
86
|
+
|
|
87
|
+
# We need to support: group_vars/group_file and group_vars/group_dir/yaml_files
|
|
88
|
+
dir_and_file = File.split(vars_file)
|
|
89
|
+
basename = File.basename(dir_and_file[0], '.*')
|
|
90
|
+
if basename == 'group_vars'
|
|
91
|
+
group_name = dir_and_file[1]
|
|
92
|
+
else
|
|
93
|
+
group_name = basename
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
logger.debug("Add ansible vars from file #{vars_file} to group #{group_name}")
|
|
97
|
+
|
|
98
|
+
if vars.has_key?(group_name)
|
|
99
|
+
vars[group_name].merge!(loaded_yaml)
|
|
100
|
+
else
|
|
101
|
+
vars[group_name] = loaded_yaml
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
errors << "No ansible group variable in #{playbook_path} defined." if everything_empty
|
|
106
|
+
|
|
107
|
+
return vars, errors
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def import_vars
|
|
111
|
+
logger.debug("Load ansible group vars for #{@ansible_playbook} from #{@ansible_playbook.path}")
|
|
112
|
+
vars, errors = extract_variables(@ansible_playbook.path)
|
|
113
|
+
@ansible_playbook.vars = vars.to_json
|
|
114
|
+
@ansible_playbook.save
|
|
115
|
+
if errors.empty?
|
|
116
|
+
process_success :success_msg => _("Successfully loaded ansible group variables from %s") % @ansible_playbook.name, :redirect => ansible_playbooks_path
|
|
117
|
+
else
|
|
118
|
+
process_error :error_msg => _(errors.join(' ')), :redirect => ansible_playbooks_path
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAcd
|
|
4
|
+
module Api
|
|
5
|
+
module V2
|
|
6
|
+
# API controller for Ansible Playbooks
|
|
7
|
+
class AnsiblePlaybooksController < ::ForemanAcd::Api::V2::BaseController
|
|
8
|
+
include ::ForemanAcd::Concerns::AnsiblePlaybookParameters
|
|
9
|
+
|
|
10
|
+
before_action :find_resource, :except => [:index, :create]
|
|
11
|
+
|
|
12
|
+
api :GET, '/ansible_playbooks/:id', N_('Show ansible playbook')
|
|
13
|
+
param :id, :identifier, :required => true
|
|
14
|
+
def show; end
|
|
15
|
+
|
|
16
|
+
api :GET, '/ansible_playbooks', N_('List ansible playbooks')
|
|
17
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
|
18
|
+
add_scoped_search_description_for(AnsiblePlaybook)
|
|
19
|
+
def index
|
|
20
|
+
@ansible_playbooks = resource_scope_for_index
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def_param_group :ansible_playbook do
|
|
24
|
+
param :ansible_playbook, Hash, :required => true, :action_aware => true do
|
|
25
|
+
param :name, String, :required => true
|
|
26
|
+
param :description, String, :required => true
|
|
27
|
+
param :services, String, :required => true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
api :POST, '/ansible_playbooks', N_('Create a ansible playbook')
|
|
32
|
+
param_group :ansible_playbook, :as => :create
|
|
33
|
+
def create
|
|
34
|
+
@ansible_playbook = AnsiblePlaybook.new(ansible_playbook_params)
|
|
35
|
+
process_response @ansible_playbook.save
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
api :DELETE, '/ansible_playbooks/:id', N_('Deletes ansible playbook')
|
|
39
|
+
param :id, :identifier, :required => true
|
|
40
|
+
def destroy
|
|
41
|
+
process_response @ansible_playbook.destroy
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def controller_permission
|
|
45
|
+
'ansible_playbooks'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def resource_class
|
|
49
|
+
ForemanAcd::AnsiblePlaybook
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -24,8 +24,7 @@ module ForemanAcd
|
|
|
24
24
|
param :app_definition, Hash, :required => true, :action_aware => true do
|
|
25
25
|
param :name, String, :required => true
|
|
26
26
|
param :description, String, :required => true
|
|
27
|
-
param :
|
|
28
|
-
param :parameters, String, :required => true
|
|
27
|
+
param :services, String, :required => true
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
30
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAcd
|
|
4
|
+
module Api
|
|
5
|
+
module V2
|
|
6
|
+
# API controller for App Instances
|
|
7
|
+
class AppInstancesController < ::ForemanAcd::Api::V2::BaseController
|
|
8
|
+
include ::ForemanAcd::Concerns::AppInstanceParameters
|
|
9
|
+
|
|
10
|
+
before_action :find_resource, :except => [:index, :create]
|
|
11
|
+
|
|
12
|
+
api :GET, '/app_instances/:id', N_('Show application instance')
|
|
13
|
+
param :id, :identifier, :required => true
|
|
14
|
+
def show; end
|
|
15
|
+
|
|
16
|
+
api :GET, '/app_instances', N_('List application instances')
|
|
17
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
|
18
|
+
add_scoped_search_description_for(AppInstance)
|
|
19
|
+
def index
|
|
20
|
+
@app_instances = resource_scope_for_index
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def_param_group :app_instance do
|
|
24
|
+
param :app_instance, Hash, :required => true, :action_aware => true do
|
|
25
|
+
param :name, String, :required => true
|
|
26
|
+
param :description, String, :required => true
|
|
27
|
+
param :services, String, :required => true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
api :POST, '/app_instances', N_('Create a application instance')
|
|
32
|
+
param_group :app_instance, :as => :create
|
|
33
|
+
def create
|
|
34
|
+
@app_instance = AppInstance.new(app_instance_params)
|
|
35
|
+
process_response @app_instance.save
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
api :DELETE, '/app_instances/:id', N_('Deletes application instance')
|
|
39
|
+
param :id, :identifier, :required => true
|
|
40
|
+
def destroy
|
|
41
|
+
process_response @app_instance.destroy
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def controller_permission
|
|
45
|
+
'app_instances'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def resource_class
|
|
49
|
+
ForemanAcd::AppInstance
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
File without changes
|
|
@@ -6,18 +6,24 @@ 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
|
+
@ansible_playbooks = AnsiblePlaybook.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
|
20
|
+
end
|
|
21
|
+
|
|
15
22
|
def read_hostgroups
|
|
16
23
|
@hostgroups = Hostgroup.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
|
17
24
|
end
|
|
18
25
|
|
|
19
26
|
def new
|
|
20
|
-
read_hostgroups
|
|
21
27
|
@app_definition = AppDefinition.new
|
|
22
28
|
end
|
|
23
29
|
|
|
@@ -31,11 +37,10 @@ module ForemanAcd
|
|
|
31
37
|
end
|
|
32
38
|
|
|
33
39
|
def edit
|
|
34
|
-
read_hostgroups
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
def update
|
|
38
|
-
if @app_definition.
|
|
43
|
+
if @app_definition.update_attributes(app_definition_params)
|
|
39
44
|
process_success
|
|
40
45
|
else
|
|
41
46
|
process_error
|
|
@@ -49,5 +54,31 @@ module ForemanAcd
|
|
|
49
54
|
process_error
|
|
50
55
|
end
|
|
51
56
|
end
|
|
57
|
+
|
|
58
|
+
def action_permission
|
|
59
|
+
case params[:action]
|
|
60
|
+
when 'export'
|
|
61
|
+
:export
|
|
62
|
+
else
|
|
63
|
+
super
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def import
|
|
68
|
+
@app_definition = AppDefinition.new
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def export
|
|
72
|
+
filename = "#{@app_definition.name}.yaml"
|
|
73
|
+
data = JSON.parse(@app_definition.services).to_yaml
|
|
74
|
+
send_data data, :type => 'text/yaml', :disposition => 'attachment', :filename => filename
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
private
|
|
78
|
+
|
|
79
|
+
def handle_file_upload
|
|
80
|
+
return unless params[:foreman_acd_app_definition] && raw_file = params[:foreman_acd_app_definition][:app_definition_file]
|
|
81
|
+
params[:foreman_acd_app_definition][:services] = YAML.load_file(raw_file.tempfile).to_json
|
|
82
|
+
end
|
|
52
83
|
end
|
|
53
84
|
end
|
|
@@ -6,19 +6,19 @@ 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, :deploy, :report, :configure]
|
|
10
|
+
before_action :read_applications, :only => [:new, :edit]
|
|
10
11
|
|
|
11
12
|
def index
|
|
12
13
|
@app_instances = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
def read_applications
|
|
16
|
-
@applications =
|
|
17
|
+
@applications = AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def new
|
|
20
21
|
@app_instance = AppInstance.new
|
|
21
|
-
read_applications
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def create
|
|
@@ -31,7 +31,6 @@ module ForemanAcd
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def edit
|
|
34
|
-
read_applications
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
def update
|
|
@@ -54,105 +53,62 @@ module ForemanAcd
|
|
|
54
53
|
case params[:action]
|
|
55
54
|
when 'deploy'
|
|
56
55
|
:deploy
|
|
56
|
+
when 'report'
|
|
57
|
+
:report
|
|
58
|
+
when 'configure'
|
|
59
|
+
:configure
|
|
57
60
|
else
|
|
58
61
|
super
|
|
59
62
|
end
|
|
60
63
|
end
|
|
61
64
|
|
|
62
65
|
def deploy
|
|
63
|
-
|
|
64
|
-
|
|
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')
|
|
73
|
-
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
|
|
77
|
-
end
|
|
66
|
+
app_deployer = ForemanAcd::AppDeployer.new(@app_instance)
|
|
78
67
|
|
|
79
|
-
|
|
68
|
+
# save any change to the app_hosts json
|
|
69
|
+
@app_instance.hosts = app_deployer.deploy.to_json
|
|
70
|
+
@app_instance.save
|
|
80
71
|
|
|
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)
|
|
72
|
+
@deploy_hosts = app_deployer.deploy_hosts
|
|
85
73
|
end
|
|
86
74
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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?)
|
|
98
|
-
end
|
|
75
|
+
def report
|
|
76
|
+
@report_hosts = []
|
|
77
|
+
app_hosts = JSON.parse(@app_instance.hosts)
|
|
78
|
+
app_hosts.each do |host_data|
|
|
79
|
+
h = Host.find(host_data['foreman_host_id'])
|
|
80
|
+
@report_hosts.push({id: h.id, name: host_data['hostname'], hostname: h.hostname, hostUrl: host_path(h), powerStatusUrl: power_api_host_path(h) })
|
|
99
81
|
end
|
|
100
|
-
params = host.apply_inherited_attributes(params) if host
|
|
101
|
-
params
|
|
102
|
-
end
|
|
103
|
-
|
|
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
|
|
108
|
-
end
|
|
109
82
|
|
|
110
|
-
|
|
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
|
|
83
|
+
logger.debug("deploy report hosts are: #{@report_hosts.inspect}")
|
|
118
84
|
end
|
|
119
85
|
|
|
120
|
-
def
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
result['ip'] = param['value']
|
|
140
|
-
|
|
141
|
-
when 'lifecycleenv'
|
|
142
|
-
result['content_facet_attributes'] = { 'lifecycle_environment_id' => param['value'] }
|
|
143
|
-
|
|
144
|
-
when 'ptable'
|
|
145
|
-
result['ptable_id'] = param['value']
|
|
146
|
-
|
|
147
|
-
when 'puppetenv'
|
|
148
|
-
result['environment_id'] = param['value']
|
|
149
|
-
|
|
150
|
-
when 'password'
|
|
151
|
-
result['root_pass'] = param['value']
|
|
152
|
-
|
|
86
|
+
def configure
|
|
87
|
+
app_configurator = ForemanAcd::AppConfigurator.new(@app_instance)
|
|
88
|
+
jobs = app_configurator.configure
|
|
89
|
+
job_count = jobs.count
|
|
90
|
+
|
|
91
|
+
customize_first = if params[:customize] == 'true'
|
|
92
|
+
true
|
|
93
|
+
else
|
|
94
|
+
false
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
logger.debug("Created #{job_count} to configure #{@app_instance} - customize: #{customize_first}")
|
|
98
|
+
|
|
99
|
+
if job_count == 1 && customize_first == false
|
|
100
|
+
jobs.first.trigger!
|
|
101
|
+
redirect_to job_invocation_path(jobs.first.job_invocation)
|
|
102
|
+
elsif customize_first == false
|
|
103
|
+
jobs.each do |composer|
|
|
104
|
+
composer.save
|
|
153
105
|
end
|
|
106
|
+
# redirect to the job itself if we want to customize the job
|
|
107
|
+
redirect_to job_invocations_path
|
|
108
|
+
else
|
|
109
|
+
# redirect to the job itself if we only have one job, otherwise to the index page
|
|
110
|
+
redirect_to job_invocations_path
|
|
154
111
|
end
|
|
155
|
-
result
|
|
156
112
|
end
|
|
157
113
|
end
|
|
158
114
|
end
|