foreman_acd 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +82 -86
  3. data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +13 -11
  4. data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +4 -3
  5. data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +1 -0
  6. data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +9 -1
  7. data/app/controllers/foreman_acd/app_definitions_controller.rb +14 -9
  8. data/app/controllers/foreman_acd/app_instances_controller.rb +97 -25
  9. data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +1 -1
  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 +3 -6
  13. data/app/controllers/ui_acd_controller.rb +9 -0
  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 +3 -0
  18. data/app/models/foreman_acd/ansible_playbook.rb +30 -13
  19. data/app/models/foreman_acd/app_definition.rb +24 -1
  20. data/app/models/foreman_acd/app_instance.rb +40 -5
  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 +7 -10
  24. data/app/services/foreman_acd/app_deployer.rb +59 -47
  25. data/app/services/foreman_acd/inventory_creator.rb +12 -25
  26. data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +11 -2
  27. data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +9 -1
  28. data/app/views/foreman_acd/ansible_playbooks/index.html.erb +3 -3
  29. data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +2 -0
  30. data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +2 -0
  31. data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +6 -0
  32. data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +2 -0
  33. data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +2 -0
  34. data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +6 -0
  35. data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +3 -1
  36. data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +2 -0
  37. data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +2 -0
  38. data/app/views/foreman_acd/app_definitions/_form.html.erb +8 -0
  39. data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -5
  40. data/app/views/foreman_acd/app_definitions/index.html.erb +4 -4
  41. data/app/views/foreman_acd/app_instances/_form.html.erb +3 -3
  42. data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
  43. data/app/views/foreman_acd/app_instances/index.html.erb +87 -14
  44. data/app/views/foreman_acd/app_instances/report.html.erb +5 -2
  45. data/app/views/templates/job/run_acd_ansible_playbook.erb +14 -1
  46. data/app/views/ui_acd/app_definition.json.rabl +1 -1
  47. data/config/routes.rb +1 -2
  48. data/db/migrate/20200917120220_add_ansible_playbook_id.rb +1 -1
  49. data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +3 -0
  50. data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +3 -0
  51. data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
  52. data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
  53. data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
  54. data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
  55. data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
  56. data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
  57. data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
  58. data/db/seeds.d/62_acd_proxy_feature.rb +1 -3
  59. data/db/seeds.d/75-job_templates.rb +6 -1
  60. data/lib/foreman_acd/engine.rb +14 -3
  61. data/lib/foreman_acd/plugin.rb +49 -28
  62. data/lib/foreman_acd/version.rb +1 -1
  63. data/locale/en/foreman_acd.edit.po +326 -0
  64. data/locale/en/foreman_acd.po +232 -2
  65. data/{app/controllers/foreman_acd/api/v2/app_playbooks_controller.rb → locale/en/foreman_acd.po.time_stamp} +0 -0
  66. data/locale/foreman_acd.pot +343 -8
  67. data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
  68. data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +31 -18
  69. data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +8 -0
  70. data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +1 -0
  71. data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +26 -0
  72. data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +1 -0
  73. data/webpack/components/ApplicationDefinition/index.js +2 -0
  74. data/webpack/components/ApplicationInstance/ApplicationInstance.js +67 -30
  75. data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +8 -0
  76. data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +1 -0
  77. data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +16 -2
  78. data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +1 -0
  79. data/webpack/components/ApplicationInstance/components/Service.js +1 -1
  80. data/webpack/components/ApplicationInstance/index.js +2 -0
  81. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +53 -60
  82. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +17 -0
  83. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +7 -51
  84. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -4
  85. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +4 -18
  86. data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +0 -1
  87. data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +1 -1
  88. data/webpack/components/ApplicationInstanceReport/index.js +0 -2
  89. data/webpack/components/ParameterSelection/ParameterSelection.js +10 -0
  90. data/webpack/components/ParameterSelection/ParameterSelectionActions.js +8 -7
  91. data/webpack/components/common/DeleteTableEntry.js +3 -2
  92. data/webpack/components/common/EditTableEntry.js +2 -1
  93. data/webpack/components/common/LockTableEntry.js +2 -1
  94. metadata +48 -6
  95. data/app/views/foreman_acd/app_instances/deploy.html.erb +0 -19
