foreman_acd 0.0.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
  3. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +54 -0
  4. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
  5. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
  6. data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +35 -4
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +43 -87
  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/ui_acd_controller.rb +11 -4
  13. data/app/models/foreman_acd/ansible_playbook.rb +50 -0
  14. data/app/models/foreman_acd/app_definition.rb +2 -1
  15. data/app/models/foreman_acd/app_instance.rb +7 -0
  16. data/app/services/foreman_acd/app_configurator.rb +70 -0
  17. data/app/services/foreman_acd/app_deployer.rb +143 -0
  18. data/app/services/foreman_acd/inventory_creator.rb +67 -0
  19. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
  20. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -0
  21. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  22. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  23. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +3 -0
  24. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
  25. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
  26. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
  27. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
  28. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
  29. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
  30. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
  31. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
  32. data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
  33. data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
  34. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  35. data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
  36. data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
  37. data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
  38. data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
  39. data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
  40. data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -0
  41. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  42. data/app/views/ui_acd/app.json.rabl +6 -2
  43. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  44. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  45. data/config/routes.rb +31 -1
  46. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  47. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  48. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  49. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  50. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +5 -0
  51. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
  52. data/db/seeds.d/75-job_templates.rb +8 -0
  53. data/lib/foreman_acd/engine.rb +3 -0
  54. data/lib/foreman_acd/plugin.rb +72 -4
  55. data/lib/foreman_acd/version.rb +1 -1
  56. data/package.json +2 -1
  57. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +376 -0
  58. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  59. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
  60. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
  61. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  62. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
  63. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
  64. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  65. data/webpack/components/ApplicationDefinition/index.js +33 -0
  66. data/webpack/components/ApplicationInstance/ApplicationInstance.js +412 -0
  67. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  68. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
  69. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
  70. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
  71. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -0
  72. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  73. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  74. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  75. data/webpack/components/ApplicationInstance/index.js +35 -0
  76. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
  77. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
  78. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
  79. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
  82. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  83. data/webpack/components/ApplicationInstanceReport/index.js +27 -0
  84. data/webpack/components/ParameterSelection/ParameterSelection.js +96 -183
  85. data/webpack/components/ParameterSelection/ParameterSelection.scss +10 -3
  86. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +72 -104
  87. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +14 -19
  88. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  89. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +100 -83
  90. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  91. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  92. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  93. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  94. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  95. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  96. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  97. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  98. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  99. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  100. data/webpack/components/ParameterSelection/index.js +6 -8
  101. data/webpack/components/common/AddTableEntry.js +30 -0
  102. data/webpack/components/common/DeleteTableEntry.js +39 -0
  103. data/webpack/components/common/ExtSelect.js +43 -0
  104. data/webpack/components/common/RailsData.js +27 -0
  105. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  106. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  107. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  108. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  109. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  110. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  111. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  112. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  113. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  114. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  115. data/webpack/helper.js +20 -0
  116. data/webpack/index.js +6 -0
  117. data/webpack/reducer.js +43 -3
  118. metadata +85 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 845682898811195ad81ff1d64e0368f33826dc202116be4955e3d61e744e24b4
4
- data.tar.gz: 39e7e212a2ca8c829bee777cb40a29fa2bcbbe2988192890248335609e456277
3
+ metadata.gz: 63b0fc4a685be137bfd8d72d166d0c157081dc4c2ad34cbde4ac7e75faed4e1a
4
+ data.tar.gz: 9484df12c6738faa15f1b6d76721992b74a5ae0a795bbe6fc1f20cb08d3e7edd
5
5
  SHA512:
6
- metadata.gz: efdabb748af796361d12deff4c50cf0418388d61f006dd26cb947c0babe76f02dac9192dd7d90db0aad95f241585bc2b131a9fbb398a46a7db47bb0deec8a488
7
- data.tar.gz: 88ed03d3042f1b0937177a8bcf18b05007954805138c79dba6d4cf211daa38a2bffe25097b4b6f0921bbb74381a6bb815546e47dd7caf13d6176036293df83c5
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 :hostgroup_id, :number, :required => true
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
@@ -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.update(app_definition_params)
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 = ForemanAcd::AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
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
- params = host_attributes(set_host_params)
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
- private
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
- # 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)
72
+ @deploy_hosts = app_deployer.deploy_hosts
85
73
  end
86
74
 
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?)
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
- 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
83
+ logger.debug("deploy report hosts are: #{@report_hosts.inspect}")
118
84
  end
119
85
 
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'] }
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