foreman_acd 0.0.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +107 -56
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +124 -0
  4. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +72 -0
  5. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +2 -2
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +46 -9
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +96 -90
  9. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
  10. data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
  11. data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
  12. data/app/controllers/foreman_acd/remote_execution_controller.rb +46 -0
  13. data/app/controllers/ui_acd_controller.rb +20 -4
  14. data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +42 -0
  15. data/app/lib/actions/foreman_acd/run_configurator.rb +41 -0
  16. data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
  17. data/app/models/foreman_acd/acd_provider.rb +30 -0
  18. data/app/models/foreman_acd/ansible_playbook.rb +67 -0
  19. data/app/models/foreman_acd/app_definition.rb +25 -1
  20. data/app/models/foreman_acd/app_instance.rb +42 -0
  21. data/app/models/foreman_acd/foreman_host.rb +23 -0
  22. data/app/models/foreman_acd/taxonomy_extensions.rb +17 -0
  23. data/app/services/foreman_acd/app_configurator.rb +54 -0
  24. data/app/services/foreman_acd/app_deployer.rb +151 -0
  25. data/app/services/foreman_acd/inventory_creator.rb +54 -0
  26. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +30 -0
  27. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
  28. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  29. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  30. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
  31. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
  32. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
  33. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
  34. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
  35. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
  36. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
  37. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
  38. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
  39. data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -20
  40. data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
  41. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  42. data/app/views/foreman_acd/app_definitions/index.html.erb +10 -6
  43. data/app/views/foreman_acd/app_instances/_form.html.erb +12 -10
  44. data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
  45. data/app/views/foreman_acd/app_instances/index.html.erb +87 -9
  46. data/app/views/foreman_acd/app_instances/report.html.erb +22 -0
  47. data/app/views/templates/job/run_acd_ansible_playbook.erb +62 -0
  48. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  49. data/app/views/ui_acd/app.json.rabl +6 -2
  50. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  51. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  52. data/config/routes.rb +35 -1
  53. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  54. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  55. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  56. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  57. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
  58. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
  59. data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
  60. data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
  61. data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
  62. data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
  63. data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
  64. data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
  65. data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
  66. data/db/seeds.d/62_acd_proxy_feature.rb +4 -0
  67. data/db/seeds.d/75-job_templates.rb +13 -0
  68. data/lib/foreman_acd/engine.rb +21 -3
  69. data/lib/foreman_acd/plugin.rb +112 -20
  70. data/lib/foreman_acd/version.rb +1 -1
  71. data/locale/en/foreman_acd.edit.po +326 -0
  72. data/locale/en/foreman_acd.po +232 -2
  73. data/locale/en/foreman_acd.po.time_stamp +0 -0
  74. data/locale/foreman_acd.pot +343 -8
  75. data/package.json +1 -1
  76. data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
  77. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +391 -0
  78. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  79. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +303 -0
  80. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +15 -0
  81. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  82. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +269 -0
  83. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +9 -0
  84. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  85. data/webpack/components/ApplicationDefinition/index.js +35 -0
  86. data/webpack/components/ApplicationInstance/ApplicationInstance.js +451 -0
  87. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  88. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +247 -0
  89. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +15 -0
  90. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +309 -0
  91. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +10 -0
  92. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  93. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  94. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  95. data/webpack/components/ApplicationInstance/index.js +37 -0
  96. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +148 -0
  97. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +44 -0
  98. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +42 -0
  99. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -0
  100. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +38 -0
  101. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
  102. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  103. data/webpack/components/ApplicationInstanceReport/index.js +25 -0
  104. data/webpack/components/ParameterSelection/ParameterSelection.js +131 -192
  105. data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
  106. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +87 -110
  107. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
  108. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  109. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
  110. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  111. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  112. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  113. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  114. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  115. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  116. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  117. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  118. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  119. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  120. data/webpack/components/ParameterSelection/index.js +6 -8
  121. data/webpack/components/common/AddTableEntry.js +30 -0
  122. data/webpack/components/common/DeleteTableEntry.js +39 -0
  123. data/webpack/components/common/EasyHeaderFormatter.js +18 -0
  124. data/webpack/components/common/EditTableEntry.js +50 -0
  125. data/webpack/components/common/ExtSelect.js +43 -0
  126. data/webpack/components/common/LockTableEntry.js +60 -0
  127. data/webpack/components/common/RailsData.js +27 -0
  128. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  129. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  130. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  131. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  132. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  133. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  134. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  135. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  136. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  137. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  138. data/webpack/helper.js +20 -0
  139. data/webpack/index.js +6 -0
  140. data/webpack/reducer.js +43 -3
  141. metadata +114 -20
