foreman_acd 0.2.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -56
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +199 -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 +1 -0
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +19 -10
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +111 -137
  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 +62 -0
  13. data/app/controllers/ui_acd_controller.rb +20 -3
  14. data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +47 -0
  15. data/app/lib/actions/foreman_acd/run_configurator.rb +44 -0
  16. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
  17. data/app/models/foreman_acd/acd_provider.rb +36 -0
  18. data/app/models/foreman_acd/ansible_playbook.rb +68 -0
  19. data/app/models/foreman_acd/app_definition.rb +25 -0
  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/acd_proxy_proxy_selector.rb +17 -0
  24. data/app/services/foreman_acd/app_configurator.rb +98 -0
  25. data/app/services/foreman_acd/app_deployer.rb +157 -0
  26. data/app/services/foreman_acd/inventory_creator.rb +68 -0
  27. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +64 -0
  28. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
  29. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  30. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  31. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
  32. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
  33. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
  34. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
  35. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
  36. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
  37. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
  38. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
  39. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
  40. data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -12
  41. data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
  42. data/app/views/foreman_acd/app_definitions/index.html.erb +4 -4
  43. data/app/views/foreman_acd/app_instances/_form.html.erb +11 -9
  44. data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
  45. data/app/views/foreman_acd/app_instances/index.html.erb +89 -10
  46. data/app/views/foreman_acd/app_instances/report.html.erb +6 -3
  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 +32 -2
  53. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  54. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  55. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
  56. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
  57. data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
  58. data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
  59. data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
  60. data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
  61. data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
  62. data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
  63. data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
  64. data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
  65. data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.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.rb +12 -0
  69. data/lib/foreman_acd/engine.rb +43 -3
  70. data/lib/foreman_acd/plugin.rb +88 -22
  71. data/lib/foreman_acd/version.rb +1 -1
  72. data/lib/tasks/foreman_acd_tasks.rake +0 -12
  73. data/locale/en/foreman_acd.edit.po +326 -0
  74. data/locale/en/foreman_acd.po +232 -2
  75. data/locale/en/foreman_acd.po.time_stamp +0 -0
  76. data/locale/foreman_acd.pot +343 -8
  77. data/package.json +9 -9
  78. data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
  79. data/test/controllers/app_instances_controller_test.rb +8 -3
  80. data/test/controllers/ui_acd_controller_test.rb +22 -6
  81. data/test/factories/foreman_acd_factories.rb +18 -4
  82. data/test/models/acd_provider_test.rb +37 -0
  83. data/test/models/ansible_playbook_test.rb +11 -0
  84. data/test/models/app_definition_test.rb +1 -1
  85. data/test/models/app_instance_test.rb +2 -0
  86. data/test/models/concerns/host_extensions_test.rb +26 -0
  87. data/test/models/foreman_host_test.rb +12 -0
  88. data/webpack/__mocks__/foremanReact/API.js +2 -0
  89. data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
  90. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  91. data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
  92. data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
  93. data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
  94. data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
  95. data/webpack/__snapshots__/helper.test.js.snap +14 -0
  96. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +159 -29
  97. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +106 -14
  98. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +8 -2
  99. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  100. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +143 -21
  101. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +3 -0
  102. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
  103. data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
  104. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +25 -0
  105. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
  106. data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +41 -0
  107. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +200 -0
  108. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
  109. data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +299 -0
  110. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +50 -0
  111. data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
  112. data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
  113. data/webpack/components/ApplicationDefinition/index.js +6 -0
  114. data/webpack/components/ApplicationInstance/ApplicationInstance.js +151 -44
  115. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +47 -10
  116. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +5 -2
  117. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +114 -28
  118. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +3 -1
  119. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
  120. data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +78 -0
  121. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +23 -0
  122. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +119 -0
  123. data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +44 -0
  124. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +209 -0
  125. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2719 -0
  126. data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +276 -0
  127. data/webpack/components/ApplicationInstance/components/Service.js +1 -1
  128. data/webpack/components/ApplicationInstance/index.js +4 -0
  129. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +53 -60
  130. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +17 -0
  131. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +7 -51
  132. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -4
  133. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +4 -18
  134. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +0 -1
  135. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
  136. data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
  137. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
  138. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
  139. data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
  140. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +130 -0
  141. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
  142. data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
  143. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +1 -1
  144. data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
  145. data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
  146. data/webpack/components/ApplicationInstanceReport/index.js +0 -2
  147. data/webpack/components/ParameterSelection/ParameterSelection.js +85 -50
  148. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +68 -62
  149. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +6 -3
  150. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +0 -32
  151. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +47 -35
  152. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +2 -2
  153. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +116 -84
  154. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
  155. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
  156. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +31 -25
  157. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  158. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +2 -126
  159. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1483 -872
  160. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +117 -79
  161. data/webpack/components/ParameterSelection/index.js +4 -4
  162. data/webpack/components/SyncGitRepo/SyncGitRepo.js +210 -0
  163. data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
  164. data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +124 -0
  165. data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +9 -0
  166. data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
  167. data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
  168. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
  169. data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
  170. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
  171. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
  172. data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
  173. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +30 -0
  174. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
  175. data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
  176. data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
  177. data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +46 -0
  178. data/webpack/components/SyncGitRepo/index.js +28 -0
  179. data/webpack/components/common/DeleteTableEntry.js +3 -3
  180. data/webpack/components/common/EditTableEntry.js +50 -0
  181. data/webpack/components/common/ExtTextInput.js +43 -0
  182. data/webpack/components/common/LockTableEntry.js +60 -0
  183. data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
  184. data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
  185. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +2 -2
  186. data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
  187. data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
  188. data/webpack/helper.js +15 -1
  189. data/webpack/helper.test.js +37 -0
  190. data/webpack/index.js +2 -0
  191. data/webpack/reducer.js +18 -11
  192. metadata +184 -10
  193. data/app/views/foreman_acd/app_instances/deploy.html.erb +0 -19
  194. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
  195. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ object @ansible_data
