foreman_acd 0.0.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +82 -27
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +122 -0
  4. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +71 -0
  5. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -2
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +54 -0
  7. data/app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb +0 -0
  8. data/app/controllers/foreman_acd/app_definitions_controller.rb +36 -4
  9. data/app/controllers/foreman_acd/app_instances_controller.rb +24 -90
  10. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
  11. data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
  12. data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
  13. data/app/controllers/foreman_acd/remote_execution_controller.rb +49 -0
  14. data/app/controllers/ui_acd_controller.rb +11 -4
  15. data/app/models/foreman_acd/acd_provider.rb +27 -0
  16. data/app/models/foreman_acd/ansible_playbook.rb +50 -0
  17. data/app/models/foreman_acd/app_definition.rb +2 -1
  18. data/app/models/foreman_acd/app_instance.rb +7 -0
  19. data/app/services/foreman_acd/app_configurator.rb +57 -0
  20. data/app/services/foreman_acd/app_deployer.rb +139 -0
  21. data/app/services/foreman_acd/inventory_creator.rb +67 -0
  22. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +21 -0
  23. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +3 -0
  24. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
  25. data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
  26. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +3 -0
  27. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +3 -0
  28. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +3 -0
  29. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +3 -0
  30. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +3 -0
  31. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +3 -0
  32. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -0
  33. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +3 -0
  34. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +3 -0
  35. data/app/views/foreman_acd/app_definitions/_form.html.erb +25 -19
  36. data/app/views/foreman_acd/app_definitions/edit.html.erb +5 -0
  37. data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
  38. data/app/views/foreman_acd/app_definitions/index.html.erb +9 -5
  39. data/app/views/foreman_acd/app_instances/_form.html.erb +10 -8
  40. data/app/views/foreman_acd/app_instances/deploy.html.erb +19 -0
  41. data/app/views/foreman_acd/app_instances/index.html.erb +10 -5
  42. data/app/views/foreman_acd/app_instances/report.html.erb +19 -0
  43. data/app/views/templates/job/run_acd_ansible_playbook.erb +49 -0
  44. data/app/views/ui_acd/ansible_data.json.rabl +6 -0
  45. data/app/views/ui_acd/app.json.rabl +6 -2
  46. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  47. data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
  48. data/config/routes.rb +36 -1
  49. data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
  50. data/db/migrate/20190625140305_create_app_instances.rb +1 -1
  51. data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
  52. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
  53. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +5 -0
  54. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +5 -0
  55. data/db/seeds.d/62_acd_proxy_feature.rb +6 -0
  56. data/db/seeds.d/75-job_templates.rb +8 -0
  57. data/lib/foreman_acd/engine.rb +7 -0
  58. data/lib/foreman_acd/plugin.rb +84 -13
  59. data/lib/foreman_acd/version.rb +1 -1
  60. data/package.json +1 -2
  61. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +378 -0
  62. data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
  63. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +295 -0
  64. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +14 -0
  65. data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
  66. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +243 -0
  67. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +8 -0
  68. data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
  69. data/webpack/components/ApplicationDefinition/index.js +33 -0
  70. data/webpack/components/ApplicationInstance/ApplicationInstance.js +414 -0
  71. data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
  72. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +239 -0
  73. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +14 -0
  74. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +295 -0
  75. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +9 -0
  76. data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
  77. data/webpack/components/ApplicationInstance/components/Service.js +30 -0
  78. data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
  79. data/webpack/components/ApplicationInstance/index.js +35 -0
  80. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +155 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +27 -0
  82. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +86 -0
  83. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +4 -0
  84. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +52 -0
  85. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +5 -0
  86. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
  87. data/webpack/components/ApplicationInstanceReport/index.js +27 -0
  88. data/webpack/components/ParameterSelection/ParameterSelection.js +121 -192
  89. data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
  90. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +80 -104
  91. data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
  92. data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
  93. data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
  94. data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
  95. data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
  96. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
  97. data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
  98. data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
  99. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
  100. data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
  101. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
  102. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
  103. data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
  104. data/webpack/components/ParameterSelection/index.js +6 -8
  105. data/webpack/components/common/AddTableEntry.js +30 -0
  106. data/webpack/components/common/DeleteTableEntry.js +38 -0
  107. data/webpack/components/common/EasyHeaderFormatter.js +18 -0
  108. data/webpack/components/common/EditTableEntry.js +49 -0
  109. data/webpack/components/common/ExtSelect.js +43 -0
  110. data/webpack/components/common/LockTableEntry.js +59 -0
  111. data/webpack/components/common/RailsData.js +27 -0
  112. data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
  113. data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
  114. data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
  115. data/webpack/components/common/__tests__/RailsData.test.js +16 -0
  116. data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
  117. data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
  118. data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
  119. data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
  120. data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
  121. data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
  122. data/webpack/helper.js +20 -0
  123. data/webpack/index.js +6 -0
  124. data/webpack/reducer.js +43 -3
  125. metadata +91 -39
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ # application instances deployer
5
+ class AppDeployer
6
+
7
+ delegate :logger, :to => :Rails
8
+
9
+ def initialize(app_instance)
10
+ @app_instance = app_instance
11
+ end
12
+
13
+ def deploy
14
+ services = JSON.parse(@app_instance.app_definition.services)
15
+ app_hosts = JSON.parse(@app_instance.hosts)
16
+
17
+ app_hosts.each do |host_data|
18
+ begin
19
+ service_data = services.select { |k| k['id'] == host_data['service'].to_i }.first
20
+ host_params = set_host_params(host_data, service_data)
21
+
22
+ host = nil
23
+ if host_data.has_key?('foreman_host_id')
24
+ logger.debug("Try to find host with id #{host_data['foreman_host_id']}")
25
+ begin
26
+ host = Host.find(host_data['foreman_host_id'])
27
+ rescue ActiveRecord::RecordNotFound
28
+ logger.info("Host with id #{host_data['foreman_host_id']} couldn\'t be found, create a new one!")
29
+ host = nil
30
+ end
31
+ end
32
+
33
+ if host.nil?
34
+ params = host_attributes(host_params)
35
+ logger.info("Host creation parameters for #{host_data['hostname']}:\n#{params}\n")
36
+ host = Host.new(params)
37
+ else
38
+ logger.info("Update parameters and re-deploy host #{host_data['hostname']}")
39
+ host.attributes = host_attributes(host_params, host)
40
+ host.setBuild
41
+ host.power.reset
42
+ end
43
+
44
+ # REMOVE ME (but very nice for testing)
45
+ # host.mac = "00:11:22:33:44:55"
46
+
47
+ apply_compute_profile(host)
48
+ host.suggest_default_pxe_loader
49
+ host.save
50
+
51
+ # save the foreman host id
52
+ host_data['foreman_host_id'] = host.id
53
+ rescue StandardError => e
54
+ logger.error("Failed to initiate host creation: #{e.class}: #{e.message}\n#{e.backtrace.join($INPUT_RECORD_SEPARATOR)}")
55
+ end
56
+ end
57
+
58
+ return app_hosts
59
+ end
60
+
61
+ private
62
+
63
+ # Copied from foreman/app/controllers/api/v2/hosts_controller.rb
64
+ def apply_compute_profile(host)
65
+ host.apply_compute_profile(InterfaceMerge.new(:merge_compute_attributes => true))
66
+ host.apply_compute_profile(ComputeAttributeMerge.new)
67
+ end
68
+
69
+ # Copied from foreman/app/controllers/api/v2/hosts_controller.rb
70
+ def host_attributes(params, host = nil)
71
+ return {} if params.nil?
72
+
73
+ params = params.deep_clone
74
+ if params[:interfaces_attributes]
75
+ # handle both hash and array styles of nested attributes
76
+ params[:interfaces_attributes] = params[:interfaces_attributes].values if params[:interfaces_attributes].is_a?(Hash) || params[:interfaces_attributes].is_a?(ActionController::Parameters)
77
+ # map interface types
78
+ params[:interfaces_attributes] = params[:interfaces_attributes].map do |nic_attr|
79
+ interface_attributes(nic_attr, :allow_nil_type => host.nil?)
80
+ end
81
+ end
82
+ params = host.apply_inherited_attributes(params) if host
83
+ params
84
+ end
85
+
86
+ # Copied from foreman/app/controllers/api/v2/hosts_controller.rb
87
+ def interface_attributes(params, allow_nil_type: false)
88
+ params[:type] = InterfaceTypeMapper.map(params[:type]) if params.key?(:type) || allow_nil_type
89
+ params
90
+ end
91
+
92
+ def hardcoded_params
93
+ result = {}
94
+ result['managed'] = true
95
+ result['enabled'] = true
96
+ result['build'] = true
97
+ result['compute_attributes'] = { 'start' => '1' }
98
+ result['host_parameters_attributes'] = []
99
+ result
100
+ end
101
+
102
+ def set_host_params(host_data, service_data)
103
+ result = hardcoded_params
104
+ result['name'] = host_data['hostname']
105
+ result['hostgroup_id'] = service_data['hostgroup']
106
+
107
+ host_data['foremanParameters'].each do |param|
108
+ case param['type']
109
+
110
+ when 'computeprofile'
111
+ result['compute_profile_id'] = param['value']
112
+
113
+ when 'domain'
114
+ result['domain_id'] = param['value']
115
+
116
+ when 'hostparam'
117
+ result['host_parameters_attributes'].push(:name => param['name'], :value => param['value'])
118
+
119
+ when 'ip'
120
+ result['ip'] = param['value']
121
+
122
+ when 'lifecycleenv'
123
+ result['content_facet_attributes'] = { 'lifecycle_environment_id' => param['value'] }
124
+
125
+ when 'ptable'
126
+ result['ptable_id'] = param['value']
127
+
128
+ when 'puppetenv'
129
+ result['environment_id'] = param['value']
130
+
131
+ when 'password'
132
+ result['root_pass'] = param['value']
133
+
134
+ end
135
+ end
136
+ result
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ # inventory creator for application instances
5
+ class InventoryCreator
6
+
7
+ delegate :logger, :to => :Rails
8
+
9
+ def initialize(app_instance, host_ids)
10
+ @app_instance = app_instance
11
+ @host_ids = host_ids
12
+ end
13
+
14
+ # TODO: this might be part of the smart proxy plugin.
15
+ def create_inventory
16
+ inventory = {}
17
+ inventory['all'] = {}
18
+
19
+ inventory['all'] = { 'vars' => inventory_all_vars } unless @app_instance.ansible_vars_all.nil? || @app_instance.ansible_vars_all.empty?
20
+
21
+ services = JSON.parse(@app_instance.app_definition.services)
22
+ app_hosts = filtered_hosts
23
+
24
+ children = {}
25
+ app_hosts.each do |host_data|
26
+ if host_data['foreman_host_id'].nil?
27
+ logger.warn "Ignore host #{host_data['hostname']} because no foreman host id could be found. Is the host not provisioned yet?"
28
+ next
29
+ end
30
+
31
+ service_id = host_data['service'].to_i
32
+ host_service = services.select { |s| s['id'] == service_id }.first
33
+ ansible_group = host_service['ansibleGroup']
34
+
35
+ unless children.has_key?(host_service['ansibleGroup'])
36
+ children[ansible_group] = { 'hosts' => {} }
37
+ end
38
+
39
+ ansible_vars = host_data['ansibleParameters'].map { |v| { v['name'] => v['value'] } }.reduce({}, :merge!)
40
+
41
+ # in case there is no ansible_user defined, set "root" as default.
42
+ unless ansible_vars.has_key?('ansible_user')
43
+ ansible_vars['ansible_user'] = 'root'
44
+ end
45
+
46
+ children[ansible_group]['hosts'][get_fqdn(host_data['foreman_host_id'])] = ansible_vars
47
+ end
48
+ inventory['all']['children'] = children
49
+ inventory
50
+ end
51
+
52
+ private
53
+ def inventory_all_vars
54
+ JSON.parse(@app_instance.ansible_vars_all).map do |a|
55
+ { a['name'] => a['value'] }
56
+ end.reduce({}, :merge!)
57
+ end
58
+
59
+ def get_fqdn(host_id)
60
+ Host.find(host_id)&.name
61
+ end
62
+
63
+ def filtered_hosts
64
+ JSON.parse(@app_instance.hosts).select{ |h| h&.key?('foreman_host_id') && @host_ids.include?(h['foreman_host_id']) }
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,21 @@
1
+ <%= form_for @ansible_playbook, :url => (@ansible_playbook.new_record? ? ansible_playbooks_path : ansible_playbook_path(:id => @ansible_playbook.id)) do |f| %>
2
+ <%= base_errors_for @ansible_playbook %>
3
+
4
+ <ul class="nav nav-tabs" data-tabs="tabs">
5
+ <li class="active"><a href="#primary" data-toggle="tab"><%= _('Ansible playbooks') %></a></li>
6
+ </ul>
7
+
8
+ <div class="tab-content">
9
+ <div class="tab-pane active" id="primary">
10
+ <%= text_f f, :name %>
11
+ <%= text_f f, :description %>
12
+ <%= f.hidden_field :scm_type, :value => 'directory' %>
13
+ <% # TODO:
14
+ # select_f(f, :scm_type, %w[Directory GIT], :downcase, :to_s)
15
+ %>
16
+ <%= text_f f, :path %>
17
+ <%= text_f f, :playfile %>
18
+ </div>
19
+
20
+ <%= submit_or_cancel f %>
21
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% title(_('Edit Ansible Playbook %s') % @ansible_playbook) %>
2
+
3
+ <%= render :partial => 'form' %>
@@ -0,0 +1,30 @@
1
+ <% title _('Ansible Playbooks') %>
2
+
3
+ <% title_actions button_group(
4
+ new_link(_('New Ansible Playbook')),
5
+ ) %>
6
+
7
+ <table class="table table-bordered table-striped">
8
+ <tr>
9
+ <th><%= sort :name, :as => s_('AnsiblePlaybook|Name') %></th>
10
+ <th><%= _('Description') %></th>
11
+ <th></th>
12
+ </tr>
13
+ <% for ansible_playbook in @ansible_playbooks %>
14
+ <tr>
15
+ <td><%=link_to_if_authorized h(ansible_playbook.name), hash_for_edit_ansible_playbook_path(:id => ansible_playbook).merge(:auth_object => ansible_playbook, :authorizer => authorizer) %></td>
16
+ <td><%= ansible_playbook.description %></td>
17
+ <td>
18
+ <%= action_buttons(
19
+ display_link_if_authorized(_("Import group variables"), hash_for_import_vars_ansible_playbook_path(:id => ansible_playbook).merge(:auth_object => ansible_playbook, :authorizer => authorizer)),
20
+ display_delete_if_authorized(hash_for_ansible_playbook_path(:id => ansible_playbook).merge(:auth_object => ansible_playbook, :authorizer => authorizer),
21
+ :data => { 'confirm': _('Delete %s?') % ansible_playbook.name })
22
+ ) %>
23
+ </td>
24
+ </tr>
25
+ <% end %>
26
+ </table>
27
+
28
+ <%= page_entries_info @ansible_playbooks %>
29
+ <%= will_paginate @ansible_playbooks %>
30
+
@@ -0,0 +1,3 @@
1
+ <% title _('New Ansible Playbook') %>
2
+
3
+ <%= render :partial => 'form' %>
@@ -0,0 +1,3 @@
1
+ object @ansible_playbook
2
+
3
+ attributes :id, :name
@@ -0,0 +1,3 @@
1
+ collection @ansible_playbooks
2
+
3
+ extends 'foreman_acd/api/v2/ansible_playbooks/base'
@@ -0,0 +1,3 @@
1
+ object @ansible_playbook
2
+
3
+ extends 'foreman_acd/api/v2/ansible_playbooks/base'
@@ -0,0 +1,3 @@
1
+ object @app_definition
2
+
3
+ attributes :id, :name
@@ -0,0 +1,3 @@
1
+ collection @app_definitions
2
+
3
+ extends 'foreman_acd/api/v2/app_definitions/base'
@@ -0,0 +1,3 @@
1
+ object @app_definition
2
+
3
+ extends 'foreman_acd/api/v2/app_definitions/base'
@@ -0,0 +1,3 @@
1
+ object @app_instance
2
+
3
+ attributes :id, :name
@@ -0,0 +1,3 @@
1
+ collection @app_instances
2
+
3
+ extends 'foreman_acd/api/v2/app_instances/base'
@@ -0,0 +1,3 @@
1
+ object @app_instance
2
+
3
+ extends 'foreman_acd/api/v2/app_instances/base'
@@ -1,23 +1,29 @@
1
1
  <%
