foreman_acd 0.4.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +84 -84
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +103 -11
- data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +21 -3
- data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -0
- data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +9 -1
- data/app/controllers/foreman_acd/app_definitions_controller.rb +117 -15
- data/app/controllers/foreman_acd/app_instances_controller.rb +104 -30
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_instance_mixins.rb +36 -0
- data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
- data/app/controllers/foreman_acd/remote_execution_controller.rb +36 -23
- data/app/controllers/ui_acd_controller.rb +46 -0
- data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +47 -0
- data/app/lib/actions/foreman_acd/run_configurator.rb +45 -0
- data/app/models/concerns/foreman_acd/host_managed_extensions.rb +39 -0
- data/app/models/foreman_acd/acd_provider.rb +36 -0
- data/app/models/foreman_acd/ansible_playbook.rb +32 -14
- data/app/models/foreman_acd/app_definition.rb +24 -1
- data/app/models/foreman_acd/app_instance.rb +85 -5
- data/app/models/foreman_acd/foreman_host.rb +31 -0
- data/app/models/foreman_acd/taxonomy_extensions.rb +17 -0
- data/app/services/foreman_acd/acd_proxy_proxy_selector.rb +17 -0
- data/app/services/foreman_acd/app_configurator.rb +64 -36
- data/app/services/foreman_acd/app_deployer.rb +83 -48
- data/app/services/foreman_acd/inventory_creator.rb +36 -25
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +50 -7
- data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +9 -1
- data/app/views/foreman_acd/ansible_playbooks/index.html.erb +3 -3
- data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +2 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +2 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +6 -0
- data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +2 -0
- data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +2 -0
- data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +6 -0
- data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -1
- data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +2 -0
- data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +2 -0
- data/app/views/foreman_acd/app_definitions/_form.html.erb +9 -1
- data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -5
- data/app/views/foreman_acd/app_definitions/import.html.erb +20 -1
- data/app/views/foreman_acd/app_definitions/index.html.erb +5 -8
- data/app/views/foreman_acd/app_instances/_form.html.erb +4 -4
- data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_instances/index.html.erb +93 -14
- data/app/views/foreman_acd/app_instances/report.html.erb +12 -4
- data/app/views/templates/job/run_acd_ansible_playbook.erb +28 -15
- data/app/views/ui_acd/app_definition.json.rabl +1 -1
- data/app/views/ui_acd/host_report.json.rabl +4 -0
- data/app/views/ui_acd/report_data.json.rabl +10 -0
- data/app/views/ui_acd/validate_hostname.json.rabl +6 -0
- data/config/routes.rb +12 -3
- data/db/migrate/20200917120220_add_ansible_playbook_id.rb +1 -1
- data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +3 -0
- data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +3 -0
- data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
- data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
- data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
- data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
- data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
- data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
- data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
- data/db/migrate/20210316151145_add_git_commit_to_ansible_playbooks.rb +8 -0
- data/db/migrate/20210503122809_add_git_url_to_ansible_playbooks.rb +8 -0
- data/db/migrate/20210818125913_add_is_existing_host_to_foreman_host.rb +8 -0
- data/db/migrate/20210902110645_add_initial_configure_task.rb +8 -0
- data/db/seeds.d/62_acd_proxy_feature.rb +4 -0
- data/db/seeds.d/75-job_templates.rb +6 -1
- data/lib/foreman_acd/engine.rb +40 -3
- data/lib/foreman_acd/plugin.rb +60 -45
- data/lib/foreman_acd/version.rb +1 -1
- data/lib/foreman_acd.rb +30 -0
- data/lib/tasks/foreman_acd_tasks.rake +0 -12
- data/locale/en/foreman_acd.edit.po +326 -0
- data/locale/en/foreman_acd.po +232 -2
- data/{app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb → locale/en/foreman_acd.po.time_stamp} +0 -0
- data/locale/foreman_acd.pot +343 -8
- data/package.json +8 -8
- data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
- data/test/controllers/app_instances_controller_test.rb +8 -3
- data/test/controllers/ui_acd_controller_test.rb +22 -6
- data/test/factories/foreman_acd_factories.rb +18 -4
- data/test/models/acd_provider_test.rb +37 -0
- data/test/models/ansible_playbook_test.rb +11 -0
- data/test/models/app_definition_test.rb +1 -1
- data/test/models/app_instance_test.rb +2 -0
- data/test/models/concerns/host_extensions_test.rb +26 -0
- data/test/models/foreman_host_test.rb +12 -0
- data/webpack/__mocks__/foremanReact/API.js +2 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +3 -0
- data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
- data/webpack/__mocks__/foremanReact/components/ForemanModal/ForemanModalActions.js +2 -0
- data/webpack/__mocks__/foremanReact/components/ForemanModal.js +7 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js +2 -0
- data/webpack/__mocks__/foremanReact/components/common/forms/TextInput.js +2 -0
- data/webpack/__mocks__/foremanReact/components/hosts/powerStatus.js +1 -0
- data/webpack/__snapshots__/helper.test.js.snap +14 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +55 -21
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +14 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +2 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +48 -1
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +4 -0
- data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionConfData_1.fixtures.js +288 -0
- data/webpack/components/ApplicationDefinition/__fixtures__/applicationDefinitionReducer.fixtures.js +79 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinition.test.js +26 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionReducer.test.js +119 -0
- data/webpack/components/ApplicationDefinition/__tests__/ApplicationDefinitionSelectors.test.js +41 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinition.test.js.snap +225 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionReducer.test.js.snap +3033 -0
- data/webpack/components/ApplicationDefinition/__tests__/__snapshots__/ApplicationDefinitionSelectors.test.js.snap +299 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +2 -1
- data/webpack/components/ApplicationDefinition/components/__tests__/AnsiblePlaybookSelector.test.js +41 -0
- data/webpack/components/ApplicationDefinition/components/__tests__/__snapshots__/AnsiblePlaybookSelector.test.js.snap +121 -0
- data/webpack/components/ApplicationDefinition/index.js +8 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.js +214 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImport.scss +1 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportActions.js +161 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportConstants.js +6 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportReducer.js +79 -0
- data/webpack/components/ApplicationDefinitionImport/ApplicationDefinitionImportSelectors.js +8 -0
- data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportConfData_1.fixtures.js +129 -0
- data/webpack/components/ApplicationDefinitionImport/__fixtures__/applicationDefinitionImportReducer.fixtures.js +29 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImport.test.js +20 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportReducer.test.js +43 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/ApplicationDefinitionImportSelectors.test.js +29 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImport.test.js.snap +62 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportReducer.test.js.snap +362 -0
- data/webpack/components/ApplicationDefinitionImport/__tests__/__snapshots__/ApplicationDefinitionImportSelectors.test.js.snap +130 -0
- data/webpack/components/ApplicationDefinitionImport/index.js +32 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +153 -45
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +120 -6
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +5 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceHelper.js +15 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +77 -22
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +4 -0
- data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceConfData_1.fixtures.js +263 -0
- data/webpack/components/ApplicationInstance/__fixtures__/applicationInstanceReducer.fixtures.js +80 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstance.test.js +24 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceReducer.test.js +131 -0
- data/webpack/components/ApplicationInstance/__tests__/ApplicationInstanceSelectors.test.js +44 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstance.test.js.snap +299 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceReducer.test.js.snap +2990 -0
- data/webpack/components/ApplicationInstance/__tests__/__snapshots__/ApplicationInstanceSelectors.test.js.snap +276 -0
- data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +1 -0
- data/webpack/components/ApplicationInstance/components/Service.js +1 -1
- data/webpack/components/ApplicationInstance/components/ServiceCounter.js +1 -1
- data/webpack/components/ApplicationInstance/helper.js +0 -0
- data/webpack/components/ApplicationInstance/index.js +8 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +128 -60
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +17 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +40 -50
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +5 -4
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +19 -14
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -1
- data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportData_1.fixtures.js +349 -0
- data/webpack/components/ApplicationInstanceReport/__fixtures__/applicationInstanceReportReducer.fixtures.js +20 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReport.test.js +47 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportReducer.test.js +41 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/ApplicationInstanceReportSelectors.test.js +26 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReport.test.js.snap +7 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportReducer.test.js.snap +718 -0
- data/webpack/components/ApplicationInstanceReport/__tests__/__snapshots__/ApplicationInstanceReportSelectors.test.js.snap +347 -0
- data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +1 -1
- data/webpack/components/ApplicationInstanceReport/components/__tests__/ReportViewer.test.js +24 -0
- data/webpack/components/ApplicationInstanceReport/components/__tests__/__snapshots__/ReportViewer.test.js.snap +24 -0
- data/webpack/components/ApplicationInstanceReport/index.js +8 -3
- data/webpack/components/ExistingHostSelection/ExistingHostSelection.js +104 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelection.scss +15 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionActions.js +71 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionConstants.js +4 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionHelper.js +0 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionReducer.js +90 -0
- data/webpack/components/ExistingHostSelection/ExistingHostSelectionSelectors.js +8 -0
- data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionConfData_1.fixtures.js +191 -0
- data/webpack/components/ExistingHostSelection/__fixtures__/existingHostSelectionReducer.fixtures.js +203 -0
- data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelection.test.js +19 -0
- data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionReducer.test.js +59 -0
- data/webpack/components/ExistingHostSelection/__tests__/ExistingHostSelectionSelectors.test.js +36 -0
- data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelection.test.js.snap +35 -0
- data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionReducer.test.js.snap +614 -0
- data/webpack/components/ExistingHostSelection/__tests__/__snapshots__/ExistingHostSelectionSelectors.test.js.snap +27 -0
- data/webpack/components/ExistingHostSelection/components/ServiceSelector.js +48 -0
- data/webpack/components/ExistingHostSelection/components/__tests__/ServiceSelector.test.js +35 -0
- data/webpack/components/ExistingHostSelection/components/__tests__/__snapshots__/ServiceSelector.test.js.snap +77 -0
- data/webpack/components/ExistingHostSelection/index.js +26 -0
- data/webpack/components/ParameterSelection/ParameterSelection.js +138 -15
- data/webpack/components/ParameterSelection/ParameterSelection.scss +7 -0
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +52 -9
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +3 -0
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +62 -25
- data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +1 -0
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +116 -84
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +10 -4
- data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +36 -46
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +33 -25
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +84 -112
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +1488 -872
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +117 -79
- data/webpack/components/ParameterSelection/index.js +2 -1
- data/webpack/components/SyncGitRepo/SyncGitRepo.js +202 -0
- data/webpack/components/SyncGitRepo/SyncGitRepo.scss +1 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoActions.js +123 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoConstants.js +8 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoReducer.js +80 -0
- data/webpack/components/SyncGitRepo/SyncGitRepoSelectors.js +6 -0
- data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoConfData_1.fixtures.js +7 -0
- data/webpack/components/SyncGitRepo/__fixtures__/syncGitRepoReducer.fixtures.js +44 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepo.test.js +27 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoReducer.test.js +95 -0
- data/webpack/components/SyncGitRepo/__tests__/SyncGitRepoSelectors.test.js +32 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepo.test.js.snap +31 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoReducer.test.js.snap +137 -0
- data/webpack/components/SyncGitRepo/__tests__/__snapshots__/SyncGitRepoSelectors.test.js.snap +13 -0
- data/webpack/components/SyncGitRepo/components/FormTextInput.js +42 -0
- data/webpack/components/SyncGitRepo/components/ScmTypeSelector.js +47 -0
- data/webpack/components/SyncGitRepo/index.js +28 -0
- data/webpack/components/common/DeleteTableEntry.js +18 -4
- data/webpack/components/common/EditTableEntry.js +50 -0
- data/webpack/components/common/ExtTextInput.js +43 -0
- data/webpack/components/common/LockTableEntry.js +60 -0
- data/webpack/components/common/__tests__/EditTableEntry.test.js +53 -0
- data/webpack/components/common/__tests__/LockTableEntry.test.js +35 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +40 -2
- data/webpack/components/common/__tests__/__snapshots__/EditTableEntry.test.js.snap +81 -0
- data/webpack/components/common/__tests__/__snapshots__/LockTableEntry.test.js.snap +60 -0
- data/webpack/helper.js +20 -1
- data/webpack/helper.test.js +37 -0
- data/webpack/index.js +7 -0
- data/webpack/js-yaml.js +3874 -0
- data/webpack/reducer.js +16 -1
- metadata +182 -11
- data/app/views/foreman_acd/app_instances/deploy.html.erb +0 -19
- data/webpack/components/common/EasyHeaderFormatter.js +0 -18
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +0 -35
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +0 -41
@@ -9,7 +9,7 @@ module ForemanAcd
|
|
9
9
|
before_action :find_resource, :only => [:edit, :update, :destroy, :export]
|
10
10
|
before_action :read_hostgroups, :only => [:edit, :new, :import]
|
11
11
|
before_action :read_ansible_playbooks, :only => [:edit, :new]
|
12
|
-
before_action :
|
12
|
+
before_action :assign_ansible_playbook, :only => [:create]
|
13
13
|
|
14
14
|
def index
|
15
15
|
@app_definitions = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
@@ -17,7 +17,7 @@ module ForemanAcd
|
|
17
17
|
|
18
18
|
def read_ansible_playbooks
|
19
19
|
# Only use ansible playbooks for which the user pressed import group vars once.
|
20
|
-
@ansible_playbooks = AnsiblePlaybook.where.not(vars
|
20
|
+
@ansible_playbooks = AnsiblePlaybook.where.not(:vars => nil).map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
21
21
|
end
|
22
22
|
|
23
23
|
def read_hostgroups
|
@@ -30,18 +30,24 @@ module ForemanAcd
|
|
30
30
|
|
31
31
|
def create
|
32
32
|
@app_definition = AppDefinition.new(app_definition_params)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
begin
|
34
|
+
if @app_definition.save!
|
35
|
+
process_success
|
36
|
+
else
|
37
|
+
process_error
|
38
|
+
end
|
39
|
+
rescue StandardError, ValidationError => e
|
40
|
+
if params[:foreman_acd_app_definition_import].present?
|
41
|
+
AnsiblePlaybook.find(params[:foreman_acd_app_definition][:acd_ansible_playbook_id]).delete if params[:foreman_acd_app_definition][:acd_ansible_playbook_id].present?
|
42
|
+
end
|
43
|
+
redirect_to new_app_definition_path, :flash => { :error => _(e.message) }
|
37
44
|
end
|
38
45
|
end
|
39
46
|
|
40
|
-
def edit
|
41
|
-
end
|
47
|
+
def edit; end
|
42
48
|
|
43
49
|
def update
|
44
|
-
if @app_definition.
|
50
|
+
if @app_definition.update(app_definition_params)
|
45
51
|
process_success
|
46
52
|
else
|
47
53
|
process_error
|
@@ -60,6 +66,8 @@ module ForemanAcd
|
|
60
66
|
case params[:action]
|
61
67
|
when 'export'
|
62
68
|
:export
|
69
|
+
when 'import'
|
70
|
+
:import
|
63
71
|
else
|
64
72
|
super
|
65
73
|
end
|
@@ -70,16 +78,110 @@ module ForemanAcd
|
|
70
78
|
end
|
71
79
|
|
72
80
|
def export
|
73
|
-
|
74
|
-
|
75
|
-
|
81
|
+
dir_path = "#{Dir.mktmpdir}/#{@app_definition.name}.tar"
|
82
|
+
`tar -cvf "#{dir_path}" "#{@app_definition.ansible_playbook.path}" #{export_app_template_data.path}`
|
83
|
+
logger.info("Successfully created application template tar file for #{@app_definition.name}")
|
84
|
+
send_file dir_path
|
85
|
+
rescue StandardError => e
|
86
|
+
logger.info("Export of #{@app_definition.name} failed with the error: #{e}")
|
87
|
+
redirect_to app_definitions_path, :flash => { :error => _(e.message) }
|
88
|
+
end
|
89
|
+
|
90
|
+
def handle_file_upload
|
91
|
+
return unless params[:app_definition_file] && (raw_directory = params[:app_definition_file])
|
92
|
+
begin
|
93
|
+
dir = Dir.mktmpdir
|
94
|
+
untar_import_directory(raw_directory, dir)
|
95
|
+
ansible_file = Dir.glob("#{dir}/tmp/*.yaml")
|
96
|
+
data = JSON.parse(YAML.load_file(ansible_file[0]).to_json) if ansible_file
|
97
|
+
ansible_playbook_import = data.find { |d| d if d['ansible_playbook'] }
|
98
|
+
|
99
|
+
session[:ansible_playbook_params] = { :dir => dir, :ansible_playbook => ansible_playbook_import['ansible_playbook'] }
|
100
|
+
render :json => { :ansible_services => create_ansible_services(data, ansible_playbook_import) }, :status => :ok
|
101
|
+
rescue StandardError => e
|
102
|
+
render :json => { :status => 'error', :message => e }, :status => :internal_server_error
|
103
|
+
end
|
76
104
|
end
|
77
105
|
|
78
106
|
private
|
79
107
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
108
|
+
def export_app_template_data
|
109
|
+
file = Tempfile.open([@app_definition.name, '.yaml'])
|
110
|
+
data = JSON.parse(@app_definition.services).append(:ansible_playbook => @app_definition.ansible_playbook.attributes.except('id', 'created_at', 'updated_at').as_json).to_yaml
|
111
|
+
file.write(data)
|
112
|
+
file.close
|
113
|
+
logger.info("Successfully created yaml file for app_template data: #{file.path}")
|
114
|
+
file
|
115
|
+
rescue StandardError => e
|
116
|
+
logger.info("Creation of app template data failed: #{e}")
|
117
|
+
redirect_to app_definitions_path, :flash => { :error => _(e.message) }
|
118
|
+
end
|
119
|
+
|
120
|
+
def rename_path_name(dir_path)
|
121
|
+
return dir_path unless Dir.exist?(dir_path)
|
122
|
+
ind = 1
|
123
|
+
loop do
|
124
|
+
path = dir_path
|
125
|
+
path += ind.to_s
|
126
|
+
return path unless Dir.exist?(path)
|
127
|
+
ind += 1
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def create_ansible_playbook(dir, ansible_playbook, dir_path)
|
132
|
+
FileUtils.cp_r "#{dir}/#{ansible_playbook['path']}/.", dir_path
|
133
|
+
ansible_playbook['path'] = dir_path
|
134
|
+
ansible_playbook['name'] = File.basename(dir_path)
|
135
|
+
new_playbook = AnsiblePlaybook.create(ansible_playbook)
|
136
|
+
new_playbook
|
137
|
+
rescue StandardError => e
|
138
|
+
logger.info("Error while creating AnsiblePlaybook: #{e}")
|
139
|
+
end
|
140
|
+
|
141
|
+
def create_ansible_services(data, ansible_playbook_import)
|
142
|
+
ansible_services = []
|
143
|
+
session[:data_services] = data - [ansible_playbook_import]
|
144
|
+
session[:data_services].each do |d|
|
145
|
+
ansible_services.append({ :id => d['id'], :value => d['name'] })
|
146
|
+
end
|
147
|
+
ansible_services
|
148
|
+
end
|
149
|
+
|
150
|
+
def untar_import_directory(directory, dir)
|
151
|
+
`tar -xvf #{directory.path} -C #{dir}`
|
152
|
+
rescue StandardError => e
|
153
|
+
logger.info("Failed to untar imported directory: #{e}")
|
154
|
+
end
|
155
|
+
|
156
|
+
def assign_ansible_playbook
|
157
|
+
return unless params[:foreman_acd_app_definition_import]
|
158
|
+
dir_path = "#{ForemanAcd.ansible_playbook_path}/#{session[:ansible_playbook_params][:ansible_playbook]['name'].split(/\W+/).join('_')}"
|
159
|
+
|
160
|
+
# Append path and name of ansible with n + 1 if ansible_playbook with same name or name[n] exists
|
161
|
+
ansible_playbook = create_ansible_playbook(session[:ansible_playbook_params][:dir], session[:ansible_playbook_params][:ansible_playbook], rename_path_name(dir_path))
|
162
|
+
params[:foreman_acd_app_definition][:acd_ansible_playbook_id] = ansible_playbook.id
|
163
|
+
|
164
|
+
begin
|
165
|
+
services = JSON.parse(params[:foreman_acd_app_definition_import][:services])
|
166
|
+
flag = 0
|
167
|
+
session[:data_services].each do |d|
|
168
|
+
hostgroup = services.find { |service| service['name'] == d['name'] }['hostgroup']
|
169
|
+
if hostgroup == ''
|
170
|
+
flag += 1
|
171
|
+
break
|
172
|
+
else
|
173
|
+
d['hostgroup'] = hostgroup
|
174
|
+
end
|
175
|
+
end
|
176
|
+
params[:foreman_acd_app_definition][:services] = session[:data_services].to_json
|
177
|
+
rescue StandardError => e
|
178
|
+
ansible_playbook&.destroy
|
179
|
+
redirect_to({ :action => 'import' }, :error => _("Hostgroups are not configured properly: #{e}"))
|
180
|
+
else
|
181
|
+
ansible_playbook&.destroy
|
182
|
+
redirect_to({ :action => 'import' }, :error => _('Some services are not assigned Hostgroups')) if flag.positive?
|
183
|
+
end
|
184
|
+
session[:data_services] = nil
|
83
185
|
end
|
84
186
|
end
|
85
187
|
end
|
@@ -3,43 +3,57 @@
|
|
3
3
|
module ForemanAcd
|
4
4
|
# Application Instance Controller
|
5
5
|
class AppInstancesController < ::ForemanAcd::ApplicationController
|
6
|
-
include Foreman::Controller::AutoCompleteSearch
|
6
|
+
include ::Foreman::Controller::AutoCompleteSearch
|
7
7
|
include ::ForemanAcd::Concerns::AppInstanceParameters
|
8
|
+
include ::ForemanAcd::Concerns::AppInstanceMixins
|
8
9
|
|
9
|
-
before_action :find_resource, :only => [:edit, :update, :
|
10
|
+
before_action :find_resource, :only => [:edit, :update, :destroy_with_hosts, :deploy, :report]
|
10
11
|
before_action :read_applications, :only => [:new, :edit]
|
12
|
+
before_action :find_taxonomy
|
13
|
+
helper_method :collect_hosts_data
|
11
14
|
|
12
15
|
def index
|
13
|
-
@app_instances = resource_base.
|
16
|
+
@app_instances = resource_base.where(:organization => @organization).
|
17
|
+
where(:location => @location).
|
18
|
+
search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
14
19
|
end
|
15
20
|
|
16
21
|
def new
|
17
22
|
@app_instance = AppInstance.new
|
23
|
+
@app_instance.organization = @organization
|
24
|
+
@app_instance.location = @location
|
18
25
|
end
|
19
26
|
|
20
27
|
def create
|
21
28
|
@app_instance = AppInstance.new(app_instance_params)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
begin
|
30
|
+
if @app_instance.save!
|
31
|
+
app_instance_has_foreman_hosts
|
32
|
+
process_success
|
33
|
+
else
|
34
|
+
process_error
|
35
|
+
end
|
36
|
+
rescue StandardError, ValidationError => e
|
37
|
+
redirect_to new_app_instance_path, :flash => { :error => _(e.message) }
|
26
38
|
end
|
27
39
|
end
|
28
40
|
|
29
|
-
def edit
|
30
|
-
end
|
41
|
+
def edit; end
|
31
42
|
|
32
43
|
def update
|
33
44
|
if @app_instance.update(app_instance_params)
|
45
|
+
app_instance_has_foreman_hosts
|
34
46
|
process_success
|
35
47
|
else
|
36
48
|
process_error
|
37
49
|
end
|
38
50
|
end
|
39
51
|
|
40
|
-
def
|
52
|
+
def destroy_with_hosts
|
53
|
+
@app_instance = AppInstance.find(params[:id])
|
54
|
+
@app_instance.clean_hosts_by_id(params[:foreman_host_ids]) if params[:foreman_host_ids]
|
41
55
|
if @app_instance.destroy
|
42
|
-
|
56
|
+
redirect_to app_instances_path, :flash => { :success => _('Successfully deleted %s') % @app_instance }
|
43
57
|
else
|
44
58
|
process_error
|
45
59
|
end
|
@@ -51,42 +65,102 @@ module ForemanAcd
|
|
51
65
|
:deploy
|
52
66
|
when 'report'
|
53
67
|
:report
|
68
|
+
when 'destroy_with_hosts'
|
69
|
+
:destroy
|
54
70
|
else
|
55
71
|
super
|
56
72
|
end
|
57
73
|
end
|
58
74
|
|
59
75
|
def deploy
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
@app_instance.
|
65
|
-
|
76
|
+
value = false
|
77
|
+
@app_instance.update!({ :last_deploy_task_id => nil,
|
78
|
+
:initial_configure_task_id => nil })
|
79
|
+
@app_instance.foreman_hosts.each { |f| f.update!(:last_progress_report => nil) }
|
80
|
+
@app_instance.clean_all_hosts if params[:delete_hosts]
|
81
|
+
value = safe_deploy? if params[:safe_deploy]
|
82
|
+
session.delete(:remember_hosts)
|
83
|
+
logger.info('Run async foreman task to deploy hosts')
|
84
|
+
async_task = ForemanTasks.async_task(::Actions::ForemanAcd::DeployAllHosts, @app_instance, value)
|
85
|
+
@app_instance.update!(:last_deploy_task => async_task)
|
86
|
+
|
87
|
+
redirect_to report_app_instance_path, :success => _('Started task to deploy hosts for %s') % @app_instance
|
88
|
+
rescue StandardError => e
|
89
|
+
error_msg = "Error happend while deploying hosts of #{@app_instance}: #{e.message}"
|
90
|
+
logger.error("#{error_msg} - #{e.class}\n#{e.backtrace.join($INPUT_RECORD_SEPARATOR)}")
|
91
|
+
process_error :error_msg => error_msg
|
92
|
+
end
|
66
93
|
|
67
|
-
|
94
|
+
def safe_deploy?
|
95
|
+
return false if session[:remember_hosts].empty?
|
96
|
+
session[:remember_hosts]
|
68
97
|
end
|
69
98
|
|
70
99
|
def report
|
71
|
-
|
72
|
-
@report_hosts
|
100
|
+
@report_hosts = collect_host_report_data(@app_instance)
|
101
|
+
logger.debug("app instance host details: #{@report_hosts.inspect}")
|
102
|
+
end
|
103
|
+
|
104
|
+
def app_instance_has_foreman_hosts
|
105
|
+
hosts = JSON.parse(@app_instance.hosts)
|
106
|
+
session[:remember_hosts] = []
|
107
|
+
hosts.each do |h|
|
108
|
+
if @app_instance.foreman_hosts.where(:hostname => h['hostname']).exists?
|
109
|
+
old_host = @app_instance.foreman_hosts.find_by(:hostname => h['hostname'])
|
110
|
+
|
111
|
+
@app_instance.foreman_hosts.where(:hostname => h['hostname']).
|
112
|
+
update(:service => h['service'], :description => h['description'],
|
113
|
+
:foremanParameters => JSON.dump(h['foremanParameters']), :ansibleParameters => JSON.dump(h['ansibleParameters']))
|
114
|
+
|
115
|
+
updated_host = @app_instance.foreman_hosts.find_by(:hostname => h['hostname'])
|
116
|
+
|
117
|
+
# Store hosts if updated for safe deploy
|
118
|
+
session[:remember_hosts] << updated_host.id if updated_host.updated_at != old_host.updated_at
|
119
|
+
else
|
120
|
+
@app_instance.foreman_hosts.create(:hostname => h['hostname'],
|
121
|
+
:service => h['service'],
|
122
|
+
:description => h['description'],
|
123
|
+
:is_existing_host => h['isExistingHost'],
|
124
|
+
:foremanParameters => JSON.dump(h['foremanParameters']),
|
125
|
+
:ansibleParameters => JSON.dump(h['ansibleParameters']))
|
126
|
+
# Store new hosts for safe deploy
|
127
|
+
session[:remember_hosts] << @app_instance.foreman_hosts.find_by(:hostname => h['hostname']).id
|
128
|
+
end
|
129
|
+
end
|
73
130
|
|
74
|
-
|
131
|
+
# Delete record if json hosts are deleted
|
132
|
+
deleted_json_hosts = @app_instance.foreman_hosts.pluck('hostname') - hosts.pluck('hostname')
|
133
|
+
@app_instance.foreman_hosts.where(:hostname => deleted_json_hosts).destroy_all if deleted_json_hosts
|
134
|
+
end
|
135
|
+
|
136
|
+
def collect_hosts_data
|
137
|
+
hosts_data = []
|
138
|
+
@app_instance.foreman_hosts.each do |h|
|
139
|
+
hosts_data << {
|
140
|
+
:id => h.id,
|
141
|
+
:hostname => h.hostname,
|
142
|
+
:service => h.service,
|
143
|
+
:description => h.description,
|
144
|
+
:isExistingHost => h.is_existing_host,
|
145
|
+
:foremanParameters => JSON.parse(h.foremanParameters),
|
146
|
+
:ansibleParameters => JSON.parse(h.ansibleParameters)
|
147
|
+
}
|
148
|
+
end
|
149
|
+
hosts_data
|
75
150
|
end
|
76
151
|
|
77
152
|
private
|
78
153
|
|
79
|
-
def
|
80
|
-
@
|
154
|
+
def find_taxonomy
|
155
|
+
@organization = Organization.current
|
156
|
+
redirect_to '/select_organization?toState=' + request.path and return unless @organization
|
157
|
+
|
158
|
+
@location = Location.current
|
159
|
+
redirect_to root_path, :error => 'Select a location to show App Instances' and return unless @location
|
81
160
|
end
|
82
161
|
|
83
|
-
def
|
84
|
-
|
85
|
-
app_hosts.each do |host_data|
|
86
|
-
host = Host.find(host_data['foreman_host_id'])
|
87
|
-
report_data << { id: host.id, name: host_data['hostname'], hostname: host.hostname, hostUrl: host_path(host), progress_report_id: host.progress_report_id}
|
88
|
-
end
|
89
|
-
report_data
|
162
|
+
def read_applications
|
163
|
+
@applications = AppDefinition.all.map { |elem| { elem.id => elem.name } }.reduce({}) { |h, v| h.merge v }
|
90
164
|
end
|
91
165
|
end
|
92
166
|
end
|
@@ -9,7 +9,7 @@ module ForemanAcd
|
|
9
9
|
class_methods do
|
10
10
|
def ansible_playbook_params_filter
|
11
11
|
Foreman::ParameterFilter.new(::ForemanAcd::AnsiblePlaybook).tap do |filter|
|
12
|
-
filter.permit(:name, :description, :scm_type, :path, :playfile)
|
12
|
+
filter.permit(:name, :description, :scm_type, :path, :git_commit, :git_url, :playfile, :location_ids => [], :organization_ids => [])
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -9,7 +9,7 @@ module ForemanAcd
|
|
9
9
|
class_methods do
|
10
10
|
def app_definition_params_filter
|
11
11
|
Foreman::ParameterFilter.new(::ForemanAcd::AppDefinition).tap do |filter|
|
12
|
-
filter.permit(:name, :description, :acd_ansible_playbook_id, :services, :ansible_vars_all)
|
12
|
+
filter.permit(:name, :description, :acd_ansible_playbook_id, :services, :ansible_vars_all, :location_ids => [], :organization_ids => [])
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForemanAcd
|
4
|
+
module Concerns
|
5
|
+
# Shared code for AppInstance API and UI controller
|
6
|
+
module AppInstanceMixins
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
def collect_host_report_data(app_instance)
|
10
|
+
report_data = []
|
11
|
+
|
12
|
+
app_instance.foreman_hosts.each do |foreman_host|
|
13
|
+
a_host = {
|
14
|
+
:id => nil,
|
15
|
+
:name => foreman_host.hostname,
|
16
|
+
:build => nil,
|
17
|
+
:hostUrl => nil,
|
18
|
+
:progress_report => foreman_host.last_progress_report.empty? ? [] : JSON.parse(foreman_host.last_progress_report)
|
19
|
+
}
|
20
|
+
|
21
|
+
if foreman_host.host.present?
|
22
|
+
a_host.update({
|
23
|
+
:id => foreman_host.host.id,
|
24
|
+
:build => foreman_host.host.build,
|
25
|
+
:hostUrl => host_path(foreman_host.host),
|
26
|
+
:isExistingHost => foreman_host.is_existing_host,
|
27
|
+
:powerStatusUrl => power_api_host_path(foreman_host.host)
|
28
|
+
})
|
29
|
+
end
|
30
|
+
report_data << OpenStruct.new(a_host)
|
31
|
+
end
|
32
|
+
report_data
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -9,7 +9,7 @@ module ForemanAcd
|
|
9
9
|
class_methods do
|
10
10
|
def app_instance_params_filter
|
11
11
|
Foreman::ParameterFilter.new(::ForemanAcd::AppInstance).tap do |filter|
|
12
|
-
filter.permit(:name, :app_definition_id, :description, :hosts, :ansible_vars_all)
|
12
|
+
filter.permit(:name, :app_definition_id, :description, :hosts, :ansible_vars_all, :organization_id, :location_id)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -3,29 +3,41 @@
|
|
3
3
|
module ForemanAcd
|
4
4
|
# Class to run remote execution jobs
|
5
5
|
class RemoteExecutionController < JobInvocationsController
|
6
|
-
|
7
6
|
def new
|
8
|
-
|
9
|
-
|
7
|
+
set_app_instance
|
8
|
+
result, job = init_configuration
|
9
|
+
|
10
|
+
if result.success == true
|
11
|
+
@composer = job
|
12
|
+
else
|
13
|
+
redirect_to(app_instances_path, :error => _("Coult not create remote execution job to configure the app '%{app_instance}': %{msg}") % {
|
14
|
+
:app_instance => @app_instance, :msg => result.error
|
15
|
+
})
|
16
|
+
end
|
10
17
|
end
|
11
18
|
|
12
19
|
def create
|
13
20
|
customize_first = params[:customize] || false
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
composer.trigger
|
21
|
+
begin
|
22
|
+
set_app_instance
|
23
|
+
result, job = init_configuration
|
24
|
+
|
25
|
+
unless result.success == true
|
26
|
+
return redirect_to(app_instances_path, :error => _("Coult not create remote execution job to configure the app '%{app_instance}': %{msg}") % {
|
27
|
+
:app_instance => @app_instance, :msg => result.error
|
28
|
+
})
|
23
29
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
|
31
|
+
@composer = job
|
32
|
+
if customize_first == false
|
33
|
+
@composer.trigger!
|
34
|
+
redirect_to job_invocation_path(@composer.job_invocation)
|
35
|
+
else
|
36
|
+
# redirect to the job itself if we want to customize the job
|
37
|
+
render :action => 'new'
|
38
|
+
end
|
39
|
+
rescue StandardError => e
|
40
|
+
redirect_to app_instances_path, :error => _("#{job}, #{e}")
|
29
41
|
end
|
30
42
|
end
|
31
43
|
|
@@ -37,13 +49,14 @@ module ForemanAcd
|
|
37
49
|
|
38
50
|
private
|
39
51
|
|
40
|
-
def
|
41
|
-
app_instance = ForemanAcd::AppInstance.find_by(:
|
42
|
-
|
52
|
+
def set_app_instance
|
53
|
+
@app_instance = ForemanAcd::AppInstance.find_by(:id => params[:id])
|
54
|
+
end
|
43
55
|
|
44
|
-
|
45
|
-
logger.debug("Creating
|
46
|
-
|
56
|
+
def init_configuration
|
57
|
+
logger.debug("Creating job to configure the app #{@app_instance}. Customize first: #{params[:customize]}")
|
58
|
+
app_configurator = ForemanAcd::AppConfigurator.new(@app_instance)
|
59
|
+
app_configurator.configure
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
# Controller to create JSON data to be used in react app
|
4
4
|
class UiAcdController < ::Api::V2::BaseController
|
5
|
+
include ::ForemanAcd::Concerns::AppInstanceMixins
|
6
|
+
|
5
7
|
def app
|
6
8
|
@app_data = {}
|
7
9
|
app_definition = ForemanAcd::AppDefinition.find(params[:id])
|
@@ -16,6 +18,23 @@ class UiAcdController < ::Api::V2::BaseController
|
|
16
18
|
@ansible_data = collect_ansible_data(params['id'])
|
17
19
|
end
|
18
20
|
|
21
|
+
def report_data
|
22
|
+
@report_data = collect_report_data(params['id'])
|
23
|
+
end
|
24
|
+
|
25
|
+
def validate_hostname
|
26
|
+
@host_validation = hostname_duplicate?(params['appDefId'].to_i, params['serviceId'].to_i, params['hostname'])
|
27
|
+
end
|
28
|
+
|
29
|
+
def action_permission
|
30
|
+
case params[:action]
|
31
|
+
when 'app', 'foreman_data', 'ansible_data', 'validate_hostname'
|
32
|
+
:view
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
19
38
|
private
|
20
39
|
|
21
40
|
def collect_foreman_data(hostgroup_id)
|
@@ -34,4 +53,31 @@ class UiAcdController < ::Api::V2::BaseController
|
|
34
53
|
def collect_ansible_data(playbook_id)
|
35
54
|
ForemanAcd::AnsiblePlaybook.find(playbook_id).as_unified_structobj
|
36
55
|
end
|
56
|
+
|
57
|
+
def collect_report_data(app_instance_id)
|
58
|
+
app_instance = ForemanAcd::AppInstance.find(app_instance_id)
|
59
|
+
|
60
|
+
report_data = {
|
61
|
+
:hosts => collect_host_report_data(app_instance),
|
62
|
+
:deploymentState => app_instance.deployment_state.to_s,
|
63
|
+
:initialConfigureState => app_instance.initial_configure_state.to_s
|
64
|
+
}
|
65
|
+
report_data['initialConfigureJobUrl'] = job_invocation_path(app_instance.initial_configure_job) unless app_instance.initial_configure_job.nil?
|
66
|
+
|
67
|
+
OpenStruct.new(report_data)
|
68
|
+
end
|
69
|
+
|
70
|
+
def hostname_duplicate?(app_def_id, service_id, hostname)
|
71
|
+
app_definition = ForemanAcd::AppDefinition.find(app_def_id)
|
72
|
+
service_data = JSON.parse(app_definition.services).select { |k| k['id'] == service_id }.first
|
73
|
+
domain_name = Hostgroup.find(service_data['hostgroup']).domain.name
|
74
|
+
validation_hostname = "#{hostname}.#{domain_name}"
|
75
|
+
|
76
|
+
vdata = OpenStruct.new(
|
77
|
+
:hostname => hostname,
|
78
|
+
:fqdn => validation_hostname,
|
79
|
+
:result => Host.find_by(:name => validation_hostname).nil?
|
80
|
+
)
|
81
|
+
vdata
|
82
|
+
end
|
37
83
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanAcd
|
5
|
+
# DeployAllHosts implements a Foreman Task EntryAction
|
6
|
+
class DeployAllHosts < Actions::EntryAction
|
7
|
+
def plan(app_instance, safe_deploy)
|
8
|
+
action_subject(app_instance, :safe_deploy => safe_deploy)
|
9
|
+
plan_self(:id => app_instance.id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
output[:status] = 'IN PROGRESS'
|
14
|
+
app_instance = ::ForemanAcd::AppInstance.find(input.fetch(:id))
|
15
|
+
safe_deploy = input.fetch(:safe_deploy)
|
16
|
+
|
17
|
+
# Goal: all, safe_deploy or nothing
|
18
|
+
begin
|
19
|
+
if safe_deploy
|
20
|
+
::Foreman::Logging.logger('foreman_acd').info "Start to safe deploy hosts of the app #{app_instance}"
|
21
|
+
else
|
22
|
+
::Foreman::Logging.logger('foreman_acd').info "Start to deploy all hosts of the app #{app_instance}"
|
23
|
+
end
|
24
|
+
app_deployer = ::ForemanAcd::AppDeployer.new(app_instance)
|
25
|
+
output[:data] = app_deployer.deploy(safe_deploy)
|
26
|
+
output[:status] = 'SUCCESS'
|
27
|
+
rescue StandardError => e
|
28
|
+
::Foreman::Logging.logger('foreman_acd').error "Error while deploying hosts for application instance '#{app_instance.name}'. Clean up all other hosts: #{e}"
|
29
|
+
app_instance.clean_all_hosts
|
30
|
+
|
31
|
+
output[:status] = 'FAILURE'
|
32
|
+
raise "Error while deploying hosts for application instance '#{app_instance.name}': (#{e.message})"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def finalize; end
|
37
|
+
|
38
|
+
def rescue_strategy
|
39
|
+
Dynflow::Action::Rescue::Fail
|
40
|
+
end
|
41
|
+
|
42
|
+
def humanized_name
|
43
|
+
_('Deploy application instance hosts')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Actions
|
4
|
+
module ForemanAcd
|
5
|
+
# RunConfigurator implements a Foreman Task EntryAction
|
6
|
+
class RunConfigurator < Actions::EntryAction
|
7
|
+
def plan(app_instance)
|
8
|
+
action_subject(app_instance)
|
9
|
+
plan_self(:id => app_instance.id)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
output[:status] = 'SUCCESS'
|
14
|
+
begin
|
15
|
+
app_instance = ::ForemanAcd::AppInstance.find(input.fetch(:id))
|
16
|
+
app_configurator = ::ForemanAcd::AppConfigurator.new(app_instance)
|
17
|
+
|
18
|
+
result, job = app_configurator.configure
|
19
|
+
if result.success
|
20
|
+
::Foreman::Logging.logger('foreman_acd').info "Creating job to configure the app #{app_instance}"
|
21
|
+
job.trigger!
|
22
|
+
output[:configure_job_id] = job.job_invocation.id
|
23
|
+
else
|
24
|
+
::Foreman::Logging.logger('foreman_acd').error "Could not create the job to configure the app #{app_instance}: #{result.error}"
|
25
|
+
end
|
26
|
+
rescue StandardError => e
|
27
|
+
::Foreman::Logging.logger('foreman_acd').error "Error while configuring application instance '#{app_instance.name}': #{e}"
|
28
|
+
|
29
|
+
output[:status] = 'FAILURE'
|
30
|
+
raise "Error while configuring hosts via ansible playbook for application instance '#{app_instance.name}': (#{e.message})"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def finalize; end
|
35
|
+
|
36
|
+
def rescue_strategy
|
37
|
+
Dynflow::Action::Rescue::Fail
|
38
|
+
end
|
39
|
+
|
40
|
+
def humanized_name
|
41
|
+
_('Configure application instance after hosts deployment')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|