4
+ attribute :id
5
+ attribute :name
6
+ attribute :groups
@@ -4,6 +4,10 @@ child @app_data['app_definition'] => :app_definition do
4
4
  extends 'ui_acd/app_definition'
5
5
  end
6
6
 
7
- child @app_data['fdata'] => :fdata do
8
- extends 'ui_acd/fdata'
7
+ child @app_data['foreman_data'] => :foreman_data do
8
+ extends 'ui_acd/foreman_data'
9
+ end
10
+
11
+ child @app_data['ansible_data'] => :ansible_data do
12
+ extends 'ui_acd/ansible_data'
9
13
  end
@@ -2,4 +2,4 @@
2
2
 
3
3
  object @app_definition
4
4
 
5
- attributes :id, :name, :description, :services, :created_at, :updated_at
5
+ attributes :id, :name, :description, :services, :ansible_vars_all, :location_ids, :organization_ids, :created_at, :updated_at
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- object @fdata
3
+ object @foreman_data
4
4
  attribute :hostgroup_id
5
5
 
6
6
  child :environments => :environments do
data/config/routes.rb CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  Rails.application.routes.draw do
4
4
  scope :acd, :path => '/acd' do
5
+ resources :ansible_playbooks, :controller => 'foreman_acd/ansible_playbooks' do
6
+ collection do
7
+ get 'auto_complete_search'
8
+ put 'sync_git_repo'
9
+ post 'sync_git_repo'
10
+ end
11
+
12
+ member do
13
+ post 'sync_git_repo'
14
+ get 'import_vars'
15
+ end
16
+ end
5
17
  resources :app_definitions, :controller => 'foreman_acd/app_definitions' do
6
18
  collection do