2
- json = {
3
- "organization": current_organization,
4
- "location": current_location,
5
- "hostgroups": @hostgroups,
6
- "loadForemanDataUrl": ui_acd_fdata_path("__id__")
7
- }
2
+ json = {
3
+ "organization": current_organization,
4
+ "location": current_location,
5
+ "hostgroups": @hostgroups,
6
+ "foremanDataUrl": ui_acd_foreman_data_path("__id__"),
7
+ "ansibleDataUrl": ui_acd_ansible_data_path("__id__"),
8
+ "services": [],
9
+ "ansibleVarsAll": [],
10
+ }
8
11
 
9
- if @app_definition.name.empty?
10
- json["mode"] = "newDefinition"
11
- else
12
- json["mode"] = "editDefinition"
13
- json["appDefinition"] = {
14
- "id": @app_definition.id,
15
- "name": @app_definition.name,
16
- "hostgroup_id": @app_definition.hostgroup_id,
17
- }
18
- json["parameters"] = JSON.parse(@app_definition.parameters)
19
- end
12
+ if @app_definition.new_record?
13
+ json["mode"] = "newDefinition"
14
+ json["ansiblePlaybooks"] = @ansible_playbooks
15
+ else
16
+ json["mode"] = "editDefinition"
17
+ json["ansiblePlaybook"] = @app_definition.ansible_playbook.as_unified_structobj
18
+ end
20
19
 