@@ -0,0 +1,22 @@
1
+ <% title _("Provisioning details for application instance #{@app_instance}") %>
2
+
3
+ <% content_for(:javascripts) do %>
4
+ <%= webpacked_plugins_js_for :foreman_acd %>
5
+ <% end %>
6
+ <% content_for(:stylesheets) do %>
7
+ <%= webpacked_plugins_css_for :foreman_acd %>
8
+ <% end %>
9
+
10
+ <%
11
+ json = {
12
+ "mode": 'lastReport',
13
+ "appInstanceName": @app_instance.name,
14
+ "hosts": @report_hosts,
15
+ "deployTaskUrl": foreman_tasks_task_path(@app_instance.last_deploy_task),
16
+ "configureJobUrl": job_invocations_path(search: "description ~ \"ACD application #{@app_instance.name}\"")
17
+ }
18
+ %>
19
+
20
+ <div id='report'></div>
21
+ <%= mount_react_component('ApplicationInstanceReport', "#report", json.to_json) %>
22
+ </div
@@ -0,0 +1,62 @@
1
+ <%#
2
+ kind: job_template
3
+ name: Run ACD Ansible Playbook - ACD Default
4
+ model: JobTemplate
5
+ job_category: Application Centric Deployment
6
+ description_format: "Run Ansible playbook %{playbook_name} for ACD application %{application_name}"
7
+ feature: run_acd_ansible_playbook
8
+ provider_type: ACD
9
+ template_inputs:
10
+ - name: application_name
11
+ description: The name of the ACD application instance to run
12
+ input_type: user
13
+ required: true
14
+ advanced: false
15
+ - name: playbook_id
16
+ description: The id of the Ansible playbook to run
17
+ input_type: user
18
+ required: true
19
+ advanced: false
20
+ - name: playbook_file
21
+ description: The playbook file of to the Ansible playbook
22
+ input_type: user
23
+ required: true
24
+ advanced: false
25
+ - name: inventory
26
+ description: The Ansible inventory
27
+ input_type: user
28
+ required: true
29
+ advanced: false
30
+ - name: extra_vars
31
+ description: Set ansible-playbook extra vars
32
+ input_type: user
33
+ required: false
34
+ advanced: true
35
+ - name: verbose
36
+ description: Whether to run the ansible-playbook in verbose mode or not.
37
+ input_type: user
38
+ options: "0 - Normal\n1 - Verbose\n2 - More Verbose\n3 - Debug\n4 - Connection Debug"
39
+ default: "0 - Normal"
40
+ required: false
41
+ advanced: true
42
+ - name: tags
43
+ description: List of playbook tags to specify which tasks to execute.
44
+ input_type: user
45
+ required: false
46
+ advanced: true
47
+ - name: skip_tags
48
+ description: List of playbook tags to skip certain tasks.
49
+ input_type: user
50
+ required: false
51
+ advanced: true
52
+ %>
53
+
54
+ application_name: <%= input('application_name') %>
55
+ playbook_id: <%= input('playbook_id') %>
56
+ playbook_file: <%= input('playbook_file') %>
57
+ extra_vars: <%= input('extra_vars') %>
58
+ verbose: <%= input('verbose') %>
59
+ tags: <%= input('tags') %>
60
+ skip_tags: <%= input('skip_tags') %>
61
+ inventory: |
62
+ <%= indent(2) { input('inventory') } %>
@@ -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, :hostgroup_id, :parameters, :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,9 +2,23 @@
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
+ end
9
+
10
+ member do
11
+ get 'import_vars'
12
+ end
13
+ end
5
14
  resources :app_definitions, :controller => 'foreman_acd/app_definitions' do