7
19
  get 'auto_complete_search'
@@ -11,7 +23,6 @@ Rails.application.routes.draw do
11
23
  member do
12
24
  get 'export'
13
25
  end
14
-
15
26
  end
16
27
 
17
28
  resources :app_instances, :controller => 'foreman_acd/app_instances' do
@@ -22,10 +33,29 @@ Rails.application.routes.draw do
22
33
  member do
23
34
  post 'deploy'
24
35
  get 'report'
36
+ delete 'destroy_with_hosts'
25
37
  end
26
38
  end
27
39
 
40
+ match '/remote_execution', :controller => 'foreman_acd/remote_execution', :action => 'create', :via => [:post]
41
+
28
42
  get 'ui_acd_app/:id', :to => 'ui_acd#app', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_app
29
- get 'ui_acd_fdata/:id', :to => 'ui_acd#fdata', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_fdata
43
+ get 'ui_acd_foreman_data/:id', :to => 'ui_acd#foreman_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_foreman_data
44
+ get 'ui_acd_ansible_data/:id', :to => 'ui_acd#ansible_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_ansible_data
45
+
46
+ scope :api, :path => '/api', :defaults => { :format => 'json' } do
47
+ scope '(:apiv)', :defaults => { :apiv => 'v2' },
48
+ :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2) do
49
+ constraints(:id => /[\w\.-]+/) do
50
+ resources :app_definitions, :only => [:show, :index], :controller => 'foreman_acd/api/v2/app_definitions', :as => :acd_api_v2_app_definitions
51
+ resources :app_instances, :only => [:show, :index], :controller => 'foreman_acd/api/v2/app_instances', :as => :api_v2_foreman_acd_app_instances
52
+ resources :ansible_playbooks, :only => [:show, :index], :controller => 'foreman_acd/api/v2/ansible_playbooks', :as => :api_v2_foreman_acd_ansible_playbooks do
53
+ member do
54
+ get 'grab'
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
30
60
  end