20
+ if @app_definition.services.present?
21
+ json["services"] = JSON.parse(@app_definition.services)
22
+ end
23
+
24
+ if @app_definition.ansible_vars_all.present?
25
+ json["ansibleVarsAll"] = JSON.parse(@app_definition.ansible_vars_all)
26
+ end
21
27
  %>
22
28
 
23
29
  <%= form_for @app_definition, :url => (@app_definition.new_record? ? app_definitions_path : app_definition_path(:id => @app_definition.id)) do |f| %>
@@ -31,8 +37,8 @@
31
37
  <%= text_f f, :name %>
32
38
  <%= text_f f, :description %>
33
39
 
34
- <div id='param-selection'></div>
35
- <%= mount_react_component('ParameterSelection', "#param-selection", json.to_json) %>
40
+ <div id='app_definition'></div>
41
+ <%= mount_react_component('ApplicationDefinition', "#app_definition", json.to_json) %>
36
42
  </div>
37
43
  </div>
38
44
 
@@ -1,5 +1,10 @@
1
1
  <% title(_('Edit Application Definition %s') % @app_definition) %>
2
2
 
3
+ <%= breadcrumbs(
4
+ :resource_url => acd_api_v2_app_definitions_path
5
+ )
6
+ %>
7
+
3
8
  <% content_for(:javascripts) do %>