@@ -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, :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
@@ -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,7 +3,6 @@
3
3
  module ForemanAcd
4
4
  # Class to run remote execution jobs
5
5
  class RemoteExecutionController < JobInvocationsController
6
-
7
6
  def new
8
7
  jobs = init_configuration
9
8
  @composer = jobs.first
@@ -18,9 +17,7 @@ module ForemanAcd
18
17
  @composer.trigger!
19
18
  redirect_to job_invocation_path(@composer.job_invocation)
20
19
  elsif customize_first == false
21
- jobs.each do |composer|
22
- composer.trigger
23
- end
20
+ jobs.each(&:trigger)
24
21
  redirect_to job_invocations_path
25
22
  else
26
23
  # redirect to the job itself if we want to customize the job
@@ -38,12 +35,12 @@ module ForemanAcd
38
35
  private
39
36
 
40
37
  def init_configuration
41
- app_instance = ForemanAcd::AppInstance.find_by(:name => params[:id])
38
+ app_instance = ForemanAcd::AppInstance.find_by(:id => params[:id])
42
39
  app_configurator = ForemanAcd::AppConfigurator.new(app_instance)
43
40
 
44
41
  jobs = app_configurator.configure
45
42
  logger.debug("Creating #{jobs.count} job(s) to configure the app #{app_instance}. Customize first: #{params[:customize]}")
46
- return jobs
43
+ jobs
47
44
  end
48
45
  end
49
46
  end
@@ -16,6 +16,15 @@ class UiAcdController < ::Api::V2::BaseController
16
16
  @ansible_data = collect_ansible_data(params['id'])
17
17
  end
18
18
 
19
+ def action_permission
20
+ case params[:action]
21
+ when 'app', 'foreman_data', 'ansible_data'
22
+ :view
23
+ else
24
+ super
25
+ end
26
+ end
27
+
19
28
  private
20
29
 
21
30
  def collect_foreman_data(hostgroup_id)
@@ -0,0 +1,42 @@
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)
8
+ action_subject(app_instance)
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
+
16
+ # Goal: all or nothing
17
+ begin
18
+ ::Foreman::Logging.logger('foreman_acd').info "Start to deploy all hosts of the app #{app_instance}"
19
+ app_deployer = ::ForemanAcd::AppDeployer.new(app_instance)
20
+ output[:data] = app_deployer.deploy
21
+ output[:status] = 'SUCCESS'
22
+ rescue StandardError => e
23
+ ::Foreman::Logging.logger('foreman_acd').error "Error while deploying hosts for application instance. Clean up all other hosts: #{e}"
24
+ app_instance.clean_all_hosts
25
+
26
+ output[:error] = e.to_s
27
+ output[:status] = 'FAILURE'
28
+ end
29
+ end
30
+
31
+ def finalize; end
32
+
33
+ def rescue_strategy
34
+ Dynflow::Action::Rescue::Fail
35
+ end
36
+
37
+ def humanized_name
38
+ _('Deploy application instance hosts')
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,41 @@
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
+ jobs = app_configurator.configure
19
+ ::Foreman::Logging.logger('foreman_acd').info "Creating #{jobs.count} job(s) to configure the app #{app_instance}"
20
+
21
+ # TODO: would it be better to create a sub task for each job we need to run?
22
+ jobs.each(&:trigger)
23
+ rescue StandardError => e
24
+ ::Foreman::Logging.logger('foreman_acd').error "Error while configuring application instance: #{e}"
25
+ output[:error] = e.to_s
26
+ output[:status] = 'FAILURE'
27
+ end
28
+ end
29
+
30
+ def finalize; end
31
+
32
+ def rescue_strategy
33
+ Dynflow::Action::Rescue::Fail
34
+ end
35
+
36
+ def humanized_name
37
+ _('Configure application instance after hosts deployment')
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ # Extends the Host Managed
5
+ module HostManagedExtensions
6
+ extend ActiveSupport::Concern
7
+
8
+ RUN_CONFIGURATOR_DELAY = 240
9
+
10
+ def self.prepended(base)
11
+ base.instance_eval do
12
+ before_provision :initiate_acd_app_configurator, :if => :deployed_via_acd?
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def deployed_via_acd?
19
+ find_app_instance_host
20
+ @app_instance_host.present?
21
+ end
22
+
23
+ def find_app_instance_host
24
+ @app_instance_host = ForemanAcd::ForemanHost.find_by(:host_id => id)
25
+ end
26
+
27
+ def initiate_acd_app_configurator
28
+ return false if @app_instance_host.blank?
29
+
30
+ run_it = true
31
+ @app_instance_host.app_instance.foreman_hosts.each do |foreman_host|
32
+ # if there is ONE host, which is still in build phase we don't let the app_configuator run
33
+ next unless foreman_host.host.build?
34
+ ::Foreman::Logging.logger('foreman_acd').info("Another host (#{foreman_host.host.name} is still in build-phase. Wait for it...")
35
+ run_it = false
36
+ break
37
+ end
38
+
39
+ return unless run_it
40
+
41
+ ::Foreman::Logging.logger('foreman_acd').info("All hosts of app (#{@app_instance_host.app_instance.name}) were built. Schedule app configurator...")
42
+ start_acd_app_configurator
43
+ end
44
+
45
+ def start_acd_app_configurator
46
+ ForemanTasks.delay(::Actions::ForemanAcd::RunConfigurator,
47
+ { :start_at => Time.zone.now + RUN_CONFIGURATOR_DELAY },
48
+ @app_instance_host.app_instance)
49
+ end
50
+ end
51
+ end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ForemanAcd
4
+ # Implement a RemoteExecutionProvider
2
5
  class AcdProvider < RemoteExecutionProvider
