foreman_puppet 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +61 -7
  3. data/app/controllers/concerns/foreman_puppet/environments_import.rb +1 -1
  4. data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +1 -1
  5. data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +1 -1
  6. data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +3 -10
  7. data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +2 -2
  8. data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +4 -0
  9. data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +4 -0
  10. data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +4 -0
  11. data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +4 -0
  12. data/app/controllers/foreman_puppet/config_groups_controller.rb +4 -0
  13. data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +4 -0
  14. data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +2 -2
  15. data/app/controllers/foreman_puppet/puppetclasses_controller.rb +3 -2
  16. data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
  17. data/app/helpers/foreman_puppet/hosts_helper.rb +15 -0
  18. data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +2 -2
  19. data/app/models/concerns/foreman_puppet/extensions/host.rb +19 -8
  20. data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +5 -5
  21. data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +2 -2
  22. data/app/models/concerns/foreman_puppet/extensions/report.rb +18 -0
  23. data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +1 -1
  24. data/app/models/concerns/foreman_puppet/extensions/user.rb +19 -12
  25. data/app/models/foreman_puppet/environment_class.rb +1 -1
  26. data/app/models/foreman_puppet/host_class.rb +1 -1
  27. data/app/models/foreman_puppet/host_puppet_facet.rb +4 -3
  28. data/app/models/foreman_puppet/puppetclass.rb +13 -1
  29. data/app/services/foreman_puppet/puppet_class_importer.rb +14 -14
  30. data/app/views/foreman_puppet/common/_puppetclasses_or_envs_changed.html.erb +62 -0
  31. data/app/views/foreman_puppet/environments/index.html.erb +1 -1
  32. data/app/views/foreman_puppet/environments/welcome.html.erb +1 -1
  33. data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +1 -1
  34. data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +1 -1
  35. data/app/views/foreman_puppet/puppetclasses/index.html.erb +1 -1
  36. data/app/views/hosts/_form_puppet_enc_tab.html.erb +1 -1
  37. data/app/views/hosts/select_multiple_environment.html.erb +1 -1
  38. data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +2 -2
  39. data/lib/foreman_puppet.rb +2 -2
  40. data/lib/foreman_puppet/engine.rb +7 -3
  41. data/lib/foreman_puppet/register.rb +4 -3
  42. data/lib/foreman_puppet/version.rb +1 -1
  43. data/locale/Makefile +1 -1
  44. data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
  45. data/locale/en/foreman_puppet.po +18 -6
  46. data/locale/foreman_puppet.pot +19 -3
  47. data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +1 -1
  48. data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +1 -1
  49. data/test/controllers/foreman_puppet/api/v2/provisioning_templates_controller_test.rb +32 -0
  50. data/test/controllers/foreman_puppet/environments_controller_test.rb +1 -1
  51. data/test/factories/foreman_puppet_factories.rb +3 -0
  52. data/test/integration/foreman_puppet/puppetclass_js_test.rb +3 -0
  53. data/test/models/foreman_puppet/host_puppet_facet_test.rb +34 -1
  54. data/test/models/foreman_puppet/host_test.rb +1 -1
  55. data/test/models/foreman_puppet/provisioning_template_test.rb +16 -16
  56. data/test/models/foreman_puppet/report_test.rb +21 -0
  57. data/test/models/foreman_puppet/user_test.rb +29 -0
  58. data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +159 -161
  59. data/test/unit/foreman_puppet/puppet_class_importer_test.rb +13 -1
  60. metadata +48 -42
  61. data/locale/en/foreman_puppet.edit.po +0 -911
  62. data/locale/en/foreman_puppet.po.time_stamp +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 063aa962a333e59fdec2a1fb2d301eef47ae7006aebee443c48b0ec0d2311016
4
- data.tar.gz: de47e4d6cc3f191b551e43e1fc5fd134e386129a2d85bdf61439103fa87dbc72
3
+ metadata.gz: 22506c7ebf919c047dded9e11b60b405e4a3e7c1456cd2d5125312ef156d3e7f
4
+ data.tar.gz: 5249dd5ee17f4627b159fb10952ce36d0b2f0bcee212df9d5cd82ba18898259c
5
5
  SHA512:
6
- metadata.gz: 0b3a81c10ef66fab6dfa6e4ba9726e19080c5d8308a89eeb21232a3d35a0c8cd9ffc3b2722fbbc297a76a94c3c6470d82782a301bbf4589b37a0419461068ea6
7
- data.tar.gz: d349b0fffba53ff1fb31c2e161a985785d47022325e3b5443c5885aba017a85fa7cae4d4234e65dee3b4be5980897ec789da9bdac21b2872abfa8afbbb7ca6df
6
+ metadata.gz: 99998691aeb424b63ceca8f140049677b3ba2c8a280c21972425b5f3efa1f4b024e75b67e386735dbb6024dfcd6d8bc4dbc3c226cef6e6d87f23c6872fd29c75
7
+ data.tar.gz: 5587134660de8b3a8bded2014307d5f515d7adcacfe6c32a90336289735ecf2123cc3b67f0231c6a1088bbe1ab11b56009cf0488449a61178e4be067bb330f0b
data/README.md CHANGED
@@ -1,19 +1,74 @@
1
1
  # ForemanPuppet
2
2
 
3
- Adds Puppet External node classification funcionality for [Foreman](theforeman.org).
3
+ [![Gem Version](https://img.shields.io/gem/v/foreman_puppet.svg)](https://rubygems.org/gems/foreman_puppet)
4
+ [![GPL License](https://img.shields.io/github/license/theforeman/foreman_puppet.svg)](https://github.com/theforeman/foreman_puppet/blob/master/LICENSE)
5
+
6
+ This plugin adds Puppet External node classification functionality to [Foreman](https://theforeman.org).
7
+
8
+ * Website: [theforeman.org](http://theforeman.org)
9
+ * Support: [Foreman support](http://theforeman.org/support.html)
10
+
11
+ ## Features
12
+
13
+ * Puppet dashboards
14
+ * Puppet
15
+ * Environments
16
+ * Classes
17
+ * Config groups
18
+ * Smart Class parameters
19
+ * Host / Hostgroup
20
+ * Classes assignment
21
+ * Environment assignment
22
+ * Puppet proxy assignment
23
+ * Puppet ENC (external node classifier)
24
+ * Smartproxy Puppet status/tab
25
+ * Template hostgroup / environment
26
+
27
+ Some features will remain in core:
28
+
29
+ * PuppetCA
30
+ * Report/Fact parsing
31
+
32
+ ## Compatibility
33
+
34
+ Foreman 3.0 will be the first release where the Puppet functionality is mostly extracted.
35
+ Therefore, this plugin is only required for 3.0 and onwards.
36
+ You can install it on Foreman 2.5 to prepare for the Foreman update.
37
+
38
+ |Foreman version|Plugin version|Notes |
39
+ |---------------|--------------|------------------------------------------|
40
+ | >= 3.0 | ~> 1.0 | Required |
41
+ | >= 2.5 | ~> 0.1 | Optional; replaces Core features |
42
+ | < 2.5 | - | Not supported (functionality is in Core) |
4
43
 
5
44
  ## Installation
6
45
 
7
- See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
46
+ See [How_to_Install_a_Plugin](https://theforeman.org/plugins/#2.Installation)
8
47
  for how to install Foreman plugins
9
48
 
49
+ You can manually install this plugin using:
50
+
51
+ ```sh
52
+ # On RedHat/CentOS
53
+ yum install tfm-rubygem-foreman_puppet
54
+
55
+ # On Debian
56
+ apt install ruby-foreman-puppet
57
+ ```
58
+
10
59
  ## Usage
11
60
 
12
- *Usage here*
61
+ The usage is identical to the prior core functionality:
62
+
63
+ * Import *environments* and *classes* from a Smartproxy
64
+ * Optionally define *Smart Class* parameters
65
+ * Assign *environment* and *classes* to *Hosts / Hostgroups*
66
+ * Use the *Puppet ENC* on your Puppetserver(s) to query Foreman
13
67
 
14
- ## TODO
68
+ ## Problems
15
69
 
16
- *Todo list here*
70
+ Please feel free to open a [new Github issue](https://github.com/theforeman/foreman_puppet/issues/new)
71
+ if you encounter any bugs/issues using this plugin.
17
72
 
18
73
  ## Contributing
19
74
 
@@ -21,7 +76,7 @@ Fork and send a Pull Request. Thanks!
21
76
 
22
77
  ## Copyright
23
78
 
24
- Copyright (c) *year* *your name*
79
+ Copyright (c) *2021* *The Foreman developers*
25
80
 
26
81
  This program is free software: you can redistribute it and/or modify
27
82
  it under the terms of the GNU General Public License as published by
@@ -35,4 +90,3 @@ GNU General Public License for more details.
35
90
 
36
91
  You should have received a copy of the GNU General Public License
37
92
  along with this program. If not, see <http://www.gnu.org/licenses/>.
38
-
@@ -16,7 +16,7 @@ module ForemanPuppet
16
16
  end
17
17
 
18
18
  if !@changed['new'].empty? || !@changed['obsolete'].empty? || !@changed['updated'].empty?
19
- render 'common/_puppetclasses_or_envs_changed'
19
+ render 'foreman_puppet/common/_puppetclasses_or_envs_changed'
20
20
  else
21
21
  info_message = _('No changes to your environments detected')
22
22
 
@@ -42,7 +42,7 @@ module ForemanPuppet
42
42
  def puppetclass_parameters
43
43
  ::Taxonomy.as_taxonomy @organization, @location do
44
44
  render partial: 'foreman_puppet/puppetclasses/classes_parameters',
45
- locals: { obj: refresh_hostgroup }
45
+ locals: { obj: refresh_hostgroup }
46
46
  end
47
47
  end
48
48
 
@@ -104,7 +104,7 @@ module ForemanPuppet
104
104
  rescue StandardError => e
105
105
  Foreman::Logging.exception("Failed to generate external nodes for #{@host}", e)
106
106
  render plain: _('Unable to generate output, Check log files'),
107
- status: :precondition_failed
107
+ status: :precondition_failed
108
108
  end
109
109
  end
110
110
  # rubocop:enable Naming/MethodName
@@ -34,16 +34,9 @@ module ForemanPuppet
34
34
  end
35
35
 
36
36
  def process_deprecated_environment_params!(params)
37
- env_id = env_name = env = nil
38
- if ForemanPuppet.extracted_from_core?
39
- env_id = params.delete(:environment_id)
40
- env_name = params.delete(:environment_name)
41
- env = params.delete(:environment)
42
- else
43
- env_id = params[:environment_id]
44
- env_name = params[:environment_name]
45
- env = params[:environment]
46
- end
37
+ env_id = params.delete(:environment_id)
38
+ env_name = params.delete(:environment_name)
39
+ env = params.delete(:environment)
47
40
 
48
41
  return unless env_id || env_name || env
49
42
  ::Foreman::Deprecation.api_deprecation_warning('param host[environment_*] has been deprecated in favor of host[puppet_attributes][environment_*]')
@@ -7,8 +7,8 @@ module ForemanPuppet
7
7
  def puppetclass_lookup_key_params_filter
8
8
  Foreman::ParameterFilter.new(ForemanPuppet::PuppetclassLookupKey).tap do |filter|
9
9
  filter.permit environments: [], environment_ids: [], environment_names: [],
10
- environment_classes: [], environment_classes_ids: [], environment_classes_names: [],
11
- param_classes: [], param_classes_ids: [], param_classes_names: []
10
+ environment_classes: [], environment_classes_ids: [], environment_classes_names: [],
11
+ param_classes: [], param_classes_ids: [], param_classes_names: []
12
12
  filter.permit_by_context :required, nested: true
13
13
  filter.permit_by_context :id, ui: false, api: false, nested: true
14
14
 
@@ -51,6 +51,10 @@ module ForemanPuppet
51
51
  def destroy
52
52
  process_response @config_group.destroy
53
53
  end
54
+
55
+ def resource_class
56
+ ForemanPuppet::ConfigGroup
57
+ end
54
58
  end
55
59
  end
56
60
  end
@@ -62,6 +62,10 @@ module ForemanPuppet
62
62
  process_response @environment.destroy
63
63
  end
64
64
 
65
+ def resource_class
66
+ ForemanPuppet::Environment
67
+ end
68
+
65
69
  private
66
70
 
67
71
  def action_permission
@@ -29,6 +29,10 @@ module ForemanPuppet
29
29
  process_response @host_class.destroy_all
30
30
  end
31
31
 
32
+ def resource_class
33
+ ForemanPuppet::HostClass
34
+ end
35
+
32
36
  private
33
37
 
34
38
  # overwrite resource_name so it's host and and not host_class, since we want to return @host
@@ -28,6 +28,10 @@ module ForemanPuppet
28
28
  process_response @hostgroup_class.destroy_all
29
29
  end
30
30
 
31
+ def resource_class
32
+ ForemanPuppet::HostgroupClass
33
+ end
34
+
31
35
  private
32
36
 
33
37
  def find_hostgroup
@@ -42,5 +42,9 @@ module ForemanPuppet
42
42
  process_error
43
43
  end
44
44
  end
45
+
46
+ def resource_class
47
+ model_of_controller
48
+ end
45
49
  end
46
50
  end
@@ -16,6 +16,10 @@ module ForemanPuppet
16
16
  process_ajax_error e
17
17
  end
18
18
 
19
+ def resource_class
20
+ ::SmartProxy
21
+ end
22
+
19
23
  private
20
24
 
21
25
  def find_status
@@ -9,11 +9,11 @@ module ForemanPuppet
9
9
  environment_classes = EnvironmentClass.where(puppetclass_lookup_key_id: @lookup_keys.map(&:id)).select(:puppetclass_id, :puppetclass_lookup_key_id).distinct.preload(:puppetclass)
10
10
  puppetclass_ids = environment_classes.map(&:puppetclass_id).uniq
11
11
  @puppetclass_authorizer = Authorizer.new(User.current, collection: puppetclass_ids)
12
- @lookup_keys_to_class = Hash[environment_classes.map { |environment_class| [environment_class.puppetclass_lookup_key_id, environment_class.puppetclass] }]
12
+ @lookup_keys_to_class = environment_classes.map { |environment_class| [environment_class.puppetclass_lookup_key_id, environment_class.puppetclass] }.to_h
13
13
  end
14
14
 
15
15
  def resource_class
16
- ForemanPuppet::PuppetclassLookupKey
16
+ model_of_controller
17
17
  end
18
18
 
19
19
  private
@@ -5,6 +5,7 @@ module ForemanPuppet
5
5
  include Foreman::Controller::Parameters::Hostgroup
6
6
  include ForemanPuppet::Parameters::Environment
7
7
  include ForemanPuppet::Parameters::Puppetclass
8
+ include ForemanPuppet::EnvironmentsImport
8
9
 
9
10
  before_action :find_resource, only: %i[edit update destroy override]
10
11
  before_action :setup_search_options, only: :index
@@ -69,8 +70,8 @@ module ForemanPuppet
69
70
  def parameters
70
71
  puppetclass = Puppetclass.find(params[:id])
71
72
  render partial: 'foreman_puppet/puppetclasses/class_parameters',
72
- locals: { puppetclass: puppetclass,
73
- obj: find_host_or_hostgroup }
73
+ locals: { puppetclass: puppetclass,
74
+ obj: find_host_or_hostgroup }
74
75
  end
75
76
 
76
77
  def resource_class
@@ -9,7 +9,7 @@ module ForemanPuppet
9
9
  end
10
10
 
11
11
  def environments_title_actions
12
- title_actions import_proxy_select(hash_for_import_environments_environments_path),
12
+ title_actions import_proxy_select(hash_for_import_environments_environments_path.merge(engine: foreman_puppet)),
13
13
  button_group(new_link(_('Create Puppet Environment'), engine: foreman_puppet)),
14
14
  button_group(help_button)
15
15
  end
@@ -4,6 +4,7 @@ module ForemanPuppet
4
4
  multiple_actions_provider :puppet_host_multiple_actions
5
5
  # otherwise registered twice
6
6
  overview_buttons_provider :puppet_host_overview_buttons if ForemanPuppet.extracted_from_core?
7
+ overview_fields_provider :puppet_host_overview_fields if ForemanPuppet.extracted_from_core?
7
8
  end
8
9
 
9
10
  def puppet_host_multiple_actions
@@ -28,5 +29,19 @@ module ForemanPuppet
28
29
  end
29
30
  buttons
30
31
  end
32
+
33
+ def puppet_host_overview_fields(host)
34
+ fields = []
35
+ if host.environment.present?
36
+ fields << {
37
+ field: [
38
+ _('Puppet Environment'),
39
+ link_to(host.puppet.environment, hosts_path(search: "environment = #{host.puppet.environment}")),
40
+ ],
41
+ priority: 650,
42
+ }
43
+ end
44
+ fields
45
+ end
31
46
  end
32
47
  end
@@ -2,8 +2,8 @@ module ForemanPuppet
2
2
  module PuppetclassLookupKeysHelper
3
3
  def puppetclass_lookup_keys_breadcrumbs
4
4
  breadcrumbs(resource_url: api_smart_class_parameters_path,
5
- name_field: 'parameter',
6
- switcher_item_url: '/puppetclass_lookup_keys/:id-:name/edit')
5
+ name_field: 'parameter',
6
+ switcher_item_url: '/puppetclass_lookup_keys/:id-:name/edit')
7
7
  end
8
8
 
9
9
  # ------ Host(group) Form Helpers -----
@@ -6,18 +6,23 @@ module ForemanPuppet
6
6
  included do
7
7
  prepend PrependedMethods
8
8
 
9
- env_assoc = reflect_on_association(:environment)
10
- env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
9
+ unless ForemanPuppet.extracted_from_core?
10
+ env_assoc = reflect_on_association(:environment)
11
+ env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
12
+
13
+ host_classes_assoc = reflect_on_association(:host_classes)
14
+ host_classes_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::HostClass')
15
+ end
11
16
 
12
17
  include_in_clone puppet: %i[config_groups host_config_groups host_classes]
13
18
 
14
19
  scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment
15
20
  scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ '],
16
- ext_method: :search_by_deprecated_class
21
+ ext_method: :search_by_deprecated_class
17
22
  scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ '],
18
- ext_method: :search_by_puppetclass
23
+ ext_method: :search_by_puppetclass
19
24
  scoped_search relation: :config_groups, on: :name, complete_value: true, rename: :config_group, only_explicit: true, operators: ['= ', '~ '],
20
- ext_method: :search_by_config_group
25
+ ext_method: :search_by_config_group
21
26
  end
22
27
 
23
28
  class_methods do
@@ -61,6 +66,12 @@ module ForemanPuppet
61
66
  end
62
67
 
63
68
  module PrependedMethods
69
+ # TODO: we can drop this once extracted_from_core?
70
+ def validate_association_taxonomy(association_name)
71
+ return if association_name.to_sym == :environment
72
+ super
73
+ end
74
+
64
75
  def provisioning_template(opts = {})
65
76
  opts[:environment_id] ||= puppet&.environment_id
66
77
  super(opts)
@@ -70,9 +81,9 @@ module ForemanPuppet
70
81
  kinds = template_kinds(provisioning)
71
82
  kinds.map do |kind|
72
83
  ProvisioningTemplate.find_template({ kind: kind.name,
73
- operatingsystem_id: operatingsystem_id,
74
- hostgroup_id: hostgroup_id,
75
- environment_id: puppet&.environment_id })
84
+ operatingsystem_id: operatingsystem_id,
85
+ hostgroup_id: hostgroup_id,
86
+ environment_id: puppet&.environment_id })
76
87
  end.compact
77
88
  end
78
89
 
@@ -17,11 +17,11 @@ module ForemanPuppet
17
17
  scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment, only_explicit: true
18
18
  scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ ']
19
19
  scoped_search relation: :config_groups, on: :name,
20
- complete_value: true,
21
- rename: :config_group,
22
- only_explicit: true,
23
- operators: ['= ', '~ '],
24
- ext_method: :search_by_config_group
20
+ complete_value: true,
21
+ rename: :config_group,
22
+ only_explicit: true,
23
+ operators: ['= ', '~ '],
24
+ ext_method: :search_by_config_group
25
25
  end
26
26
 
27
27
  # Temporary, can be ordinary class_methods do, when removed from core
@@ -6,11 +6,11 @@ module ForemanPuppet
6
6
  included do
7
7
  if ForemanPuppet.extracted_from_core?
8
8
  has_many :environments, through: :template_combinations
9
- before_destroy EnsureNotUsedBy.new(:environments)
9
+ before_destroy ActiveRecord::Base::EnsureNotUsedBy.new(:environments)
10
10
 
11
11
  scoped_search relation: :environments, on: :name, rename: :environment, complete_value: true
12
12
 
13
- class << base
13
+ class << self
14
14
  prepend PrependedClassMethods
15
15
  end
16
16
 
@@ -5,6 +5,24 @@ module ForemanPuppet
5
5
 
6
6
  included do
7
7
  has_one :environment, through: :host
8
+
9
+ # for cases when class already inherit before we apply the patch
10
+ self.class.subclasses.each do |subclass|
11
+ add_environment_search_to(subclass)
12
+ end
13
+ end
14
+
15
+ class_methods do
16
+ def inherited(child)
17
+ add_environment_search_to(child)
18
+ super
19
+ end
20
+
21
+ def add_environment_search_to(klass)
22
+ klass.instance_eval do
23
+ scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment
24
+ end
25
+ end
8
26
  end
9
27
  end
10
28
  end
@@ -5,7 +5,7 @@ module ForemanPuppet
5
5
 
6
6
  included do
7
7
  if ForemanPuppet.extracted_from_core?
8
- belongs_to :environment
8
+ belongs_to :environment, class_name: 'ForemanPuppet::Environment'
9
9
 
10
10
  validates :environment_id, uniqueness: { scope: %i[hostgroup_id provisioning_template_id] }
11
11