foreman_puppet 11.0.0 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_puppet/locale/ca/foreman_puppet.js +181 -1
  3. data/app/assets/javascripts/foreman_puppet/locale/cs_CZ/foreman_puppet.js +181 -1
  4. data/app/assets/javascripts/foreman_puppet/locale/de/foreman_puppet.js +181 -1
  5. data/app/assets/javascripts/foreman_puppet/locale/en/foreman_puppet.js +181 -1
  6. data/app/assets/javascripts/foreman_puppet/locale/en_GB/foreman_puppet.js +181 -1
  7. data/app/assets/javascripts/foreman_puppet/locale/es/foreman_puppet.js +181 -1
  8. data/app/assets/javascripts/foreman_puppet/locale/fr/foreman_puppet.js +181 -1
  9. data/app/assets/javascripts/foreman_puppet/locale/gl/foreman_puppet.js +181 -1
  10. data/app/assets/javascripts/foreman_puppet/locale/it/foreman_puppet.js +181 -1
  11. data/app/assets/javascripts/foreman_puppet/locale/ja/foreman_puppet.js +181 -1
  12. data/app/assets/javascripts/foreman_puppet/locale/ka/foreman_puppet.js +192 -12
  13. data/app/assets/javascripts/foreman_puppet/locale/ko/foreman_puppet.js +181 -1
  14. data/app/assets/javascripts/foreman_puppet/locale/nl_NL/foreman_puppet.js +181 -1
  15. data/app/assets/javascripts/foreman_puppet/locale/pl/foreman_puppet.js +181 -1
  16. data/app/assets/javascripts/foreman_puppet/locale/pt_BR/foreman_puppet.js +181 -1
  17. data/app/assets/javascripts/foreman_puppet/locale/ru/foreman_puppet.js +181 -1
  18. data/app/assets/javascripts/foreman_puppet/locale/sv_SE/foreman_puppet.js +181 -1
  19. data/app/assets/javascripts/foreman_puppet/locale/zh_CN/foreman_puppet.js +181 -1
  20. data/app/assets/javascripts/foreman_puppet/locale/zh_TW/foreman_puppet.js +181 -1
  21. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  22. data/app/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller.rb +75 -1
  23. data/app/models/foreman_puppet/config_group.rb +3 -1
  24. data/app/models/foreman_puppet/host_config_group.rb +12 -0
  25. data/app/models/foreman_puppet/puppetclass.rb +14 -3
  26. data/app/services/concerns/foreman_puppet/extensions/bulk_hosts_manager.rb +18 -0
  27. data/config/api_routes.rb +1 -0
  28. data/db/seeds.d/111_puppet_proxy_feature.rb +1 -1
  29. data/lib/foreman_puppet/register.rb +1 -0
  30. data/lib/foreman_puppet/version.rb +1 -1
  31. data/locale/ca/LC_MESSAGES/foreman_puppet.mo +0 -0
  32. data/locale/ca/foreman_puppet.po +187 -1
  33. data/locale/cs_CZ/LC_MESSAGES/foreman_puppet.mo +0 -0
  34. data/locale/cs_CZ/foreman_puppet.po +187 -1
  35. data/locale/de/LC_MESSAGES/foreman_puppet.mo +0 -0
  36. data/locale/de/foreman_puppet.po +188 -2
  37. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  38. data/locale/en/foreman_puppet.po +187 -1
  39. data/locale/en_GB/LC_MESSAGES/foreman_puppet.mo +0 -0
  40. data/locale/en_GB/foreman_puppet.po +187 -1
  41. data/locale/es/LC_MESSAGES/foreman_puppet.mo +0 -0
  42. data/locale/es/foreman_puppet.po +187 -1
  43. data/locale/foreman_puppet.pot +312 -13
  44. data/locale/fr/LC_MESSAGES/foreman_puppet.mo +0 -0
  45. data/locale/fr/foreman_puppet.po +187 -1
  46. data/locale/gl/LC_MESSAGES/foreman_puppet.mo +0 -0
  47. data/locale/gl/foreman_puppet.po +187 -1
  48. data/locale/it/LC_MESSAGES/foreman_puppet.mo +0 -0
  49. data/locale/it/foreman_puppet.po +187 -1
  50. data/locale/ja/LC_MESSAGES/foreman_puppet.mo +0 -0
  51. data/locale/ja/foreman_puppet.po +187 -1
  52. data/locale/ka/LC_MESSAGES/foreman_puppet.mo +0 -0
  53. data/locale/ka/foreman_puppet.po +199 -13
  54. data/locale/ko/LC_MESSAGES/foreman_puppet.mo +0 -0
  55. data/locale/ko/foreman_puppet.po +187 -1
  56. data/locale/nl_NL/LC_MESSAGES/foreman_puppet.mo +0 -0
  57. data/locale/nl_NL/foreman_puppet.po +187 -1
  58. data/locale/pl/LC_MESSAGES/foreman_puppet.mo +0 -0
  59. data/locale/pl/foreman_puppet.po +187 -1
  60. data/locale/pt_BR/LC_MESSAGES/foreman_puppet.mo +0 -0
  61. data/locale/pt_BR/foreman_puppet.po +187 -1
  62. data/locale/ru/LC_MESSAGES/foreman_puppet.mo +0 -0
  63. data/locale/ru/foreman_puppet.po +187 -1
  64. data/locale/sv_SE/LC_MESSAGES/foreman_puppet.mo +0 -0
  65. data/locale/sv_SE/foreman_puppet.po +187 -1
  66. data/locale/zh_CN/LC_MESSAGES/foreman_puppet.mo +0 -0
  67. data/locale/zh_CN/foreman_puppet.po +187 -1
  68. data/locale/zh_TW/LC_MESSAGES/foreman_puppet.mo +0 -0
  69. data/locale/zh_TW/foreman_puppet.po +187 -1
  70. data/test/controllers/foreman_puppet/api/v2/hosts_bulk_actions_controller_test.rb +93 -0
  71. data/test/models/foreman_puppet/host_test.rb +50 -0
  72. data/test/models/foreman_puppet/hostgroup_test.rb +50 -0
  73. data/test/services/foreman_puppet/bulk_hosts_manager_test.rb +45 -0
  74. data/webpack/__mocks__/foremanReact/redux/API/index.js +8 -0
  75. data/webpack/global_index.js +18 -1
  76. data/webpack/src/Extends/Hosts/ActionsBar/index.js +20 -0
  77. data/webpack/src/Extends/Hosts/BulkActions/BulkChangeProxyCommon/__tests__/actions.test.js +0 -7
  78. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/BulkChangePuppetEnvironmentModal.js +239 -0
  79. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/BulkChangePuppetEnvironmentModal.test.js +155 -0
  80. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/actions.test.js +49 -0
  81. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/__tests__/index.test.js +66 -0
  82. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/actions.js +37 -0
  83. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetEnvironment/index.js +30 -0
  84. data/webpack/src/Extends/Hosts/BulkActions/BulkChangePuppetProxy/__tests__/index.test.js +160 -47
  85. data/webpack/src/Extends/Hosts/BulkActions/BulkRemoveProxyCommon/__tests__/actions.test.js +0 -6
  86. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetCAProxy/__tests__/index.test.js +136 -39
  87. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/BulkRemovePuppetEnvironmentModal.js +148 -0
  88. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/BulkRemovePuppetEnvironmentModal.test.js +80 -0
  89. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/__tests__/index.test.js +66 -0
  90. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetEnvironment/index.js +30 -0
  91. data/webpack/src/Extends/Hosts/BulkActions/BulkRemovePuppetProxy/__tests__/index.test.js +123 -34
  92. data/webpack/src/Router/routes.fixtures.js +13 -0
  93. data/webpack/src/Router/routes.test.js +68 -8
  94. data/webpack/src/foreman_puppet_host_form.test.js +3 -1
  95. data/webpack/test_setup.js +1 -0
  96. metadata +14 -3
  97. data/webpack/src/Router/__snapshots__/routes.test.js.snap +0 -3
