foreman_puppet 2.0.0.alpha.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +41 -32
  3. data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +37 -28
  4. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +1 -1
  5. data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
  6. data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
  7. data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +2 -0
  8. data/app/views/foreman_puppet/config_groups/index.html.erb +1 -1
  9. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +36 -20
  10. data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +0 -8
  11. data/db/migrate/20211111125003_drop_puppetclasses_direct_references.foreman_puppet.rb +11 -0
  12. data/db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb +10 -0
  13. data/db/migrate_foreman/{20090722141107_create_environments.rb → 20090722141107_create_environments.foreman_puppet.rb} +1 -1
  14. data/db/migrate_foreman/{20090802062223_create_puppetclasses.rb → 20090802062223_create_puppetclasses.foreman_puppet.rb} +3 -2
  15. data/db/migrate_foreman/{20090905150132_create_hostgroups_puppetclasses.rb → 20090905150132_create_hostgroups_puppetclasses.foreman_puppet.rb} +0 -0
  16. data/db/migrate_foreman/{20110412103238_remove_unused_fields_from_puppet_classes.rb → 20110412103238_remove_unused_fields_from_puppet_classes.foreman_puppet.rb} +0 -0
  17. data/db/migrate_foreman/{20110712070522_create_host_class.rb → 20110712070522_create_host_class.foreman_puppet.rb} +0 -0
  18. data/db/migrate_foreman/{20120824142048_add_some_indexes.rb → 20120824142048_add_some_indexes.foreman_puppet.rb} +8 -1
  19. data/db/migrate_foreman/{20120905095532_create_environment_classes.rb → 20120905095532_create_environment_classes.foreman_puppet.rb} +2 -2
  20. data/db/migrate_foreman/{20121018152459_create_hostgroup_classes.rb → 20121018152459_create_hostgroup_classes.foreman_puppet.rb} +0 -0
  21. data/db/migrate_foreman/{20140407161817_create_config_groups.rb → 20140407161817_create_config_groups.foreman_puppet.rb} +0 -0
  22. data/db/migrate_foreman/{20140407162007_create_config_group_classes.rb → 20140407162007_create_config_group_classes.foreman_puppet.rb} +0 -0
  23. data/db/migrate_foreman/{20140407162059_create_host_config_groups.rb → 20140407162059_create_host_config_groups.foreman_puppet.rb} +0 -0
  24. data/db/migrate_foreman/{20161205142618_delete_orphaned_smart_class_parameters.rb → 20161205142618_delete_orphaned_smart_class_parameters.foreman_puppet.rb} +0 -0
  25. data/db/migrate_foreman/{20170109115157_fix_lookup_key_auditable_type.rb → 20170109115157_fix_lookup_key_auditable_type.foreman_puppet.rb} +0 -0
  26. data/db/migrate_foreman/{20180816134832_cast_lookup_key_values.rb → 20180816134832_cast_lookup_key_values.foreman_puppet.rb} +0 -0
  27. data/db/migrate_foreman/{20180831115634_add_uniqueness_to_puppetclass_name.rb → 20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb} +0 -0
  28. data/db/migrate_foreman/{20181023112532_add_environment_puppetclass_id.rb → 20181023112532_add_environment_puppetclass_id.foreman_puppet.rb} +0 -0
  29. data/db/migrate_foreman/{20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb → 20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.foreman_puppet.rb} +0 -0
  30. data/lib/foreman_puppet/register.rb +35 -0
  31. data/lib/foreman_puppet/version.rb +1 -1
  32. data/locale/ca/LC_MESSAGES/foreman_puppet.mo +0 -0
  33. data/locale/ca/foreman_puppet.po +760 -0
  34. data/locale/cs_CZ/LC_MESSAGES/foreman_puppet.mo +0 -0
  35. data/locale/cs_CZ/foreman_puppet.edit.po +1085 -0
  36. data/locale/cs_CZ/foreman_puppet.po +823 -0
  37. data/locale/cs_CZ/foreman_puppet.po.time_stamp +0 -0
  38. data/locale/de/LC_MESSAGES/foreman_puppet.mo +0 -0
  39. data/locale/de/foreman_puppet.po +844 -0
  40. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  41. data/locale/en/foreman_puppet.edit.po +317 -162
  42. data/locale/en/foreman_puppet.po +58 -1
  43. data/locale/en_GB/LC_MESSAGES/foreman_puppet.mo +0 -0
  44. data/locale/en_GB/foreman_puppet.po +820 -0
  45. data/locale/es/LC_MESSAGES/foreman_puppet.mo +0 -0
  46. data/locale/es/foreman_puppet.po +827 -0
  47. data/locale/foreman_puppet.pot +181 -92
  48. data/locale/fr/LC_MESSAGES/foreman_puppet.mo +0 -0
  49. data/locale/fr/foreman_puppet.po +835 -0
  50. data/locale/gl/LC_MESSAGES/foreman_puppet.mo +0 -0
  51. data/locale/gl/foreman_puppet.po +818 -0
  52. data/locale/it/LC_MESSAGES/foreman_puppet.mo +0 -0
  53. data/locale/it/foreman_puppet.po +822 -0
  54. data/locale/ja/LC_MESSAGES/foreman_puppet.mo +0 -0
  55. data/locale/ja/foreman_puppet.po +830 -0
  56. data/locale/ko/LC_MESSAGES/foreman_puppet.mo +0 -0
  57. data/locale/ko/foreman_puppet.po +819 -0
  58. data/locale/nl_NL/LC_MESSAGES/foreman_puppet.mo +0 -0
  59. data/locale/nl_NL/foreman_puppet.po +823 -0
  60. data/locale/pl/LC_MESSAGES/foreman_puppet.mo +0 -0
  61. data/locale/pl/foreman_puppet.po +822 -0
  62. data/locale/pt_BR/LC_MESSAGES/foreman_puppet.mo +0 -0
  63. data/locale/pt_BR/foreman_puppet.po +826 -0
  64. data/locale/ru/LC_MESSAGES/foreman_puppet.mo +0 -0
  65. data/locale/ru/foreman_puppet.po +827 -0
  66. data/locale/sv_SE/LC_MESSAGES/foreman_puppet.mo +0 -0
  67. data/locale/sv_SE/foreman_puppet.po +822 -0
  68. data/locale/zh_CN/LC_MESSAGES/foreman_puppet.mo +0 -0
  69. data/locale/zh_CN/foreman_puppet.po +831 -0
  70. data/locale/zh_TW/LC_MESSAGES/foreman_puppet.mo +0 -0
  71. data/locale/zh_TW/foreman_puppet.po +821 -0
  72. data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +70 -31
  73. data/test/integration/foreman_puppet/dashboard_js_test.rb +31 -0
  74. data/test/models/foreman_puppet/host_puppet_facet_test.rb +7 -1
  75. metadata +64 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61b910e24e11c9bd100021c5b87cc45b03eab68bc68260985f90d3510496d016