4
9
  <%= webpacked_plugins_js_for :foreman_acd %>
5
10
  <% end %>
@@ -0,0 +1,18 @@
1
+ <% title _('Import Application Definition') %>
2
+
3
+ <%= form_for @app_definition, :url => (app_definitions_path), :html => { :multipart => true } do |f| %>
4
+ <%= base_errors_for @app_definition %>
5
+ <ul class="nav nav-tabs" data-tabs="tabs">
6
+ <li class="active"><a href="#primary" data-toggle="tab"><%= _('Application Definitions') %></a></li>
7
+ </ul>
8
+
9
+ <div class="tab-content">
10
+ <div class="tab-pane active" id="primary">
11
+ <%= text_f f, :name %>
12
+ <%= text_f f, :description %>
13
+ <%= file_field_f f, :app_definition_file, :label_help => _("Application Definition file") %>
14
+ </div>
15
+ </div>
16
+
17
+ <%= submit_or_cancel f %>
18
+ <% end %>
@@ -1,22 +1,26 @@
1
1
  <% title _('Application Definitions') %>
2
2
 
3
- <% title_actions button_group(new_link(_('New Application Definition'))) %>
3
+ <% title_actions button_group(
4
+ new_link(_('New Application Definition')),
5
+ display_link_if_authorized(_("Import"), hash_for_import_app_definitions_path, :class => 'btn btn-default')
6
+ ) %>
4
7
 