31
61
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adding acd ansible playbooks db table
4
+ class CreateAnsiblePlaybooks < ActiveRecord::Migration[5.2]
5
+ def up
6
+ create_table :acd_ansible_playbooks do |t|
7
+ t.string :name, :default => '', :null => false, :limit => 255, :unique => true
8
+ t.text :description
9
+ t.string :scm_type
10
+ t.string :path
11
+ t.string :playfile
12
+ t.text :vars
13
+ t.timestamps :null => true
14
+ end
15
+ end
16
+
17
+ def down
18
+ drop_table :acd_ansible_playbooks
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adding acd ansible playbooks db table
4
+ class AddAnsiblePlaybookId < ActiveRecord::Migration[5.2]
5
+ def up
6
+ add_column :app_definitions, :acd_ansible_playbook_id, :integer
7
+ add_foreign_key 'app_definitions', 'acd_ansible_playbooks', :name => 'app_definitions_acd_ansible_playbooks_id_fk'
8
+ end
9
+
10
+ def down
11
+ remove_foreign_key 'app_definitions', :name => 'app_definitions_acd_ansible_playbooks_id_fk'
12
+ remove_column :app_definitions, :acd_ansible_playbook_id
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add ansible variables to app definitions
4
+ class AddAnsibleVarsAllToAppDefinitions < ActiveRecord::Migration[5.2]
5
+ def change
6
+ add_column :app_definitions, :ansible_vars_all, :text
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add ansible variables to app instances
4
+ class AddAnsibleVarsAllToAppInstances < ActiveRecord::Migration[5.2]
5
+ def change
6
+ add_column :app_instances, :ansible_vars_all, :text
7
+ end
8
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add organization to app instance
4
+ class AddOrganizationToAppInstance < ActiveRecord::Migration[6.0]
5
+ # FakeAppInstance, because of 'validates :location'
6
+ class AppInstance < ApplicationRecord
7
+ belongs_to :organization
8
+ end
9
+
10
+ def up
11
+ add_column :app_instances, :organization_id, :integer, :null => true, :index => true
12
+ AppInstance.all.each do |a|
13
+ a.organization = ::Organization.first
14
+ a.save!
15
+ end
16
+ change_column :app_instances, :organization_id, :integer, :null => false, :index => true
17
+ end
18
+
19
+ def down
20
+ remove_column :app_instances, :organization_id, :integer
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add location to app instance
4
+ class AddLocationToAppInstance < ActiveRecord::Migration[6.0]
5
+ def change
6
+ add_column :app_instances, :location_id, :integer, :null => true, :index => true
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adding acd_foreman_hosts db table
4
+ class CreateForemanHosts < ActiveRecord::Migration[6.0]
5
+ def up
6
+ create_table :foreman_hosts do |t|
7
+ t.string :hostname, :default => '', :null => false, :limit => 255, :unique => true
8
+ t.column :app_instance_id, :integer, :null => false
9
+ t.column :host_id, :integer
10
+ t.string :service
11
+ t.string :description
12
+ t.text :foremanParameters
13
+ t.text :ansibleParameters
14
+
15
+ t.timestamps :null => false
16
+ end
17
+ add_foreign_key :foreman_hosts, :app_instances
18
+ add_foreign_key :foreman_hosts, :hosts
19
+ end
20
+
21
+ def down
22
+ drop_table :foreman_hosts
23
+ end
24
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Remove hosts column from app_instances db table
4
+ class RemoveHostsFromAppInstances < ActiveRecord::Migration[6.0]
5
+ def change
6
+ remove_column :app_instances, :hosts, :text
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Adding Rename ACD db tables
4
+ class RenameAcdTables < ActiveRecord::Migration[6.0]
5
+ def up
6
+ rename_table :app_definitions, :acd_app_definitions
7
+ rename_table :app_instances, :acd_app_instances
8
+ rename_table :foreman_hosts, :acd_foreman_hosts
9
+ end
10
+
11
+ def down
12
+ rename_table :acd_app_definitions
13
+ rename_table :acd_app_instances
14
+ rename_table :acd_foreman_hosts
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add AddLastProgressReport
4
+ class AddLastProgressReport < ActiveRecord::Migration[5.2]
5
+ def change
6
+ add_column :acd_foreman_hosts, :last_progress_report, :text
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add AddLastDeployTask
4
+ class AddLastDeployTask < ActiveRecord::Migration[5.2]
5
+ def change
6
+ add_column :acd_app_instances, :last_deploy_task_id, :uuid, :null => true
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add git_commit column to ansible_playbook
4
+ class AddGitCommitToAnsiblePlaybooks < ActiveRecord::Migration[6.0]
5
+ def change
6
+ add_column :acd_ansible_playbooks, :git_commit, :string
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add git_url column to ansible_playbook
4
+ class AddGitUrlToAnsiblePlaybooks < ActiveRecord::Migration[6.0]
5
+ def change
6
+ add_column :acd_ansible_playbooks, :git_url, :string
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ proxy_feature = Feature.where(:name => 'ACD').first_or_create
4
+ raise "Unable to create proxy feature: #{format_errors proxy_feature}" if proxy_feature.nil? || proxy_feature.errors.any?
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ User.as_anonymous_admin do
4
+ JobTemplate.without_auditing do
5
+ Dir[File.join("#{ForemanAcd::Engine.root}/app/views/templates/**/*.erb")].each do |template|
6
+ sync = !Rails.env.test? && Setting[:remote_execution_sync_templates]
7
+ template = JobTemplate.import_raw!(File.read(template), :default => true, :lock => true, :update => sync)
8
+
9
+ template.organizations << Organization.unscoped.all if template&.organizations&.empty?
10
+ template.locations << Location.unscoped.all if template&.locations&.empty?
11
+ end
12
+ end
13
+ end
data/lib/foreman_acd.rb CHANGED
@@ -4,4 +4,16 @@ require 'foreman_acd/engine'
4
4
 