4
- data.tar.gz: '08fa8d3c7bdf23231daf2e14332f68be4d2a79fe33195260de1c1b276924c2de'
3
+ metadata.gz: c850f32331462f52510a8e895c149eb470e9982ad819de78529c38c888ab549c
4
+ data.tar.gz: 81460cb582b62baa3f96083c3573a99607a9b2619d2a20c31df4f41da48677c6
5
5
  SHA512:
6
- metadata.gz: cb6a6d40b42d741a4f4010aa81b9bbfa7e0b330473637036522d0a8d7e2fa983cee353ee0a59c3eacd1a64314d3edb17dfa29ee95adb7d47f08938f2380e822a
7
- data.tar.gz: 1e2f6b9ac9b996cbb368612dfb22d3adc03c89201d3d1931ca7920baf58090769160ded784c5094a3cfd1043ba22bf93b2926ff6de0075294630a7376179be6b
6
+ metadata.gz: f0b20469d894d6a1cc2e8c6f486ef5f09dd9c04742c0be684f68846fe930536a813ee404fb30af2ba0ae9031df6c2c00ea3a4af0233be5b24640b81d2a58d031
7
+ data.tar.gz: 16cab8e0431a72b04795046e4e66ca67a029247f4bf182a7a3f36e7ec8f2c5d45a1ae3db4ce8d96a48869a698eebec284eef6d9c0290d10270c41ab19789d0ee
@@ -14,12 +14,7 @@ module ForemanPuppet
14
14
  module PatchedClassMethods
15
15
  def host_params_filter
16
16
  super.tap do |filter|