3
6
  class << self
4
7
  def supports_effective_user?
@@ -4,14 +4,35 @@ module ForemanAcd
4
4
  # Ansible playbook
5
5
  class AnsiblePlaybook < ApplicationRecord
6
6
  include Authorizable
7
+ include Taxonomix
7
8
  extend FriendlyId
8
9
  friendly_id :name
10
+ include Parameterizable::ByIdName
9
11
 
10
12
  self.table_name = 'acd_ansible_playbooks'
11
- has_many :app_definitions, :inverse_of => :ansible_playbook, :foreign_key => 'acd_ansible_playbook_id', dependent: :restrict_with_error
13
+ has_many :app_definitions, :inverse_of => :ansible_playbook, :foreign_key => 'acd_ansible_playbook_id', :dependent => :restrict_with_error
12
14
  validates :name, :presence => true, :uniqueness => true
13
15
  scoped_search :on => :name
14
- default_scope -> { order("acd_ansible_playbooks.name") }
16
+
17
+ default_scope do
18
+ with_taxonomy_scope do
19
+ order('acd_ansible_playbooks.name')
20
+ end
21
+ end
22
+
23
+ def used_location_ids
24
+ Location.joins(:taxable_taxonomies).where(
25
+ 'taxable_taxonomies.taxable_type' => 'ForemanAcd::AnsiblePlaybook',
26
+ 'taxable_taxonomies.taxable_id' => id
27
+ ).pluck("#{Taxonomy.table_name}.id")
28
+ end
29
+
30
+ def used_organization_ids
31
+ Organization.joins(:taxable_taxonomies).where(
32
+ 'taxable_taxonomies.taxable_type' => 'ForemanAcd::AnsiblePlaybook',
33
+ 'taxable_taxonomies.taxable_id' => id
34
+ ).pluck("#{Taxonomy.table_name}.id")
35
+ end
15
36
 
16
37
  def self.humanize_class_name(_name = nil)
17
38
  _('Ansible playbook')
@@ -31,20 +52,16 @@ module ForemanAcd
31
52
  end
32
53
 
33
54
  def as_unified_structobj