5
5
  # Module required to start the Foreman Rails engine
6
6
  module ForemanAcd
7
+ def self.acd_base_path
8
+ '/var/lib/foreman/foreman_acd/'
9
+ end
10
+
11
+ def self.ansible_playbook_path
12
+ File.join(acd_base_path, 'ansible-playbooks')
13
+ end
14
+
15
+ def self.proxy_setting
16
+ HttpProxy.default_global_content_proxy&.full_url ||
17
+ Setting[:http_proxy]
18
+ end
7
19
  end
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'foreman_remote_execution'
4
+ require 'git'
5
+
6
+ # The ForemanAcd module
3
7
  module ForemanAcd
4
8
  # This engine connects ForemanAcd with Foreman core
5
9
  class Engine < ::Rails::Engine
6
10
  engine_name 'foreman_acd'
7
11
 
8
12
  config.autoload_paths += Dir["#{config.root}/app/controllers/foreman_acd/concerns"]
13
+ config.autoload_paths += Dir["#{config.root}/app/models"]
14
+ config.autoload_paths += Dir["#{config.root}/app/services"]
9
15
  config.autoload_paths += Dir["#{config.root}/app/helpers"]
10
- config.autoload_paths += Dir["#{config.root}/app/models/foreman_acd/concerns"]
11
- config.autoload_paths += Dir["#{config.root}/app/models/parameters"]
12
16
  config.autoload_paths += Dir["#{config.root}/app/overrides"]
13
- config.autoload_paths += Dir["#{config.root}/app/services"]
14
17
  config.autoload_paths += Dir["#{config.root}/app/lib"]
18
+ config.autoload_paths += Dir["#{config.root}/lib"]
15
19
 
16
20
  # Add any db migrations
17
21
  initializer 'foreman_acd.load_app_instance_data' do |app|
@@ -39,5 +43,41 @@ module ForemanAcd
39
43
  initializer 'foreman_acd.register_plugin', :before => :finisher_hook do
40
44
  require 'foreman_acd/plugin'
41
45
  end