17
- filter.permit :environment_id, :environment_name, :environment,
18
- config_groups: [], config_group_ids: [], config_group_names: [],
19
- puppetclasses: [], puppetclass_ids: [], puppetclass_names: []
20
-
21
- # TODO: bring to core - this is what facets should do, but does not
22
- filter.permit(puppet_attributes: {})
17
+ add_host_puppet_params_filter(filter)
23
18
  end
24
19
  end
25
20
  end
@@ -27,40 +22,54 @@ module ForemanPuppet
27
22
  module PatchedMethods
28
23
  def host_params(*attrs)
29
24
  params = super(*attrs)
30
-
31
- process_deprecated_environment_params!(params)
32
- process_deprecated_attributes!(params)
25
+ process_deprecated_puppet_params!(params)
33
26
  params
34
27
  end
28
+ end
35
29
 
36
- def process_deprecated_environment_params!(params)
37
- env_id = params.delete(:environment_id)
38
- env_name = params.delete(:environment_name)
39
- env = params.delete(:environment)
40
-
41
- return unless env_id || env_name || env
42
- ::Foreman::Deprecation.api_deprecation_warning('param host[environment_*] has been deprecated in favor of host[puppet_attributes][environment_*]')
30
+ class_methods do
31
+ def add_host_puppet_params_filter(filter)
32
+ filter.permit :environment_id, :environment_name, :environment,
33
+ config_groups: [], config_group_ids: [], config_group_names: [],
34
+ puppetclasses: [], puppetclass_ids: [], puppetclass_names: []
43
35
 
44
- params[:puppet_attributes] ||= {}
45
- params[:puppet_attributes][:environment_id] ||= env_id if env_id
46
- params[:puppet_attributes][:environment_name] ||= env_name if env_name
47
- params[:puppet_attributes][:environment] ||= env if env
36
+ # TODO: bring to core - this is what facets should do, but does not
37
+ filter.permit(puppet_attributes: {})
48
38
  end
39
+ end
40
+
41
+ def process_deprecated_puppet_params!(params, top_level_hash = controller_name.singularize)
42
+ process_deprecated_environment_params!(params, top_level_hash)
43
+ process_deprecated_attributes!(params, top_level_hash)
44
+ end
49
45
 
50
- def process_deprecated_attributes!(params)
51
- %w[puppetclass config_group].each do |relation|
52
- ids = params.delete("#{relation}_ids".to_sym)
53
- names = params.delete("#{relation}_names".to_sym)
54
- plains = params.delete(relation.pluralize.to_sym)
46
+ def process_deprecated_environment_params!(params, top_level_hash = 'host')
47
+ env_id = params.delete(:environment_id)
48
+ env_name = params.delete(:environment_name)
49
+ env = params.delete(:environment)
55
50
 
56
- next unless ids || names || plains
57
- ::Foreman::Deprecation.api_deprecation_warning("param host[#{relation}_*] has been deprecated in favor of host[puppet_attributes][#{relation}_*]")
51
+ return unless env_id || env_name || env
52
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[environment_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][environment_*]")
58
53
 