6
15
  collection do
7
16
  get 'auto_complete_search'
17
+ get 'import'
18
+ end
19
+
20
+ member do
21
+ get 'export'
8
22
  end
9
23
  end
10
24
 
@@ -15,10 +29,30 @@ Rails.application.routes.draw do
15
29
 
16
30
  member do
17
31
  post 'deploy'
32
+ get 'report'
33
+ delete 'destroy_with_hosts'
18
34
  end
19
35
  end
20
36
 
37
+ match '/remote_execution', :controller => 'foreman_acd/remote_execution', :action => 'create', :via => [:post]
38
+
21
39
  get 'ui_acd_app/:id', :to => 'ui_acd#app', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_app
22
- get 'ui_acd_fdata/:id', :to => 'ui_acd#fdata', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_fdata
40
+ get 'ui_acd_foreman_data/:id', :to => 'ui_acd#foreman_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_foreman_data
41
+ get 'ui_acd_ansible_data/:id', :to => 'ui_acd#ansible_data', :constraints => { :id => /[\w\.-]+/ }, :as => :ui_acd_ansible_data
42
+
43
+ scope :api, :path => '/api', :defaults => { :format => 'json' } do
44
+ scope '(:apiv)', :defaults => { :apiv => 'v2' },
45
+ :apiv => /v1|v2/, :constraints => ApiConstraints.new(:version => 2) do
46
+ constraints(:id => /[\w\.-]+/) do
47
+ resources :app_definitions, :only => [:show, :index], :controller => 'foreman_acd/api/v2/app_definitions', :as => :acd_api_v2_app_definitions
48
+ resources :app_instances, :only => [:show, :index], :controller => 'foreman_acd/api/v2/app_instances', :as => :api_v2_foreman_acd_app_instances
49
+ resources :ansible_playbooks, :only => [:show, :index], :controller => 'foreman_acd/api/v2/ansible_playbooks', :as => :api_v2_foreman_acd_ansible_playbooks do
50
+ member do
51
+ get 'grab'
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
23
57
  end
24
58
  end
@@ -6,11 +6,9 @@ class CreateAppDefinitions < ActiveRecord::Migration[5.2]
6
6
  create_table :app_definitions do |t|
7
7
  t.string :name, :default => '', :null => false, :limit => 255, :unique => true
8
8
  t.text :description
9
- t.column :hostgroup_id, :integer
10
- t.text :parameters
9
+ t.text :services
11
10
  t.timestamps :null => true
12
11
  end
13
- add_foreign_key :app_definitions, :hostgroups
14
12
  end
15
13
 
16
14
  def down
@@ -7,7 +7,7 @@ class CreateAppInstances < ActiveRecord::Migration[5.2]
7
7
  t.string :name, :default => '', :null => false, :limit => 255, :unique => true
8
8
  t.column :app_definition_id, :integer, :null => false
9
9
  t.text :description
10
- t.text :parameters
10
+ t.text :hosts
11
11
  t.timestamps :null => true
12
12
  end
13
13
  add_foreign_key :app_instances, :app_definitions
@@ -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,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, :locked => 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
@@ -1,17 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'foreman_remote_execution'
4
+
3
5
  module ForemanAcd
4
6
  # This engine connects ForemanAcd with Foreman core
5
7
  class Engine < ::Rails::Engine
6
8
  engine_name 'foreman_acd'
7
9
 
8
10
  config.autoload_paths += Dir["#{config.root}/app/controllers/foreman_acd/concerns"]
11
+ config.autoload_paths += Dir["#{config.root}/app/models"]
12
+ config.autoload_paths += Dir["#{config.root}/app/services"]
9
13
  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
14
  config.autoload_paths += Dir["#{config.root}/app/overrides"]
13
- config.autoload_paths += Dir["#{config.root}/app/services"]
14
15
  config.autoload_paths += Dir["#{config.root}/app/lib"]
16
+ config.autoload_paths += Dir["#{config.root}/lib"]
15
17
 
16
18
  # Add any db migrations
17
19
  initializer 'foreman_acd.load_app_instance_data' do |app|