5
8
  <table class="table table-bordered table-striped">
6
9
  <tr>
7
10
  <th><%= sort :name, :as => s_('AppDefinition|Name') %></th>
8
11
  <th><%= _('Description') %></th>
9
- <th><%= sort :hostgroup, :as => _('Host groups'), :default => 'DESC' %></th>
10
12
  <th></th>
11
13
  </tr>
12
14
  <% for app_definition in @app_definitions %>
13
15
  <tr>
14
16
  <td><%=link_to_if_authorized h(app_definition.name), hash_for_edit_app_definition_path(:id => app_definition).merge(:auth_object => app_definition, :authorizer => authorizer) %></td>
15
17
  <td><%= app_definition.description %></td>
16
- <td><%= app_definition.hostgroup %></td>
17
18
  <td>
18
- <%= action_buttons(display_delete_if_authorized(hash_for_app_definition_path(:id => app_definition).merge(:auth_object => app_definition, :authorizer => authorizer),
19
- :data => { 'confirm': _('Delete %s?') % app_definition.name })) %>
19
+ <%= action_buttons(
20
+ display_delete_if_authorized(hash_for_app_definition_path(:id => app_definition).merge(:auth_object => app_definition, :authorizer => authorizer),
21
+ :data => { 'confirm': _('Delete %s?') % app_definition.name }),
22
+ display_link_if_authorized(_("Export"), hash_for_export_app_definition_path(:id => app_definition).merge(:auth_object => app_definition, :authorizer => authorizer))
23
+ ) %>
20
24
  </td>