59
- params[:puppet_attributes] ||= {}
60
- params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
61
- params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
62
- params[:puppet_attributes][relation.pluralize.to_sym] ||= plains if plains
63
- end
54
+ params[:puppet_attributes] ||= {}
55
+ params[:puppet_attributes][:environment_id] ||= env_id if env_id
56
+ params[:puppet_attributes][:environment_name] ||= env_name if env_name
57
+ params[:puppet_attributes][:environment] ||= env if env
58
+ end
59
+
60
+ def process_deprecated_attributes!(params, top_level_hash = 'host')
61
+ %w[puppetclass config_group].each do |relation|
62
+ ids = params.delete("#{relation}_ids".to_sym)
63
+ names = params.delete("#{relation}_names".to_sym)
64
+ plains = params.delete(relation.pluralize.to_sym)
65
+
66
+ next unless ids || names || plains
67
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[#{relation}_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][#{relation}_*]")
68
+
69
+ params[:puppet_attributes] ||= {}
70
+ params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
71
+ params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
72
+ params[:puppet_attributes][relation.pluralize.to_sym] ||= plains if plains
64
73
  end
65
74
  end
66
75
  end
@@ -14,12 +14,7 @@ module ForemanPuppet
14
14
  module PatchedClassMethods
15
15
  def hostgroup_params_filter
16
16
  super.tap do |filter|
17
- filter.permit :environment_id, :environment_name,
18
- config_group_ids: [], config_group_names: [],
19
- puppetclass_ids: [], puppetclass_names: []
20
-
21
- # TODO: bring to core - this is what facets should do, but does not
22
- filter.permit(puppet_attributes: {})
17
+ add_hostgroup_puppet_params_filter(filter)
23
18
  end
24
19
  end
25
20
  end
@@ -27,36 +22,50 @@ module ForemanPuppet
27
22
  module PatchedMethods
28
23
  def hostgroup_params(*attrs)
29
24
  params = super(*attrs)
30
-
31
- process_deprecated_hostgroup_environment_params!(params)
32
- process_deprecated_hostgroup_attributes!(params)
25
+ process_deprecated_hostgroup_puppet_params!(params)
33
26
  params
34
27
  end
28
+ end
35
29
 
36
- def process_deprecated_hostgroup_environment_params!(params)
37
- env_id = params.delete(:environment_id)
38
- env_name = params.delete(:environment_name)
39
-
40
- return unless env_id || env_name
41
- ::Foreman::Deprecation.api_deprecation_warning('param hostgroup[environment_*] has been deprecated in favor of hostgroup[puppet_attributes][environment_*]')
30
+ class_methods do
31
+ def add_hostgroup_puppet_params_filter(filter)
32
+ filter.permit :environment_id, :environment_name,
33
+ config_group_ids: [], config_group_names: [],
34
+ puppetclass_ids: [], puppetclass_names: []
42
35
 
43
- params[:puppet_attributes] ||= {}
44
- params[:puppet_attributes][:environment_id] ||= env_id if env_id
45
- params[:puppet_attributes][:environment_name] ||= env_name if env_name
36
+ # TODO: bring to core - this is what facets should do, but does not
37
+ filter.permit(puppet_attributes: {})
46
38
  end
39
+ end
40
+
41
+ def process_deprecated_hostgroup_puppet_params!(params, top_level_hash = 'hostgroup')
42
+ process_deprecated_hostgroup_environment_params!(params, top_level_hash)
43
+ process_deprecated_hostgroup_attributes!(params, top_level_hash)
44
+ end
47
45
 
48
- def process_deprecated_hostgroup_attributes!(params)
49
- %w[puppetclass config_group].each do |relation|
50
- ids = params.delete("#{relation}_ids")
51
- names = params.delete("#{relation}_names")
46
+ def process_deprecated_hostgroup_environment_params!(params, top_level_hash = 'hostgroup')
47
+ env_id = params.delete(:environment_id)
48
+ env_name = params.delete(:environment_name)
52
49
 
53
- next unless ids || names
54
- ::Foreman::Deprecation.api_deprecation_warning("param hostgroup[#{relation}_*] has been deprecated in favor of hostgroup[puppet_attributes][#{relation}_*]")
50
+ return unless env_id || env_name
51
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[environment_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][environment_*]")
55
52
 
56
- params[:puppet_attributes] ||= {}
57
- params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
58
- params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
59
- end
53
+ params[:puppet_attributes] ||= {}
54
+ params[:puppet_attributes][:environment_id] ||= env_id if env_id
55
+ params[:puppet_attributes][:environment_name] ||= env_name if env_name
56
+ end
57
+
58
+ def process_deprecated_hostgroup_attributes!(params, top_level_hash = 'hostgroup')
59
+ %w[puppetclass config_group].each do |relation|
60
+ ids = params.delete("#{relation}_ids")
61
+ names = params.delete("#{relation}_names")
62
+
63
+ next unless ids || names
64
+ ::Foreman::Deprecation.api_deprecation_warning("param #{top_level_hash}[#{relation}_*] has been deprecated in favor of #{top_level_hash}[puppet_attributes][#{relation}_*]")
65
+
66
+ params[:puppet_attributes] ||= {}
67
+ params[:puppet_attributes]["#{relation}_ids".to_sym] ||= ids if ids
68
+ params[:puppet_attributes]["#{relation}_names".to_sym] ||= names if names
60
69
  end
61
70
  end
62
71
  end
@@ -20,7 +20,7 @@ module ForemanPuppet
20
20
 
21
21
  def create
22
22
  @hostgroup_class = HostgroupClass.create!(hostgroup_puppet_facet_id: @hostgroup.puppet.id, puppetclass_id: params[:puppetclass_id].to_i)
23
- render json: { hostgroup_id: @hostgroup_class.hostgroup_id, puppetclass_id: @hostgroup_class.puppetclass_id }
23
+ render json: { hostgroup_id: @hostgroup.puppet.hostgroup_id, puppetclass_id: @hostgroup_class.puppetclass_id }
24
24
  end
25
25
 
26
26
  api :DELETE, '/hostgroups/:hostgroup_id/puppetclass_ids/:id/', N_('Remove a Puppet class from host group')
@@ -10,7 +10,7 @@ module ForemanPuppet
10
10
 
11
11
  def environments_title_actions
12
12
  title_actions import_proxy_select(hash_for_import_environments_environments_path.merge(engine: foreman_puppet)),
13
- button_group(new_link(_('Create Puppet Environment'), engine: foreman_puppet)),
13
+ button_group(new_link(_('Create Puppet Environment'), { engine: foreman_puppet }, id: 'new_environment')),
14
14
  button_group(help_button)
15
15
  end
16
16
  end
@@ -48,7 +48,7 @@ module ForemanPuppet
48
48
 
49
49
  def parent_config_groups
50
50
  return [] unless host.hostgroup
51
- host.hostgroup.puppet&.all_config_groups
51
+ host.hostgroup.puppet&.all_config_groups || []
52
52
  end
53
53
 
54
54
  def ensure_puppet_associations
@@ -48,6 +48,8 @@ module ForemanPuppet
48
48
  Hostgroup.sort_by_ancestry(hostgroup.ancestors.joins(:puppet).where(HostgroupPuppetFacet.arel_table[attr.to_sym].not_eq(nil))).last&.puppet.try(attr)
49
49
  end
50
50
 
51
+ delegate :parent_id, to: :hostgroup
52
+
51
53
  # and helpers
52
54
  def parent_facet_id
53
55
  parent_facet&.id
@@ -2,7 +2,7 @@
2
2
  <% content_for(:search_bar) { } %>
3
3
  <% title _('Config Groups') %>
4
4
 
5
- <% title_actions new_link(_('Create Config Group'), engine: foreman_puppet), help_button %>
5
+ <% title_actions new_link(_('Create Config Group'), { engine: foreman_puppet }, id: 'new_config_group'), help_button %>
6
6
 
7
7
  <table class="<%= table_css_classes 'table-fixed' %>">
8
8
  <thead>
@@ -13,26 +13,8 @@ class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
13
13
  end
14
14
 
15
15
  def up
16
- host_config_group_ids = FakeHostConfigGroup.for_host.pluck(:host_id).uniq
17
- host_config_group_ids.each do |host_id|
18
- host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(:id)
19
- host_groups = FakeHostConfigGroup.for_host.where(host_id: host_id)
20
- if host_facet_id
21
- host_groups.update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
22
- else
23
- deleted_groups = FakeConfigGroup.where(id: host_groups.pluck(:config_group_id)).pluck(:name)
24
- say "deleting groups #{deleted_groups.join(', ')} from Host (id=#{host_id}) because it has no environment"
25
- host_groups.delete_all
26
- end
27
- end
28
- hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
29
- hostgroup_config_group_ids.each do |hostgroup_id|
30
- hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(:id)
31
- hostgroup_facet_id ||= ForemanPuppet::HostgroupPuppetFacet.create!(hostgroup: Hostgroup.unscoped.find(hostgroup_id)).id
32
- FakeHostConfigGroup.for_hostgroup
33
- .where(host_id: hostgroup_id)
34
- .update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
35
- end
16
+ migrate_host_data_to_facets
17
+ migrate_hostgroup_data_to_facets
36
18
  end
37
19
 
38
20
  def down
@@ -51,4 +33,38 @@ class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
51
33
  .update_all(host_type: 'Hostgroup', host_id: hostgroup_facet_ids[hostgroup_facet_id])
52
34
  end
53
35
  end
36
+
37
+ private
38
+
39
+ def migrate_host_data_to_facets
40
+ host_config_group_ids = FakeHostConfigGroup.for_host.pluck(:host_id).uniq
41
+ host_config_group_ids.each do |host_id|
42
+ host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(:id)
43
+ host_groups = FakeHostConfigGroup.for_host.where(host_id: host_id)
44
+ if host_facet_id
45
+ host_groups.update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
46
+ else
47
+ deleted_groups = FakeConfigGroup.where(id: host_groups.pluck(:config_group_id)).pluck(:name)
48
+ say "Deleting Config groups #{deleted_groups.join(', ')} from Host (id=#{host_id}) because the Host doesn't exist or has no environment"
49
+ host_groups.delete_all
50
+ end
51
+ end
52
+ end
53
+
54
+ def migrate_hostgroup_data_to_facets
55
+ hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
56
+ hostgroup_config_group_ids.each do |hostgroup_id|
57
+ hostgroup = Hostgroup.unscoped.find_by(id: hostgroup_id)
58
+ hostgroup_groups = FakeHostConfigGroup.for_hostgroup.where(host_id: hostgroup_id)
59
+ if hostgroup
60
+ hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(:id)
61
+ hostgroup_facet_id ||= ForemanPuppet::HostgroupPuppetFacet.create!(hostgroup: hostgroup).id
62
+ hostgroup_groups.update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
63
+ else
64
+ deleted_groups = FakeConfigGroup.where(id: hostgroup_groups.pluck(:config_group_id)).pluck(:name)
65
+ say "Deleting Config groups #{deleted_groups.join(', ')} from Hostgroup (id=#{hostgroup_id}) because Hostgroup doesn't exist"
66
+ hostgroup_groups.delete_all
67
+ end
68
+ end
69
+ end
54
70
  end
@@ -33,17 +33,9 @@ class MigratePuppetclassesToFacets < ActiveRecord::Migration[6.0]
33
33
  hostgroup_facet ||= ForemanPuppet::HostgroupPuppetFacet.create(hostgroup: Hostgroup.unscoped.find(hostgroup_id))
34
34
  ForemanPuppet::HostgroupClass.where(hostgroup_id: hostgroup_id).update_all(hostgroup_puppet_facet_id: hostgroup_facet.id)
35
35
  end
36
-
37
- change_column_null(:host_classes, :host_id, true)
38
- change_column_null(:hostgroup_classes, :hostgroup_id, true)
39
- # remove_reference(:host_classes, :host, index: true, foreign_key: true)
40
- # remove_reference(:hostgroup_classes, :hostgroup, index: true, foreign_key: true)
41
36
  end
42
37
 
43
38
  def down
44
- # add_reference :host_classes, :host, foreign_key: true, index: true
45
- # add_reference :hostgroup_classes, :hostgroup, foreign_key: true, index: true
46
-
47
39
  host_facets_ids = ForemanPuppet::HostClass.joins(:host_puppet_facet).pluck(:host_puppet_facet_id, 'host_puppet_facets.host_id')
48
40
  host_facets_ids.each do |host_facet_id, host_id|
49
41
  ForemanPuppet::HostClass.where(host_puppet_facet_id: host_facet_id).update_all(host_id: host_id)
@@ -0,0 +1,11 @@
1
+ class DropPuppetclassesDirectReferences < ActiveRecord::Migration[6.0]
2
+ def up
3
+ remove_reference(:host_classes, :host, index: true, foreign_key: true)
4
+ remove_reference(:hostgroup_classes, :hostgroup, index: true, foreign_key: true)
5
+ end
6
+
7
+ def down
8
+ add_reference :host_classes, :host, foreign_key: true, index: true
9
+ add_reference :hostgroup_classes, :hostgroup, foreign_key: true, index: true
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ class CleanupEnvironmentFromCoreTables < ActiveRecord::Migration[6.0]
2
+ def up
3
+ ::Hostgroup.update_all(environment_id: nil) if column_exists?(:hostgroups, :environment_id)
4
+ Host::Managed.update_all(environment_id: nil) if column_exists?(:hosts, :environment_id)
5
+ end
6
+
7
+ def down
8
+ # nothing to do
9
+ end
10
+ end
@@ -11,7 +11,7 @@ class CreateEnvironments < ActiveRecord::Migration[4.2]
11
11
  end
12
12
 
13
13
  def down
14
- drop_table :environments
15
14
  drop_table :environments_puppetclasses
15
+ drop_table :environments
16
16
  end
17
17
  end
@@ -21,8 +21,9 @@ class CreatePuppetclasses < ActiveRecord::Migration[4.2]
21
21
  end
22
22
 
23
23
  def down
24
- drop_table :puppetclasses
25
- drop_table :hosts_puppetclasses
26
24
  drop_table :operatingsystems_puppetclasses
25
+ drop_table :hosts_puppetclasses
26
+ remove_foreign_key(:environments_puppetclasses, :puppetclasses)
27
+ drop_table :puppetclasses
27
28
  end
28
29
  end
@@ -1,5 +1,5 @@
1
1
  class AddSomeIndexes < ActiveRecord::Migration[4.2]
2
- def change
2
+ def up
3
3
  # puppetclasses
4
4
  add_index :puppetclasses, :name
5
5
 
@@ -11,4 +11,11 @@ class AddSomeIndexes < ActiveRecord::Migration[4.2]
11
11
  add_foreign_key 'operatingsystems_puppetclasses', 'operatingsystems', name: 'operatingsystems_puppetclasses_operatingsystem_id_fk'
12
12
  add_foreign_key 'operatingsystems_puppetclasses', 'puppetclasses', name: 'operatingsystems_puppetclasses_puppetclass_id_fk'
13
13
  end
14
+
15
+ def down
16
+ remove_foreign_key 'host_classes', 'hosts', name: 'host_classes_host_id_fk'
17
+ remove_foreign_key 'host_classes', 'puppetclasses', name: 'host_classes_puppetclass_id_fk'
18
+ remove_foreign_key 'operatingsystems_puppetclasses', 'operatingsystems', name: 'operatingsystems_puppetclasses_operatingsystem_id_fk'
19
+ remove_foreign_key 'operatingsystems_puppetclasses', 'puppetclasses', name: 'operatingsystems_puppetclasses_puppetclass_id_fk'
20
+ end
14
21
  end
@@ -8,8 +8,8 @@ class CreateEnvironmentClasses < ActiveRecord::Migration[5.0]
8
8
  end
9
9
 
10
10
  def down
11
- remove_foreign_key :environment_classes, :lookup_key
12
- drop_column :environment_classes, :puppetclass_lookup_key_id, :integer
11
+ remove_foreign_key :environment_classes, :lookup_keys, column: :puppetclass_lookup_key_id
12
+ remove_column :environment_classes, :puppetclass_lookup_key_id, :integer
13
13
  rename_table :environment_classes, :environments_puppetclasses
14
14
  end
15
15
  end
@@ -3,6 +3,41 @@ Foreman::Plugin.register :foreman_puppet do
3
3
  # Add Global JS file for extending foreman-core components and routes
4
4
  register_global_js_file 'fills'
5
5
 
6
+ settings do
7
+ category(:facts, N_('Facts')) do
8
+ setting('default_puppet_environment',
9
+ type: :string,
10
+ description: N_('Foreman will default to this puppet environment if it cannot auto detect one'),
11
+ default: 'production',
12
+ full_name: N_('Default Puppet environment'),
13
+ collection: proc { ForemanPuppet::Environment.pluck(:name).map { |name| [name, name] }.to_h })
14
+ setting('enc_environment',
15
+ type: :boolean,
16
+ description: N_('Foreman will explicitly set the puppet environment in the ENC yaml output. '\
17
+ 'This will avoid conflicts between the environment in puppet.conf and the environment set in Foreman'),
18
+ default: true,
19
+ full_name: N_('ENC environment'))
20
+ setting('update_environment_from_facts',
21
+ type: :boolean,
22
+ description: N_("Foreman will update a host's environment from its facts"),
23
+ default: false,
24
+ full_name: N_('Update environment from facts'))
25
+ end
26
+
27
+ category(:cfgmgmt, N_('Config Management')) do
28
+ setting('puppet_interval',
29
+ type: :integer,
30
+ description: N_('Duration in minutes after servers reporting via Puppet are classed as out of sync.'),
31
+ default: 35,
32
+ full_name: N_('Puppet interval'))
33
+ setting('puppet_out_of_sync_disabled',
34
+ type: :boolean,
35
+ description: N_('Disable host configuration status turning to out of sync for %s after report does not arrive within configured interval') % 'Puppet',
36
+ default: false,
37
+ full_name: N_('%s out of sync disabled') % 'Puppet')
38
+ end
39
+ end
40
+
6
41
  apipie_documented_controllers(["#{ForemanPuppet::Engine.root}/app/controllers/foreman_puppet/api/v2/*.rb"])
7
42
 
8
43
  # TODO: maybe this would not be necessary if we rething the form
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '2.0.0.alpha.2'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end