@@ -3,7 +3,7 @@
3
3
  "locale_data": {
4
4
  "foreman_puppet": {
5
5
  "": {
6
- "Project-Id-Version": "foreman_puppet 9.0.0",
6
+ "Project-Id-Version": "foreman_puppet 11.1.0",
7
7
  "Report-Msgid-Bugs-To": "",
8
8
  "PO-Revision-Date": "2021-02-03 16:30+0000",
9
9
  "Last-Translator": "0868a4d1af5275b3f70b0a6dac4c99a4, 2023",
@@ -45,6 +45,12 @@
45
45
  "<b>Description:</b> %{desc}<br/>\\n <b>Type:</b> %{type}<br/>\\n <b>Matcher:</b> %{matcher}<br/>\\n <b>Inherited value:</b> %{inherited_value}": [
46
46
  ""
47
47
  ],
48
+ "A Puppet environment with id %{id} could not be found.": [
49
+ ""
50
+ ],
51
+ "A Smart Proxy with id %{id} and the %{proxy_type} feature could not be found.": [
52
+ ""
53
+ ],
48
54
  "A config group provides a one-step method of associating many Puppet classes to either a host or host group. Typically this would be used to add a particular application profile or stack in one step.": [
49
55
  ""
50
56
  ],
@@ -69,6 +75,9 @@
69
75
  "Add:": [
70
76
  "新增:"
71
77
  ],
78
+ "All": [
79
+ ""
80
+ ],
72
81
  "All environments - (not filtered)": [
73
82
  "所有環境 -(未篩選)"
74
83
  ],
@@ -96,15 +105,54 @@
96
105
  "Change Environment": [
97
106
  "更改環境"
98
107
  ],
108
+ "Change Puppet (CA) Proxy": [
109
+ ""
110
+ ],
111
+ "Change Puppet CA Proxy": [
112
+ ""
113
+ ],
114
+ "Change Puppet CA proxy": [
115
+ ""
116
+ ],
117
+ "Change Puppet Environment": [
118
+ ""
119
+ ],
99
120
  "Change Puppet Master": [
100
121
  "改變 Puppet Master"
101
122
  ],
123
+ "Change Puppet Proxy": [
124
+ ""
125
+ ],
126
+ "Change Puppet environment": [
127
+ ""
128
+ ],
129
+ "Change Puppet proxy": [
130
+ ""
131
+ ],
102
132
  "Changed": [
103
133
  ""
104
134
  ],
105
135
  "Changed environments": [
106
136
  "已更改的環境"
107
137
  ],
138
+ "Changing the Puppet CA proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet CA proxy.": [
139
+ ""
140
+ ],
141
+ "Changing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet CA proxy.": [
142
+ ""
143
+ ],
144
+ "Changing the Puppet environment will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected environment.": [
145
+ ""
146
+ ],
147
+ "Changing the Puppet environment will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected environment.": [
148
+ ""
149
+ ],
150
+ "Changing the Puppet proxy will affect {boldCount} selected hosts. Some hosts may already have been associated with the selected Puppet proxy.": [
151
+ ""
152
+ ],
153
+ "Changing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Some hosts may already have been associated with the selected Puppet proxy.": [
154
+ ""
155
+ ],
108
156
  "Check/Uncheck all": [
109
157
  "選取/反選全部"
110
158
  ],
@@ -261,12 +309,48 @@
261
309
  "Failed": [
262
310
  ""
263
311
  ],
312
+ "Failed to change %{proxy_type} for %{count} host": [
313
+ "",
314
+ ""
315
+ ],
316
+ "Failed to change Puppet CA Proxy": [
317
+ ""
318
+ ],
319
+ "Failed to change Puppet Environment": [
320
+ ""
321
+ ],
322
+ "Failed to change Puppet Proxy": [
323
+ ""
324
+ ],
325
+ "Failed to change environment for %{count} host": [
326
+ "",
327
+ ""
328
+ ],
264
329
  "Failed to import %{klass} for %{name}: doesn't exists in our database - ignoring": [
265
330
  "為 %{name} 匯入 %{klass} 失敗:不存在我們的資料庫中 - 將被忽略"
266
331
  ],
332
+ "Failed to remove %{proxy_type} for %{count} host": [
333
+ "",
334
+ ""
335
+ ],
336
+ "Failed to remove Puppet CA Proxy": [
337
+ ""
338
+ ],
339
+ "Failed to remove Puppet Environment": [
340
+ ""
341
+ ],
342
+ "Failed to remove Puppet Proxy": [
343
+ ""
344
+ ],
267
345
  "Failed to set %{proxy_type} proxy for %{host}.": [
268
346
  "設定 %{proxy_type} 代理給 %{host} 時失敗。"
269
347
  ],
348
+ "Failed to set Puppet environment for %{host}.": [
349
+ ""
350
+ ],
351
+ "Failed to set proxy for %{host}.": [
352
+ ""
353
+ ],
270
354
  "Failed to start": [
271
355
  ""
272
356
  ],
@@ -348,6 +432,15 @@
348
432
  "ID of puppet environment": [
349
433
  ""
350
434
  ],
435
+ "ID of the Puppet environment to set for the selected hosts": [
436
+ ""
437
+ ],
438
+ "ID of the Puppet proxy to reassign the hosts to": [
439
+ ""
440
+ ],
441
+ "ID of the organization": [
442
+ ""
443
+ ],
351
444
  "IDs of associated ConfigGroups": [
352
445
  ""
353
446
  ],
@@ -450,6 +543,12 @@
450
543
  "List of config groups": [
451
544
  "配置群組清單"
452
545
  ],
546
+ "List of host ids to exclude and not run an action on": [
547
+ ""
548
+ ],
549
+ "List of host ids to perform an action on": [
550
+ ""
551
+ ],
453
552
  "List of override values for a specific smart class parameter": [
454
553
  "特定智慧型類別參數的置換值之清單"
455
554
  ],
@@ -597,6 +696,9 @@
597
696
  "Puppet CA Smart Proxy": [
598
697
  ""
599
698
  ],
699
+ "Puppet CA proxy": [
700
+ ""
701
+ ],
600
702
  "Puppet Class": [
601
703
  "Puppet 類別"
602
704
  ],
@@ -651,6 +753,9 @@
651
753
  "Puppet parameter": [
652
754
  "Puppet 參數"
653
755
  ],
756
+ "Puppet proxy": [
757
+ ""
758
+ ],
654
759
  "Puppetclass|Name": [
655
760
  "名稱"
656
761
  ],
@@ -660,6 +765,27 @@
660
765
  "Remove Combination": [
661
766
  ""
662
767
  ],
768
+ "Remove Puppet (CA) Proxy": [
769
+ ""
770
+ ],
771
+ "Remove Puppet CA Proxy": [
772
+ ""
773
+ ],
774
+ "Remove Puppet CA proxy": [
775
+ ""
776
+ ],
777
+ "Remove Puppet Environment": [
778
+ ""
779
+ ],
780
+ "Remove Puppet Proxy": [
781
+ ""
782
+ ],
783
+ "Remove Puppet environment": [
784
+ ""
785
+ ],
786
+ "Remove Puppet proxy": [
787
+ ""
788
+ ],
663
789
  "Remove a Puppet class from host": [
664
790
  "從主機移除一個 Puppet 類別"
665
791
  ],
@@ -675,6 +801,24 @@
675
801
  "Remove:": [
676
802
  "移除:"
677
803
  ],
804
+ "Removing the Puppet CA proxy will affect {boldCount} selected hosts. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!": [
805
+ ""
806
+ ],
807
+ "Removing the Puppet CA proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}. Warning: If a Puppet Proxy is still set, the Puppet CA Proxy will fall back to that value after removal!": [
808
+ ""
809
+ ],
810
+ "Removing the Puppet environment will affect {boldCount} selected hosts.": [
811
+ ""
812
+ ],
813
+ "Removing the Puppet environment will affect {boldCount} selected {count, plural, one {host} other {hosts}}.": [
814
+ ""
815
+ ],
816
+ "Removing the Puppet proxy will affect {boldCount} selected hosts.": [
817
+ ""
818
+ ],
819
+ "Removing the Puppet proxy will affect {boldCount} selected {count, plural, one {host} other {hosts}}.": [
820
+ ""
821
+ ],
678
822
  "Reports": [
679
823
  "報告"
680
824
  ],
@@ -687,12 +831,27 @@
687
831
  "Scheduled": [
688
832
  ""
689
833
  ],
834
+ "Search string for hosts to perform an action on": [
835
+ ""
836
+ ],
837
+ "Select a Puppet CA Proxy": [
838
+ ""
839
+ ],
840
+ "Select a Puppet Proxy": [
841
+ ""
842
+ ],
843
+ "Select an Environment": [
844
+ ""
845
+ ],
690
846
  "Select environment": [
691
847
  "選擇環境"
692
848
  ],
693
849
  "Select the changes you want to apply to Foreman": [
694
850
  ""
695
851
  ],
852
+ "Selected Puppet environment is not assigned to the proper organization and/or location for all hosts.": [
853
+ ""
854
+ ],
696
855
  "Set parameters to defaults": [
697
856
  "將參數設為預設值"
698
857
  ],
@@ -778,6 +937,9 @@
778
937
  "There are no puppet environments set up on this puppet master. Please check the puppet master configuration.": [
779
938
  "此 puppet master 上並未設定 puppet 環境。請檢查 puppet master 的配置。"
780
939
  ],
940
+ "There is no Smart Proxy with the feature '%s' available.": [
941
+ ""
942
+ ],
781
943
  "This Puppet class has no parameters in its signature.": [
782
944
  "此 puppet 類別的簽章中沒有參數。"
783
945
  ],
@@ -799,6 +961,12 @@
799
961
  "Total": [
800
962
  "總數"
801
963
  ],
964
+ "True, if Puppet CA proxy should be changed instead of the Puppet proxy": [
965
+ ""
966
+ ],
967
+ "True, if Puppet CA proxy should be removed instead of the Puppet proxy": [
968
+ ""
969
+ ],
802
970
  "Types of validation values": [
803
971
  "驗證值的類型"
804
972
  ],
@@ -838,6 +1006,18 @@
838
1006
  "Updated": [
839
1007
  "已更新"
840
1008
  ],
1009
+ "Updated host: changed %{proxy_type}": [
1010
+ "",
1011
+ ""
1012
+ ],
1013
+ "Updated host: changed environment": [
1014
+ "",
1015
+ ""
1016
+ ],
1017
+ "Updated host: removed %{proxy_type}": [
1018
+ "",
1019
+ ""
1020
+ ],
841
1021
  "Updated hosts: changed environment": [
842
1022
  "已更新主機:已更改的環境"
843
1023
  ],
@@ -126,7 +126,7 @@ module ForemanPuppet
126
126
 
127
127
  def get_environment_for(host, id)
128
128
  if id == 'inherit' && host.hostgroup.present?
129
- host.hostgroup.environment
129
+ host.hostgroup.puppet&.environment
130
130
  else
131
131
  ForemanPuppet::Environment.find_by(id: id)
132
132
  end
@@ -3,7 +3,9 @@ module ForemanPuppet
3
3
  module V2
4
4
  class HostsBulkActionsController < ::ForemanPuppet::Api::V2::PuppetBaseController
5
5
  include ::Api::V2::BulkHostsExtension
6
- before_action :find_editable_hosts, only: %i[change_puppet_proxy remove_puppet_proxy]
6
+ before_action :find_editable_hosts, only: %i[change_puppet_environment change_puppet_proxy remove_puppet_proxy]
7
+ before_action :find_environment, only: %i[change_puppet_environment]
8
+ before_action :validate_environment_taxonomies, only: %i[change_puppet_environment]
7
9
  before_action :find_smart_proxy, only: %i[change_puppet_proxy]
8
10
 
9
11
  def_param_group :bulk_params do
@@ -17,6 +19,27 @@ module ForemanPuppet
17
19
  end
18
20
  end
19
21
 
22
+ api :PUT, '/hosts/bulk/change_puppet_environment', N_('Change Puppet environment')
23
+ param_group :bulk_params
24
+ param :environment_id, String, required: false, desc: N_('ID of the Puppet environment to set for the selected hosts')
25
+ def change_puppet_environment
26
+ error_hosts = ::BulkHostsManager.new(hosts: @hosts).change_puppet_environment(resolved_environment)
27
+
28
+ process_bulk_response(
29
+ error_hosts,
30
+ success_message: format(n_(
31
+ 'Updated host: changed environment',
32
+ 'Updated hosts: changed environment',
33
+ @hosts.count
34
+ )),
35
+ error_message: format(n_(
36
+ 'Failed to change environment for %{count} host',
37
+ 'Failed to change environment for %{count} hosts',
38
+ error_hosts.count
39
+ ), count: error_hosts.count)
40
+ )
41
+ end
42
+
20
43
  api :PUT, '/hosts/bulk/change_puppet_proxy', N_('Change Puppet (CA) Proxy')
21
44
  param_group :bulk_params
22
45
  param :proxy_id, :number, required: true, desc: N_('ID of the Puppet proxy to reassign the hosts to')
@@ -65,6 +88,14 @@ module ForemanPuppet
65
88
  end
66
89
 
67
90
  def process_bulk_puppet_proxy_response(error_hosts, success_message:, error_message:)
91
+ process_bulk_response(
92
+ error_hosts,
93
+ success_message: success_message,
94
+ error_message: error_message
95
+ )
96
+ end
97
+
98
+ def process_bulk_response(error_hosts, success_message:, error_message:)
68
99
  if error_hosts.empty?
69
100
  process_response(true, { message: success_message })
70
101
  else
@@ -93,6 +124,49 @@ module ForemanPuppet
93
124
  Foreman::Cast.to_bool(params[:ca_proxy])
94
125
  end
95
126
 
127
+ def find_environment
128
+ return true if environment_value == 'inherit' || environment_value.blank?
129
+
130
+ @environment = ForemanPuppet::Environment.find_by(id: environment_value)
131
+ return true if @environment.present?
132
+
133
+ render json: {
134
+ error: {
135
+ message: format(_('A Puppet environment with id %{id} could not be found.'), id: environment_value),
136
+ },
137
+ }, status: :unprocessable_entity
138
+ false
139
+ end
140
+
141
+ def validate_environment_taxonomies
142
+ return true if resolved_environment.blank? || resolved_environment == 'inherit'
143
+
144
+ invalid_host_ids = @hosts.reject do |host|
145
+ ForemanPuppet::Environment.with_taxonomy_scope(host.organization, host.location)
146
+ .exists?(id: resolved_environment.id)
147
+ end.map(&:id)
148
+
149
+ return true if invalid_host_ids.empty?
150
+
151
+ render_error(:bulk_hosts_error, status: :unprocessable_entity,
152
+ locals: {
153
+ message: _('Selected Puppet environment is not assigned to the proper organization and/or location for all hosts.'),
154
+ failed_host_ids: invalid_host_ids,
155
+ })
156
+ false
157
+ end
158
+
159
+ def environment_value
160
+ params[:environment_id]
161
+ end
162
+
163
+ def resolved_environment
164
+ return 'inherit' if environment_value == 'inherit'
165
+ return nil if environment_value.blank?
166
+
167
+ @environment
168
+ end
169
+
96
170
  def proxy_type
97
171
  ca_proxy? ? _('Puppet CA proxy') : _('Puppet proxy')
98
172
  end
@@ -16,7 +16,9 @@ module ForemanPuppet
16
16
 
17
17
  validates :name, presence: true, uniqueness: true
18
18
 
19
- scope :assigned_to_hosts, -> { where(id: ForemanPuppet::HostConfigGroup.select(:config_group_id)) }
19
+ scope :assigned_to_hosts, lambda {
20
+ where(id: ForemanPuppet::HostConfigGroup.assigned_to_taxonomy.select(:config_group_id))
21
+ }
20
22
 
21
23
  scoped_search on: :name, complete_value: true
22
24
  scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ ']
@@ -8,6 +8,18 @@ module ForemanPuppet
8
8
 
9
9
  validates :host_id, uniqueness: { scope: %i[config_group_id host_type] }
10
10
 
11
+ scope :assigned_to_taxonomy, lambda {
12
+ host_facets = ForemanPuppet::HostPuppetFacet
13
+ .where(host_id: ::Host::Managed.reorder(nil).select(:id))
14
+ .select(:id)
15
+ hostgroup_facets = ForemanPuppet::HostgroupPuppetFacet
16
+ .where(hostgroup_id: ::Hostgroup.reorder(nil).select(:id))
17
+ .select(:id)
18
+
19
+ where(host_type: ForemanPuppet::HostPuppetFacet.polymorphic_name, host_id: host_facets)
20
+ .or(where(host_type: ForemanPuppet::HostgroupPuppetFacet.polymorphic_name, host_id: hostgroup_facets))
21
+ }
22
+
11
23
  def check_permissions_after_save
12
24
  true
13
25
  end
@@ -42,10 +42,21 @@ module ForemanPuppet
42
42
  default_scope -> { order(:name) }
43
43
 
44
44
  scope :assigned_to_hosts, lambda {
45
- direct = ForemanPuppet::HostClass.select(:puppetclass_id)
46
- via_hostgroup = ForemanPuppet::HostgroupClass.select(:puppetclass_id)
45
+ host_facets = ForemanPuppet::HostPuppetFacet
46
+ .where(host_id: ::Host::Managed.reorder(nil).select(:id))
47
+ .select(:id)
48
+ hostgroup_facets = ForemanPuppet::HostgroupPuppetFacet
49
+ .where(hostgroup_id: ::Hostgroup.unscoped.with_taxonomy_scope.reorder(nil).select(:id))
50
+ .select(:id)
51
+ direct = ForemanPuppet::HostClass
52
+ .where(host_puppet_facet_id: host_facets)
53
+ .select(:puppetclass_id)
54
+ via_hostgroup = ForemanPuppet::HostgroupClass
55
+ .where(hostgroup_puppet_facet_id: hostgroup_facets)
56
+ .select(:puppetclass_id)
57
+ config_group_ids = ForemanPuppet::HostConfigGroup.assigned_to_taxonomy.select(:config_group_id)
47
58
  via_config_group = ForemanPuppet::ConfigGroupClass
48
- .where(config_group_id: ForemanPuppet::HostConfigGroup.select(:config_group_id))
59
+ .where(config_group_id: config_group_ids)
49
60
  .select(:puppetclass_id)
50
61
 
51
62
  where(id: direct).or(where(id: via_hostgroup)).or(where(id: via_config_group))
@@ -3,6 +3,24 @@ module ForemanPuppet
3
3
  module BulkHostsManager
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ def change_puppet_environment(environment)
7
+ error_hosts = []
8
+ @hosts.each do |host|
9
+ puppet = host.puppet || host.build_puppet
10
+ puppet.environment = if environment == 'inherit'
11
+ host.hostgroup&.puppet&.environment
12
+ else
13
+ environment
14
+ end
15
+ host.save(validate: false)
16
+ rescue StandardError => e
17
+ message = format(_('Failed to set Puppet environment for %{host}.'), host: host)
18
+ Foreman::Logging.exception(message, e)
19
+ error_hosts << host.id
20
+ end
21
+ error_hosts
22
+ end
23
+
6
24
  def change_puppet_proxy(proxy, is_ca_proxy)
7
25
  error_hosts = []
8
26
  @hosts.each do |host|
data/config/api_routes.rb CHANGED
@@ -4,6 +4,7 @@ Foreman::Application.routes.draw do
4
4
  scope '(:apiv)', module: :v2, defaults: { apiv: 'v2' }, apiv: /v1|v2/, constraints: ApiConstraints.new(version: 2, default: true) do
5
5
  match 'hosts/bulk/change_puppet_proxy', to: 'hosts_bulk_actions#change_puppet_proxy', via: [:put]
6
6
  match 'hosts/bulk/remove_puppet_proxy', to: 'hosts_bulk_actions#remove_puppet_proxy', via: [:put]
7
+ match 'hosts/bulk/change_puppet_environment', to: 'hosts_bulk_actions#change_puppet_environment', via: [:put]
7
8
  end
8
9
  end
9
10
  end
@@ -4,5 +4,5 @@ proxy_features = %w[Puppet]
4
4
 
5
5
  proxy_features.each do |f_name|
6
6
  f = Feature.where(name: f_name).first_or_create
7
- raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
7
+ raise "Unable to create proxy feature: #{SeedHelper.format_errors(f)}" if f.nil? || f.errors.any?
8
8
  end
@@ -62,6 +62,7 @@ Foreman::Plugin.register :foreman_puppet do
62
62
  p.actions << 'hosts/update_multiple_environment'
63
63
  p.actions << 'hosts/select_multiple_puppet_proxy'
64
64
  p.actions << 'hosts/update_multiple_puppet_proxy'
65
+ p.actions << 'foreman_puppet/api/v2/hosts_bulk_actions/change_puppet_environment'
65
66
  p.actions << 'foreman_puppet/api/v2/hosts_bulk_actions/change_puppet_proxy'
66
67
  p.actions << 'foreman_puppet/api/v2/hosts_bulk_actions/remove_puppet_proxy'
67
68
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanPuppet
2
- VERSION = '11.0.0'.freeze
2
+ VERSION = '11.2.0'.freeze
3
3
  end