@@ -39,5 +41,21 @@ module ForemanAcd
39
41
  initializer 'foreman_acd.register_plugin', :before => :finisher_hook do
40
42
  require 'foreman_acd/plugin'
41
43
  end
44
+
45
+ initializer 'foreman_acd.register_actions', :before => :finisher_hook do |_app|
46
+ ForemanTasks.dynflow.require!
47
+ action_paths = %W[#{ForemanAcd::Engine.root}/app/lib/actions]
48
+ ForemanTasks.dynflow.config.eager_load_paths.concat(action_paths)
49
+ end
50
+
51
+ config.to_prepare do
52
+ RemoteExecutionProvider.register(:ACD, AcdProvider)
53
+ ::Taxonomy.include ForemanAcd::TaxonomyExtensions
54
+ ::Host::Managed.prepend ForemanAcd::HostManagedExtensions
55
+ end
56
+
57
+ def self.with_katello?
58
+ defined?(::Katello)
59
+ end
42
60
  end
43
61
  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
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'
14
13
 
15
- menu :top_menu, :app_instances,
16
- :url_hash => { :controller => :'foreman_acd/app_instances', :action => :index },
17
- :caption => 'App Instances',
18
- :parent => :configure_menu
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] },
@@ -39,6 +71,16 @@ Foreman::Plugin.register :foreman_acd do
39
71
  :'foreman_acd/api/v2/app_definitions' => [:destroy] },
40
72
  :resource_type => 'ForemanAcd::AppDefinition'
41
73
 
74
+ permission :export_app_definitions,
75
+ { :'foreman_acd/app_definitions' => [:export],
76
+ :'foreman_acd/api/v2/app_definitions' => [:export] },
77
+ :resource_type => 'ForemanAcd::AppDefinition'
78
+
79
+ permission :import_app_definitions,
80
+ { :'foreman_acd/app_definitions' => [:import],
81
+ :'foreman_acd/api/v2/app_definitions' => [:import] },
82
+ :resource_type => 'ForemanAcd::AppDefinition'
83
+
42
84
  permission :create_app_instances,
43
85
  { :'foreman_acd/app_instances' => [:new, :create],
44
86
  :'foreman_acd/api/v2/app_instances' => [:create] },
@@ -55,26 +97,76 @@ Foreman::Plugin.register :foreman_acd do
55
97
  :resource_type => 'ForemanAcd::AppInstance'
56
98
 
57
99
  permission :destroy_app_instances,
58
- { :'foreman_acd/app_instances' => [:destroy],
59
- :'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] },
60
102
  :resource_type => 'ForemanAcd::AppInstance'
61
103
 
62
104
  permission :deploy_app_instances,
63
105
  { :'foreman_acd/app_instances' => [:deploy],
64
106
  :'foreman_acd/api/v2/app_instances' => [:deploy] },
65
107
  :resource_type => 'ForemanAcd::AppInstance'
108
+
109
+ permission :report_app_instances,
110
+ { :'foreman_acd/app_instances' => [:report],
111
+ :'foreman_acd/api/v2/app_instances' => [:report] },
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'
66
128
  end
67
129
 
68
130
  # Manager Role
69
- role 'Application Centric Deployment Manager', [:create_app_definitions,
70
- :view_app_definitions,
71
- :edit_app_definitions,
72
- :destroy_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]
73
148
 
74
149
  # User Role
75
- role 'Application Centric Deployment User', [:create_app_instances,
76
- :view_app_instances,
77
- :edit_app_instances,
150
+ role 'Application Centric Deployment User', [:create_app_instances, :view_app_instances, :edit_app_instances,
78
151
  :destroy_app_instances,
79
- :deploy_app_instances]
152
+ :deploy_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
163
+
164
+ RemoteExecutionFeature.register(
165
+ :run_acd_ansible_playbook,
166
+ N_('Run playbook for ACD'),
167
+ {
168
+ :description => N_('Run an Ansible playbook to configure ACD application'),
169
+ :provided_inputs => %w[application_name playbook_name playbook_path inventory_path]
170
+ }
171
+ )
80
172
  end