21
25
  </tr>
22
26
  <% end %>
@@ -1,25 +1,27 @@
1
1
  <%
2
- if @app_instance.app_definition_id.blank?
2
+ if @app_instance.new_record?
3
3
  json = {
4
4
  "mode": "newInstance",
5
5
  "organization": current_organization,
6
6
  "location": current_location,
7
7
  "applications": @applications,
8
- "loadParameterSelectionUrl": ui_acd_app_path("__id__"),
9
- "loadForemanDataUrl": ui_acd_fdata_path("__id__"),
8
+ "appDefinitionUrl": ui_acd_app_path("__id__"),
9
+ "foremanDataUrl": ui_acd_foreman_data_path("__id__"),
10
+ "ansibleVarsAll": [],
10
11
  }
11
12
  else
12
13
  json = {
13
14
  "mode": "editInstance",
14
15
  "organization": current_organization,
15
16
  "location": current_location,
16
- "loadForemanDataUrl": ui_acd_fdata_path("__id__"),
17
+ "appDefinitionUrl": ui_acd_app_path("__id__"),
18
+ "foremanDataUrl": ui_acd_foreman_data_path("__id__"),
17
19
  "appDefinition": {
18
20
  "id": @app_instance.app_definition.id,
19
21
  "name": @app_instance.app_definition.name,
20
- "hostgroup_id": @app_instance.app_definition.hostgroup_id,
21
22
  },
22
- "parameters": JSON.parse(@app_instance.parameters),
23
+ "hosts": JSON.parse(@app_instance.hosts),
24
+ "ansibleVarsAll": @app_instance.ansible_vars_all.blank? ? [] : JSON.parse(@app_instance.ansible_vars_all),
23
25
  }
24
26
  end
25
27
  %>
@@ -35,8 +37,8 @@
35
37
  <%= text_f f, :name %>
36
38
  <%= text_f f, :description %>
37
39
 
38
- <div id='param-selection'></div>
39
- <%= mount_react_component('ParameterSelection', "#param-selection", json.to_json) %>
40
+ <div id='app_instance'></div>
41
+ <%= mount_react_component('ApplicationInstance', "#app_instance", json.to_json) %>
40
42
  </div>
41
43
  </div>
42
44
  </div>