34
- groups = []
35
-
36
- JSON.load(self.vars).each do |group_name, vars|
37
- groups << OpenStruct.new(
38
- :name => group_name,
39
- :vars => vars.map { |k,v| OpenStruct.new(:name => k, :value => v) })
55
+ # FIXME: For now, we convert all values to string - even booleans and dicts
56
+ pretty_groups = JSON.parse(vars).each do |_, params|
57
+ params.transform_values!(&:to_s)
40
58
  end
41
59
 
42
- adata = OpenStruct.new(
43
- :id => self.id,
44
- :name => self.name,
45
- :groups => JSON.load(self.vars)
60
+ OpenStruct.new(
61
+ :id => id,
62
+ :name => name,
63
+ :groups => pretty_groups
46
64
  )
47
- adata
48
65
  end
49
66
  end
50
67
  end
@@ -4,14 +4,37 @@ module ForemanAcd
4
4
  # Application Definition
5
5
  class AppDefinition < ApplicationRecord
6
6
  include Authorizable
7
+ include Taxonomix
7
8
  extend FriendlyId
8
9
  friendly_id :name
10
+ include Parameterizable::ByIdName
9
11
 
12
+ self.table_name = 'acd_app_definitions'
10
13
  validates :name, :presence => true, :uniqueness => true
14
+ validates :ansible_playbook, :presence => true
11
15
  has_many :app_instances, :inverse_of => :app_definition, :dependent => :destroy
12
16
  belongs_to :ansible_playbook, :inverse_of => :app_definitions, :foreign_key => :acd_ansible_playbook_id
13
17
  scoped_search :on => :name
14
- default_scope -> { order("app_definitions.name") }
18
+
19
+ default_scope do
20
+ with_taxonomy_scope do
21
+ order('acd_app_definitions.name')
22
+ end
23
+ end
24
+
25
+ def used_location_ids
26
+ Location.joins(:taxable_taxonomies).where(
27
+ 'taxable_taxonomies.taxable_type' => 'ForemanAcd::AppDefinition',
28
+ 'taxable_taxonomies.taxable_id' => id
29
+ ).pluck("#{Taxonomy.table_name}.id")
30
+ end
31
+
32
+ def used_organization_ids
33
+ Organization.joins(:taxable_taxonomies).where(
34
+ 'taxable_taxonomies.taxable_type' => 'ForemanAcd::AppDefinition',
35
+ 'taxable_taxonomies.taxable_id' => id
36
+ ).pluck("#{Taxonomy.table_name}.id")
37
+ end
15
38
 
16
39
  def self.humanize_class_name(_name = nil)
17
40
  _('App Definition')
@@ -4,12 +4,24 @@ module ForemanAcd
4
4
  # Application Instance
5
5
  class AppInstance < ApplicationRecord
6
6
  include Authorizable
7
+ include ForemanTasks::Concerns::ActionSubject
7
8
  extend FriendlyId
8
9
  friendly_id :name
10
+ include Parameterizable::ByIdName
11
+
12
+ self.table_name = 'acd_app_instances'
13
+ belongs_to :last_deploy_task, :class_name => 'ForemanTasks::Task'
9
14
  validates :name, :presence => true, :uniqueness => true
15
+ validates :app_definition, :presence => true
10
16
  belongs_to :app_definition, :inverse_of => :app_instances
17
+ belongs_to :organization
18
+ validates :organization, :presence => true
19
+ belongs_to :location
20
+ validates :location, :presence => true
21
+ has_many :foreman_hosts, :inverse_of => :app_instance, :dependent => :destroy
11
22
  scoped_search :on => :name
12
- default_scope -> { order("app_instances.name") }
23
+ default_scope -> { order('acd_app_instances.name') }
24
+ attr_accessor :hosts
13
25
 
14
26
  def self.humanize_class_name(_name = nil)
15
27
  _('App Instance')
@@ -19,10 +31,33 @@ module ForemanAcd
19
31
  'app_instances'
20
32
  end
21
33
 
22
- def foreman_hosts
23
- app_hosts = JSON.parse(self.hosts)
24
- host_ids = app_hosts.select{ |h| h&.key?('foreman_host_id') }.map{ |h| h['foreman_host_id'] }
25
- ::Host.find(host_ids)
34
+ def clean_all_hosts
35
+ remember_host_ids = foreman_hosts.map(&:host_id)
36
+
37
+ # Clean the app instance association first
38
+ foreman_hosts.update_all(:host_id => nil)
39
+
40
+ # Remove all hosts afterwards
41
+ delete_hosts(remember_host_ids)
42
+ end
43
+
44
+ def clean_hosts_by_id(ids = [])
45
+ # Clean the app instance association first
46
+ foreman_hosts.where(:host_id => ids).update_all(:host_id => nil)
47
+
48
+ # Remove all hosts afterwards
49
+ delete_hosts(ids)
50
+ end
51
+
52
+ def delete_hosts(ids = [])
53
+ return if ids.empty?
54
+ ids.each do |host_id|
55
+ h = ::Host.find(host_id) unless host_id.nil?
56
+ if h
57
+ Katello::RegistrationManager.unregister_host(h, :unregistering => false) if ForemanAcd::Engine.with_katello?
58
+ h.destroy
59
+ end
60
+ end
26
61
  end
27
62
  end
28
63
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ # Foreman Host
5
+ class ForemanHost < ApplicationRecord
6
+ include Authorizable
7
+
8
+ self.table_name = 'acd_foreman_hosts'
9
+ validates :hostname, :presence => true
10
+ belongs_to :app_instance, :inverse_of => :foreman_hosts
11
+ belongs_to :host, :class_name => '::Host::Managed'
12
+ scoped_search :on => :hostname
13
+ default_scope -> { order('acd_foreman_hosts.hostname') }
14
+
15
+ def self.humanize_class_name(_name = nil)
16
+ _('Foreman Host')
17
+ end
18
+
19
+ def self.permission_name
20
+ 'foreman_hosts'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ForemanAcd
4
+ # This is a TaxonomyExtensions
5
+ module TaxonomyExtensions
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ if SETTINGS[:version].to_s.to_f <= 1.7
10
+ def self.enabled_taxonomies
11
+ %w[locations organizations].select { |taxonomy| SETTINGS["#{taxonomy}_enabled".to_sym] }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ # To be removed after 1.7 compatibility is no longer required
@@ -3,7 +3,6 @@
3
3
  module ForemanAcd
4
4
  # application instances configurator
5
5
  class AppConfigurator
6
-
7
6
  delegate :logger, :to => :Rails
8
7
 
9
8
  def initialize(app_instance)
@@ -25,20 +24,18 @@ module ForemanAcd
25
24
  hosts = @app_instance.foreman_hosts
26
25
  proxy_selector = RemoteExecutionProxySelector.new
27
26
  hosts.each do |h|
28
- proxy = proxy_selector.determine_proxy(h, 'SSH')
29
- unless proxy_hosts.has_key?(proxy.name)
30
- proxy_hosts[proxy.name] = Array.new
31
- end
32
- proxy_hosts[proxy.name] << h.id
27
+ proxy = proxy_selector.determine_proxy(h.host, 'ACD')
28
+ proxy_hosts[proxy.name] = [] unless proxy_hosts.key?(proxy.name)
29
+ proxy_hosts[proxy.name] << h
33
30
  end
34
31
 
35
- # TODO just for testing...
36
- #proxy_hosts = { Host.first.name => [ Host.first.id] }
32
+ # TODO: just for testing...
33
+ # proxy_hosts = { Host.first.name => [ Host.first.id] }
37
34
 
38
35
  # we need to compose multiple jobs. for each proxy one job.
39
- proxy_hosts.each do |proxy_name, host_names|
36
+ proxy_hosts.each do |proxy_name, foreman_hosts|
40
37
  # create the inventory file
41
- inventory = ForemanAcd::InventoryCreator.new(@app_instance, host_names).create_inventory
38
+ inventory = ForemanAcd::InventoryCreator.new(@app_instance, foreman_hosts).create_inventory
42
39
  job_input['inventory'] = YAML.dump(inventory)
43
40
 
44
41
  composer = JobInvocationComposer.for_feature(