46
+
47
+ initializer 'foreman_acd.register_actions', :before => :finisher_hook do |_app|
48
+ ForemanTasks.dynflow.require!
49
+ action_paths = %W[#{ForemanAcd::Engine.root}/app/lib/actions]
50
+ ForemanTasks.dynflow.config.eager_load_paths.concat(action_paths)
51
+ end
52
+
53
+ config.to_prepare do
54
+ ::Taxonomy.include ForemanAcd::TaxonomyExtensions
55
+ ::Host::Managed.prepend ForemanAcd::HostManagedExtensions
56
+
57
+ RemoteExecutionProvider.register(:ACD, AcdProvider)
58
+ ForemanAcd.register_rex_feature
59
+ end
60
+ end
61
+
62
+ def self.with_katello?
63
+ defined?(::Katello)
64
+ end
65
+
66
+ def self.with_remote_execution?
67
+ RemoteExecutionFeature
68
+ rescue StandardError
69
+ false
70
+ end
71
+
72
+ def self.register_rex_feature
73
+ return unless ForemanAcd.with_remote_execution?
74
+ RemoteExecutionFeature.register(
75
+ :run_acd_ansible_playbook,
76
+ N_('Run playbook for ACD'),
77
+ {
78
+ :description => N_('Run an Ansible playbook to configure ACD application'),
79
+ :provided_inputs => %w[application_name playbook_name playbook_path inventory_path]
80
+ }
81
+ )
42
82
  end
43
83
  end
@@ -1,24 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Foreman::Plugin.register :foreman_acd do
4
- requires_foreman '>= 1.19'
4
+ requires_foreman '>= 2.1'
5
5
 
6
6
  apipie_documented_controllers ["#{ForemanAcd::Engine.root}/app/controllers/foreman_acd/api/v2/*.rb"]
7
7
 
8
8
  # Menus
9
- divider :top_menu, :parent => :configure_menu, :caption => 'Applications'
10
- menu :top_menu, :app_definitions,
11
- :url_hash => { :controller => :'foreman_acd/app_definitions', :action => :index },
12
- :caption => 'App Definitions',
13
- :parent => :configure_menu
14
-
15
- menu :top_menu, :app_instances,
16
- :url_hash => { :controller => :'foreman_acd/app_instances', :action => :index },
17
- :caption => 'App Instances',
18
- :parent => :configure_menu
9
+ sub_menu :top_menu, :application, :caption => N_('Applications'), :after => :hosts_menu, :icon => 'pficon pficon-integration' do
10
+ menu :top_menu, :ansible_playbooks,
11
+ :url_hash => { :controller => :'foreman_acd/ansible_playbooks', :action => :index },
12
+ :caption => 'Ansible Playbooks'
13
+
14
+ menu :top_menu, :app_definitions,
15
+ :url_hash => { :controller => :'foreman_acd/app_definitions', :action => :index },
16
+ :caption => 'App Definitions'
17
+
18
+ menu :top_menu, :app_instances,
19
+ :url_hash => { :controller => :'foreman_acd/app_instances', :action => :index },
20
+ :caption => 'App Instances'
21
+ end
19
22
 
20
23
  # Add permissions
21
24
  security_block :foreman_acd do
25
+ permission :create_ansible_playbooks,
26
+ { :'foreman_acd/ansible_playbooks' => [:new, :create],
27
+ :'foreman_acd/api/v2/ansible_playbooks' => [:create] },
28
+ :resource_type => 'ForemanAcd::AnsiblePlaybook'
29
+
30
+ permission :view_ansible_playbooks,
31
+ { :'foreman_acd/ansible_playbooks' => [:index, :show, :auto_complete_search],
32
+ :'foreman_acd/api/v2/ansible_playbooks' => [:index, :show] },
33
+ :resource_type => 'ForemanAcd::AnsiblePlaybook'
34
+
35
+ permission :edit_ansible_playbooks,
36
+ { :'foreman_acd/ansible_playbooks' => [:update, :edit],
37
+ :'foreman_acd/api/v2/ansible_playbooks' => [:update] },
38
+ :resource_type => 'ForemanAcd::AnsiblePlaybook'
39
+
40
+ permission :destroy_ansible_playbooks,
41
+ { :'foreman_acd/ansible_playbooks' => [:destroy],
42
+ :'foreman_acd/api/v2/ansible_playbooks' => [:destroy] },
43
+ :resource_type => 'ForemanAcd::AnsiblePlaybook'
44
+
45
+ permission :import_vars_ansible_playbooks,
46
+ { :'foreman_acd/ansible_playbooks' => [:import_vars],
47
+ :'foreman_acd/api/v2/ansible_playbooks' => [:import_vars] },
48
+ :resource_type => 'ForemanAcd::AnsiblePlaybook'
49
+
50
+ permission :grab_ansible_playbooks,
51
+ { :'foreman_acd/api/v2/ansible_playbooks' => [:grab] },
52
+ :resource_type => 'ForemanAcd::AnsiblePlaybook'
53
+
22
54
  permission :create_app_definitions,
23
55
  { :'foreman_acd/app_definitions' => [:new, :create],
24
56
  :'foreman_acd/api/v2/app_definitions' => [:create] },
@@ -65,8 +97,8 @@ Foreman::Plugin.register :foreman_acd do
65
97
  :resource_type => 'ForemanAcd::AppInstance'
66
98
 
67
99
  permission :destroy_app_instances,
68
- { :'foreman_acd/app_instances' => [:destroy],
69
- :'foreman_acd/api/v2/app_instances' => [:destroy] },
100
+ { :'foreman_acd/app_instances' => [:destroy, :destroy_with_hosts],
101
+ :'foreman_acd/api/v2/app_instances' => [:destroy, :destroy_with_hosts] },
70
102
  :resource_type => 'ForemanAcd::AppInstance'
71
103
 
72
104
  permission :deploy_app_instances,
@@ -78,20 +110,54 @@ Foreman::Plugin.register :foreman_acd do
78
110
  { :'foreman_acd/app_instances' => [:report],
79
111
  :'foreman_acd/api/v2/app_instances' => [:report] },
80
112
  :resource_type => 'ForemanAcd::AppInstance'
113
+
114
+ permission :new_remote_execution,
115
+ { :'foreman_acd/remote_execution' => [:new] },
116
+ :resource_type => 'ForemanAcd::RemoteExecution'
117
+
118
+ permission :create_remote_execution,
119
+ { :'foreman_acd/remote_execution' => [:create] },
120
+ :resource_type => 'ForemanAcd::RemoteExecution'
121
+
122
+ permission :view_ui_acd,
123
+ { :ui_acd => [:app, :foreman_data, :ansible_data] }
124
+
125
+ permission :acd_foreman_hosts,
126
+ { :'foreman_acd/app_instances' => [:create, :edit, :update, :deploy, :destroy_with_hosts, :destroy] },
127
+ :resource_type => 'ForemanAcd::ForemanHost'
81
128
  end
82
129
 
83
130
  # Manager Role
84
- role 'Application Centric Deployment Manager', [:create_app_definitions,
85
- :view_app_definitions,
86
- :edit_app_definitions,
87
- :export_app_definitions,
88
- :import_app_definitions]
131
+ role 'Application Centric Deployment Manager', [:create_ansible_playbooks, :view_ansible_playbooks, :edit_ansible_playbooks,
132
+ :destroy_ansible_playbooks,
133
+ :import_vars_ansible_playbooks, :grab_ansible_playbooks,
134
+ :create_app_definitions, :view_app_definitions, :edit_app_definitions,
135
+ :destroy_app_definitions,
136
+ :export_app_definitions, :import_app_definitions,
137
+ :create_app_instances, :view_app_instances, :edit_app_instances,
138
+ :destroy_app_instances,
139
+ :deploy_app_instances,
140
+ :new_remote_execution, :create_remote_execution,
141
+ :report_app_instances,
142
+ :view_ui_acd,
143
+ :view_hosts, :build_hosts, :power_hosts, :create_hosts, :edit_hosts, :destroy_hosts, :console_hosts,
144
+ :view_job_invocations, :cancel_job_invocations, :create_job_invocations, :create_template_invocations,
145
+ :view_job_templates,
146
+ :view_foreman_tasks,
147
+ :acd_foreman_hosts, :view_smart_proxies]
89
148
 
90
149
  # User Role
91
- role 'Application Centric Deployment User', [:create_app_instances,
92
- :view_app_instances,
93
- :edit_app_instances,
150
+ role 'Application Centric Deployment User', [:create_app_instances, :view_app_instances, :edit_app_instances,
94
151
  :destroy_app_instances,
95
152
  :deploy_app_instances,
96
- :report_app_instances]
153
+ :new_remote_execution, :create_remote_execution,
154
+ :report_app_instances,
155
+ :view_ui_acd,
156
+ :view_hosts, :build_hosts, :power_hosts, :create_hosts, :edit_hosts, :destroy_hosts, :console_hosts,
157
+ :view_job_invocations, :cancel_job_invocations, :create_job_invocations, :create_template_invocations,
158
+ :view_job_templates,
159
+ :view_foreman_tasks,
160
+ :acd_foreman_hosts, :view_smart_proxies]
161
+
162
+ add_all_permissions_to_default_roles
97
163
  end