foreman_puppet 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +619 -0
- data/README.md +38 -0
- data/Rakefile +31 -0
- data/app/assets/stylesheets/foreman_puppet.scss +117 -0
- data/app/controllers/concerns/foreman_puppet/api/import_puppetclasses_common_controller.rb +139 -0
- data/app/controllers/concerns/foreman_puppet/environments_import.rb +61 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +40 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -0
- data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +48 -0
- data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +58 -0
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +228 -0
- data/app/controllers/concerns/foreman_puppet/extensions/operatingsystems_controller.rb +11 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +75 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +70 -0
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_template_combination.rb +21 -0
- data/app/controllers/concerns/foreman_puppet/parameters/config_group.rb +17 -0
- data/app/controllers/concerns/foreman_puppet/parameters/environment.rb +21 -0
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass.rb +24 -0
- data/app/controllers/concerns/foreman_puppet/parameters/puppetclass_lookup_key.rb +24 -0
- data/app/controllers/foreman_puppet/api/v2/base_controller.rb +26 -0
- data/app/controllers/foreman_puppet/api/v2/config_groups_controller.rb +57 -0
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +91 -0
- data/app/controllers/foreman_puppet/api/v2/host_classes_controller.rb +59 -0
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +46 -0
- data/app/controllers/foreman_puppet/api/v2/lookups_common_controller.rb +114 -0
- data/app/controllers/foreman_puppet/api/v2/override_values_controller.rb +99 -0
- data/app/controllers/foreman_puppet/api/v2/puppetclasses_controller.rb +99 -0
- data/app/controllers/foreman_puppet/api/v2/smart_class_parameters_controller.rb +76 -0
- data/app/controllers/foreman_puppet/config_groups_controller.rb +46 -0
- data/app/controllers/foreman_puppet/environments_controller.rb +51 -0
- data/app/controllers/foreman_puppet/puppet_smart_proxies_controller.rb +39 -0
- data/app/controllers/foreman_puppet/puppetclass_lookup_keys_controller.rb +33 -0
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +113 -0
- data/app/controllers/foreman_puppet/react_controller.rb +19 -0
- data/app/helpers/concerns/foreman_puppet/template_renderer_scope.rb +14 -0
- data/app/helpers/foreman_puppet/environments_helper.rb +17 -0
- data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +96 -0
- data/app/helpers/foreman_puppet/hosts_helper.rb +32 -0
- data/app/helpers/foreman_puppet/puppet_smart_proxies_helper.rb +8 -0
- data/app/helpers/foreman_puppet/puppetclass_lookup_keys_helper.rb +135 -0
- data/app/helpers/foreman_puppet/puppetclasses_and_environments_helper.rb +55 -0
- data/app/helpers/foreman_puppet/puppetclasses_helper.rb +59 -0
- data/app/helpers/foreman_puppet/template_combinations_helper.rb +33 -0
- data/app/models/concerns/foreman_puppet/extensions/host.rb +88 -0
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +40 -0
- data/app/models/concerns/foreman_puppet/extensions/nic_managed.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/operatingsystem.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +64 -0
- data/app/models/concerns/foreman_puppet/extensions/report.rb +11 -0
- data/app/models/concerns/foreman_puppet/extensions/taxonomy.rb +19 -0
- data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +23 -0
- data/app/models/concerns/foreman_puppet/extensions/user.rb +22 -0
- data/app/models/concerns/foreman_puppet/host_common.rb +90 -0
- data/app/models/concerns/foreman_puppet/puppet_lookup_value_extensions.rb +13 -0
- data/app/models/foreman_puppet/config_group.rb +45 -0
- data/app/models/foreman_puppet/config_group_class.rb +19 -0
- data/app/models/foreman_puppet/environment.rb +63 -0
- data/app/models/foreman_puppet/environment_class.rb +40 -0
- data/app/models/foreman_puppet/host_class.rb +23 -0
- data/app/models/foreman_puppet/host_config_group.rb +15 -0
- data/app/models/foreman_puppet/host_puppet_facet.rb +130 -0
- data/app/models/foreman_puppet/hostgroup_class.rb +23 -0
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +98 -0
- data/app/models/foreman_puppet/puppetclass.rb +132 -0
- data/app/models/foreman_puppet/puppetclass_lookup_key.rb +58 -0
- data/app/services/foreman_puppet/host_info_providers/config_groups_info.rb +10 -0
- data/app/services/foreman_puppet/host_info_providers/puppet_info.rb +92 -0
- data/app/services/foreman_puppet/input_type/puppet_parameter_input.rb +35 -0
- data/app/services/foreman_puppet/proxy_status/puppet.rb +17 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +355 -0
- data/app/views/api/v2/template_combinations/base.json.erb +9 -0
- data/app/views/foreman_puppet/api/v2/config_groups/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/main.json.rabl +8 -0
- data/app/views/foreman_puppet/api/v2/config_groups/show.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/config_groups/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/environments/main.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/environments/show.json.rabl +15 -0
- data/app/views/foreman_puppet/api/v2/environments/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/base.json.rabl +1 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_single.json.rabl +17 -0
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/show.json.rabl +11 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_single.json.rabl +16 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/show.json.rabl +11 -0
- data/app/views/foreman_puppet/api/v2/import_puppetclasses/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/import_puppetclasses/show.json.rabl +36 -0
- data/app/views/foreman_puppet/api/v2/override_values/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/show.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/override_values/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/base.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/index.json.rabl +4 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/list.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/main.json.rabl +5 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/show.json.rabl +15 -0
- data/app/views/foreman_puppet/api/v2/puppetclasses/update.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/base.json.rabl +4 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/create.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/destroy.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/index.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/main.json.rabl +23 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/show.json.rabl +19 -0
- data/app/views/foreman_puppet/api/v2/smart_class_parameters/update.json.rabl +3 -0
- data/app/views/foreman_puppet/config_groups/_config_group.html.erb +34 -0
- data/app/views/foreman_puppet/config_groups/_config_groups_selection.html.erb +36 -0
- data/app/views/foreman_puppet/config_groups/_form.html.erb +9 -0
- data/app/views/foreman_puppet/config_groups/edit.html.erb +3 -0
- data/app/views/foreman_puppet/config_groups/index.html.erb +31 -0
- data/app/views/foreman_puppet/config_groups/new.html.erb +3 -0
- data/app/views/foreman_puppet/config_groups/welcome.html.erb +12 -0
- data/app/views/foreman_puppet/environments/_form.html.erb +20 -0
- data/app/views/foreman_puppet/environments/edit.html.erb +8 -0
- data/app/views/foreman_puppet/environments/index.html.erb +32 -0
- data/app/views/foreman_puppet/environments/new.html.erb +7 -0
- data/app/views/foreman_puppet/environments/welcome.html.erb +16 -0
- data/app/views/foreman_puppet/layouts/application_react.html.erb +15 -0
- data/app/views/foreman_puppet/puppet_smart_proxies/_dashboard.html.erb +9 -0
- data/app/views/foreman_puppet/puppet_smart_proxies/_environments.html.erb +30 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/edit.html.erb +3 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/index.html.erb +22 -0
- data/app/views/foreman_puppet/puppetclass_lookup_keys/welcome.html.erb +9 -0
- data/app/views/foreman_puppet/puppetclasses/_class_parameters.html.erb +37 -0
- data/app/views/foreman_puppet/puppetclasses/_class_selection.html.erb +70 -0
- data/app/views/foreman_puppet/puppetclasses/_classes.html.erb +22 -0
- data/app/views/foreman_puppet/puppetclasses/_classes_in_groups.html.erb +5 -0
- data/app/views/foreman_puppet/puppetclasses/_classes_parameters.html.erb +16 -0
- data/app/views/foreman_puppet/puppetclasses/_form.html.erb +62 -0
- data/app/views/foreman_puppet/puppetclasses/_selected_classes.html.erb +4 -0
- data/app/views/foreman_puppet/puppetclasses/edit.html.erb +4 -0
- data/app/views/foreman_puppet/puppetclasses/index.html.erb +47 -0
- data/app/views/hosts/_form_puppet_enc_tab.html.erb +24 -0
- data/app/views/hosts/foreman_puppet/_form_main_tab_fields.html.erb +1 -0
- data/app/views/hosts/select_multiple_environment.html.erb +8 -0
- data/app/views/provisioning_templates/_combination.html.erb +5 -0
- data/app/views/provisioning_templates/_combinations.html.erb +6 -0
- data/app/views/smart_proxies/plugins/_puppet.html.erb +24 -0
- data/config/api_routes.rb +81 -0
- data/config/routes.rb +89 -0
- data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +9 -0
- data/db/migrate/20200720123005_migrate_puppet_core_types.foreman_puppet.rb +19 -0
- data/db/migrate/20200722171017_create_host_puppet_facet.foreman_puppet.rb +10 -0
- data/db/migrate/20200803113531_create_hostgroup_puppet_facet.foreman_puppet.rb +10 -0
- data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +22 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +29 -0
- data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +47 -0
- data/db/migrate_foreman/20090722141107_create_environments.rb +17 -0
- data/db/migrate_foreman/20120905095532_create_environment_classes.rb +15 -0
- data/db/migrate_foreman/20140407161817_create_config_groups.rb +9 -0
- data/db/migrate_foreman/20140407162007_create_config_group_classes.rb +10 -0
- data/db/migrate_foreman/20140407162059_create_host_config_groups.rb +11 -0
- data/db/migrate_foreman/20161205142618_delete_orphaned_smart_class_parameters.rb +10 -0
- data/db/migrate_foreman/20170109115157_fix_lookup_key_auditable_type.rb +15 -0
- data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +35 -0
- data/db/migrate_foreman/20181023112532_add_environment_puppetclass_id.rb +7 -0
- data/db/migrate_foreman/20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb +6 -0
- data/db/seeds.d/111_puppet_proxy_feature.rb +8 -0
- data/lib/foreman_puppet.rb +10 -0
- data/lib/foreman_puppet/engine.rb +82 -0
- data/lib/foreman_puppet/register.rb +218 -0
- data/lib/foreman_puppet/version.rb +3 -0
- data/lib/tasks/foreman_puppet_tasks.rake +31 -0
- data/locale/Makefile +60 -0
- data/locale/action_names.rb +5 -0
- data/locale/en/foreman_puppet.edit.po +911 -0
- data/locale/en/foreman_puppet.po +690 -0
- data/locale/en/foreman_puppet.po.time_stamp +0 -0
- data/locale/foreman_puppet.pot +1076 -0
- data/locale/gemspec.rb +2 -0
- data/test/controllers/foreman_puppet/api/v2/config_groups_controller_test.rb +28 -0
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +346 -0
- data/test/controllers/foreman_puppet/api/v2/host_classes_controller_test.rb +48 -0
- data/test/controllers/foreman_puppet/api/v2/hostgroup_classes_controller_test.rb +41 -0
- data/test/controllers/foreman_puppet/api/v2/hostgroups_controller_test.rb +79 -0
- data/test/controllers/foreman_puppet/api/v2/hosts_controller_test.rb +101 -0
- data/test/controllers/foreman_puppet/api/v2/lookups_common_controller_test.rb +29 -0
- data/test/controllers/foreman_puppet/api/v2/override_values_controller_test.rb +169 -0
- data/test/controllers/foreman_puppet/api/v2/puppetclasses_controller_test.rb +144 -0
- data/test/controllers/foreman_puppet/api/v2/smart_class_parameters_controller_test.rb +557 -0
- data/test/controllers/foreman_puppet/api/v2/template_combinations_controller_test.rb +81 -0
- data/test/controllers/foreman_puppet/config_groups_controller_test.rb +47 -0
- data/test/controllers/foreman_puppet/environments_controller_test.rb +230 -0
- data/test/controllers/foreman_puppet/hostgroups_controller_test.rb +72 -0
- data/test/controllers/foreman_puppet/hosts_controller_test.rb +346 -0
- data/test/controllers/foreman_puppet/puppet_smart_proxies_controller_test.rb +29 -0
- data/test/controllers/foreman_puppet/puppetclass_lookup_keys_controller_test.rb +59 -0
- data/test/controllers/foreman_puppet/puppetclasses_controller_test.rb +235 -0
- data/test/controllers/provisioning_templates_controller_test.rb +70 -0
- data/test/factories/foreman_puppet_factories.rb +134 -0
- data/test/factories/host_puppet_enhancements.rb +61 -0
- data/test/factories/proxy_puppet_enhancements.rb +33 -0
- data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +65 -0
- data/test/helpers/foreman_puppet/puppetclasses_helper_test.rb +33 -0
- data/test/integration/foreman_puppet/environment_js_test.rb +27 -0
- data/test/integration/foreman_puppet/host_js_test.rb +371 -0
- data/test/integration/foreman_puppet/hostgroup_js_test.rb +100 -0
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +37 -0
- data/test/integration/foreman_puppet/smartclass_parameter_js_test.rb +84 -0
- data/test/models/foreman_puppet/config_group_class_test.rb +9 -0
- data/test/models/foreman_puppet/config_group_test.rb +8 -0
- data/test/models/foreman_puppet/environment_test.rb +92 -0
- data/test/models/foreman_puppet/host_config_group_test.rb +39 -0
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +116 -0
- data/test/models/foreman_puppet/host_test.rb +288 -0
- data/test/models/foreman_puppet/hostgroup_puppet_facet_test.rb +200 -0
- data/test/models/foreman_puppet/hostgroup_test.rb +14 -0
- data/test/models/foreman_puppet/lookup_value_test.rb +69 -0
- data/test/models/foreman_puppet/provisioning_template_test.rb +124 -0
- data/test/models/foreman_puppet/puppetclass_lookup_key_test.rb +81 -0
- data/test/models/foreman_puppet/puppetclass_test.rb +144 -0
- data/test/models/foreman_puppet/smart_proxy_test.rb +28 -0
- data/test/qraphql/queries/host_puppet_query_test.rb +36 -0
- data/test/qraphql/queries/hostgroup_puppet_query_test.rb +36 -0
- data/test/services/foreman_puppet/host_info_providers/puppet_info_test.rb +791 -0
- data/test/services/foreman_puppet/input_type/puppet_parameter_input_test.rb +14 -0
- data/test/test_puppet_helper.rb +30 -0
- data/test/unit/foreman_puppet/access_permissions_test.rb +16 -0
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +247 -0
- data/test/unit/foreman_puppet/template_rendering_test.rb +20 -0
- data/test/unit/foreman_puppet_test.rb +11 -0
- data/webpack/__mocks__/foremanReact/common/I18n.js +7 -0
- data/webpack/__mocks__/foremanReact/components/Layout/LayoutActions.js +2 -0
- data/webpack/__mocks__/foremanReact/readme.md +11 -0
- data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/actions/toasts.js +8 -0
- data/webpack/__mocks__/foremanReact/redux/index.js +1 -0
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
- data/webpack/fills_index.js +30 -0
- data/webpack/index.js +18 -0
- data/webpack/src/ForemanPuppet.js +11 -0
- data/webpack/src/Router/__snapshots__/routes.test.js.snap +3 -0
- data/webpack/src/Router/index.js +14 -0
- data/webpack/src/Router/routes.js +3 -0
- data/webpack/src/Router/routes.test.js +16 -0
- data/webpack/src/foreman_class_edit.js +224 -0
- data/webpack/src/foreman_puppet_host_form.js +140 -0
- data/webpack/src/foreman_puppet_host_form.test.js +65 -0
- data/webpack/src/index.js +1 -0
- data/webpack/src/reducers.js +7 -0
- metadata +340 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
class PuppetclassesController < ApplicationController
|
3
|
+
include Foreman::Controller::AutoCompleteSearch
|
4
|
+
include Foreman::Controller::Parameters::Host
|
5
|
+
include Foreman::Controller::Parameters::Hostgroup
|
6
|
+
include ForemanPuppet::Parameters::Environment
|
7
|
+
include ForemanPuppet::Parameters::Puppetclass
|
8
|
+
|
9
|
+
before_action :find_resource, only: %i[edit update destroy override]
|
10
|
+
before_action :setup_search_options, only: :index
|
11
|
+
|
12
|
+
helper ForemanPuppet::PuppetclassLookupKeysHelper
|
13
|
+
|
14
|
+
# TODO: extracted_from_core?
|
15
|
+
def host_params(top_level_hash = controller_name.singularize)
|
16
|
+
filter = self.class.host_params_filter
|
17
|
+
filter.permit(puppet_attributes: {})
|
18
|
+
filter.filter_params(params, parameter_filter_context, top_level_hash).tap do |normalized|
|
19
|
+
if parameter_filter_context.ui? && normalized['compute_attributes'] && normalized['compute_attributes']['scsi_controllers']
|
20
|
+
normalize_scsi_attributes(normalized['compute_attributes'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def index
|
26
|
+
@puppetclasses = resource_base_search_and_page
|
27
|
+
allowed_hostgroup_ids = HostgroupPuppetFacet.joins(:hostgroup_classes)
|
28
|
+
.where(HostgroupClass.arel_table[:puppetclass_id].in(@puppetclasses.map(&:id)))
|
29
|
+
.pluck(:hostgroup_id).uniq
|
30
|
+
@hostgroups_authorizer = Authorizer.new(User.current, collection: allowed_hostgroup_ids)
|
31
|
+
end
|
32
|
+
|
33
|
+
def edit
|
34
|
+
end
|
35
|
+
|
36
|
+
def update
|
37
|
+
if @puppetclass.update(puppetclass_params)
|
38
|
+
process_success
|
39
|
+
else
|
40
|
+
process_error
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
if @puppetclass.destroy
|
46
|
+
process_success
|
47
|
+
else
|
48
|
+
process_error
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def override
|
53
|
+
if @puppetclass.class_params.present?
|
54
|
+
@puppetclass.class_params.each do |class_param|
|
55
|
+
class_param.update(override: params[:enable])
|
56
|
+
end
|
57
|
+
if [true, 'true'].include?(params[:enable])
|
58
|
+
success _('Successfully overridden all parameters of Puppet class %s') % @puppetclass.name
|
59
|
+
else
|
60
|
+
success _('Successfully reset all parameters of Puppet class %s to their default values') % @puppetclass.name
|
61
|
+
end
|
62
|
+
else
|
63
|
+
error _('No parameters to override for Puppet class %s') % @puppetclass.name
|
64
|
+
end
|
65
|
+
redirect_to puppetclasses_path
|
66
|
+
end
|
67
|
+
|
68
|
+
# form AJAX methods
|
69
|
+
def parameters
|
70
|
+
puppetclass = Puppetclass.find(params[:id])
|
71
|
+
render partial: 'foreman_puppet/puppetclasses/class_parameters',
|
72
|
+
locals: { puppetclass: puppetclass,
|
73
|
+
obj: find_host_or_hostgroup }
|
74
|
+
end
|
75
|
+
|
76
|
+
def resource_class
|
77
|
+
model_of_controller
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def find_host_or_hostgroup
|
83
|
+
# params['host_id'] = 'undefined' if NEW since hosts/form and hostgroups/form has no data-id
|
84
|
+
host_id = params.delete(:host_id)
|
85
|
+
if host_id == 'undefined'
|
86
|
+
@obj = Host::Managed.new(host_params('host')) if params['host']
|
87
|
+
@obj ||= Hostgroup.new(hostgroup_params('hostgroup')) if params['hostgroup']
|
88
|
+
elsif params['host']
|
89
|
+
@obj = Host::Base.find(host_id)
|
90
|
+
unless @obj.is_a?(Host::Managed)
|
91
|
+
@obj = @obj.becomes(Host::Managed)
|
92
|
+
@obj.type = 'Host::Managed'
|
93
|
+
end
|
94
|
+
# puppetclass_ids and config_group_ids need to be removed so they don't cause automatic insertsgroup
|
95
|
+
@obj.attributes = host_params('host')
|
96
|
+
elsif params['hostgroup']
|
97
|
+
# hostgroup.id is assigned to params['host_id'] by host_edit.js#load_puppet_class_parameters
|
98
|
+
@obj = Hostgroup.find(host_id)
|
99
|
+
@obj.attributes = hostgroup_params('hostgroup')
|
100
|
+
end
|
101
|
+
@obj
|
102
|
+
end
|
103
|
+
|
104
|
+
def action_permission
|
105
|
+
case params[:action]
|
106
|
+
when 'override'
|
107
|
+
:edit
|
108
|
+
else
|
109
|
+
super
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
class ReactController < ::ApplicationController
|
3
|
+
layout 'foreman_puppet/layouts/application_react'
|
4
|
+
|
5
|
+
def index
|
6
|
+
render html: nil, layout: true
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def controller_permission
|
12
|
+
:foreman_puppet
|
13
|
+
end
|
14
|
+
|
15
|
+
def action_permission
|
16
|
+
:view
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module TemplateRendererScope
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
extend ApipieDSL::Module
|
5
|
+
|
6
|
+
apipie :method, 'Returns puppet classes assigned to the host' do
|
7
|
+
returns Array, desc: 'Puppet classes assigned to the host'
|
8
|
+
end
|
9
|
+
def host_puppet_classes
|
10
|
+
check_host
|
11
|
+
host.puppet&.puppetclasses || []
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module EnvironmentsHelper
|
3
|
+
include PuppetclassesAndEnvironmentsHelper
|
4
|
+
|
5
|
+
def url_for(*args)
|
6
|
+
super
|
7
|
+
rescue ActionController::UrlGenerationError => _e
|
8
|
+
foreman_puppet.url_for(*args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def environments_title_actions
|
12
|
+
title_actions import_proxy_select(hash_for_import_environments_environments_path),
|
13
|
+
button_group(new_link(_('Create Puppet Environment'), engine: foreman_puppet)),
|
14
|
+
button_group(help_button)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module HostsAndHostgroupsHelper
|
3
|
+
# TODO: remove me - prevents the puppetclass tab duplication
|
4
|
+
# unless ForemanPuppet.extracted_from_core?
|
5
|
+
def puppetclasses_tab(puppetclasses_receiver)
|
6
|
+
end
|
7
|
+
|
8
|
+
def environment_inherited_by_default?(host)
|
9
|
+
return false unless host.hostgroup && host.hostgroup_id_was.nil?
|
10
|
+
return false if params[:action] == 'clone'
|
11
|
+
return true unless params[:host]
|
12
|
+
!params[:host].dig(:puppet_attributes, :environment_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
# rubocop:disable Rails/HelperInstanceVariable
|
16
|
+
def user_set_environment?
|
17
|
+
# if the host has no hostgroup
|
18
|
+
return true unless @host&.hostgroup
|
19
|
+
# when editing a host, the values are specified explicitly
|
20
|
+
return true if params[:action] == 'edit'
|
21
|
+
return true if params[:action] == 'clone'
|
22
|
+
# check if the user set the field explicitly despite setting a hostgroup.
|
23
|
+
params[:host] && params[:host][:hostgroup_id] && params[:host].dig(:puppet_attributes, :environment_id)
|
24
|
+
end
|
25
|
+
# rubocop:enable Rails/HelperInstanceVariable
|
26
|
+
|
27
|
+
def host_puppet_environment_field(form, select_options = {}, html_options = {})
|
28
|
+
form.fields_for(:puppet, form.object.puppet || form.object.build_puppet, include_id: false) do |fields|
|
29
|
+
select_options = {
|
30
|
+
include_blank: true,
|
31
|
+
disable_button: _(::HostsAndHostgroupsHelper::INHERIT_TEXT),
|
32
|
+
disable_button_enabled: environment_inherited_by_default?(form.object),
|
33
|
+
user_set: user_set_environment?,
|
34
|
+
}.deep_merge(select_options)
|
35
|
+
|
36
|
+
html_options = {
|
37
|
+
data: {
|
38
|
+
host: {
|
39
|
+
id: form.object.id,
|
40
|
+
},
|
41
|
+
},
|
42
|
+
}.deep_merge(html_options)
|
43
|
+
|
44
|
+
puppet_environment_field(
|
45
|
+
fields,
|
46
|
+
accessible_resource(fields.object, 'ForemanPuppet::Environment', association: :environment),
|
47
|
+
select_options,
|
48
|
+
html_options
|
49
|
+
)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def hostgroup_puppet_environment_field(form, select_options = {}, html_options = {})
|
54
|
+
form.fields_for(:puppet, form.object.puppet || form.object.build_puppet, include_id: false) do |fields|
|
55
|
+
select_options = {
|
56
|
+
include_blank: blank_or_inherit_f(fields, :environment),
|
57
|
+
}.deep_merge(select_options)
|
58
|
+
|
59
|
+
puppet_environment_field(
|
60
|
+
fields,
|
61
|
+
accessible_resource(fields.object, 'ForemanPuppet::Environment', association: :environment),
|
62
|
+
select_options,
|
63
|
+
html_options
|
64
|
+
)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def puppet_environment_field(form, environments_choice, select_options = {}, html_options = {})
|
69
|
+
html_options = {
|
70
|
+
onchange: 'tfm.puppetEnc.hostForm.updatePuppetclasses(this)',
|
71
|
+
help_inline: :indicator,
|
72
|
+
}.deep_merge(html_options)
|
73
|
+
|
74
|
+
select_f(
|
75
|
+
form,
|
76
|
+
:environment_id,
|
77
|
+
environments_choice,
|
78
|
+
:id,
|
79
|
+
:to_label,
|
80
|
+
select_options,
|
81
|
+
html_options
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
def puppetclasses_with_parameters_for(obj)
|
86
|
+
classes = obj.all_puppetclasses
|
87
|
+
ids = classes.reorder(nil).pluck(:id)
|
88
|
+
class_vars = ForemanPuppet::PuppetclassLookupKey.reorder(nil)
|
89
|
+
.joins(:environment_classes)
|
90
|
+
.where(EnvironmentClass.arel_table[:puppetclass_id].in(ids))
|
91
|
+
.distinct
|
92
|
+
.pluck('environment_classes.puppetclass_id')
|
93
|
+
classes.where(id: class_vars)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module HostsHelper
|
3
|
+
UI.register_host_description do
|
4
|
+
multiple_actions_provider :puppet_host_multiple_actions
|
5
|
+
# otherwise registered twice
|
6
|
+
overview_buttons_provider :puppet_host_overview_buttons if ForemanPuppet.extracted_from_core?
|
7
|
+
end
|
8
|
+
|
9
|
+
def puppet_host_multiple_actions
|
10
|
+
if ForemanPuppet.extracted_from_core?
|
11
|
+
actions = [{ action: [_('Change Environment'), foreman_puppet.select_multiple_environment_hosts_path], priority: 200 }]
|
12
|
+
if authorized_for(controller: :hosts, action: :edit) && SmartProxy.unscoped.authorized.with_features('Puppet').exists?
|
13
|
+
actions << { action: [_('Change Puppet Master'), foreman_puppet.select_multiple_puppet_proxy_hosts_path], priority: 1050 }
|
14
|
+
end
|
15
|
+
actions
|
16
|
+
else
|
17
|
+
[]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def puppet_host_overview_buttons(host)
|
22
|
+
buttons = []
|
23
|
+
if SmartProxy.with_features('Puppet').any?
|
24
|
+
buttons << {
|
25
|
+
button: link_to(_('Puppet YAML'), foreman_puppet.externalNodes_host_path(name: host), title: _('Puppet external nodes YAML dump'),
|
26
|
+
class: 'btn btn-default'), priority: 400
|
27
|
+
}
|
28
|
+
end
|
29
|
+
buttons
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module PuppetclassLookupKeysHelper
|
3
|
+
def puppetclass_lookup_keys_breadcrumbs
|
4
|
+
breadcrumbs(resource_url: api_smart_class_parameters_path,
|
5
|
+
name_field: 'parameter',
|
6
|
+
switcher_item_url: '/puppetclass_lookup_keys/:id-:name/edit')
|
7
|
+
end
|
8
|
+
|
9
|
+
# ------ Host(group) Form Helpers -----
|
10
|
+
|
11
|
+
def overridable_puppet_lookup_keys(klass, obj)
|
12
|
+
klass.class_params.override.where(environment_classes: { environment_id: obj.environment_id })
|
13
|
+
end
|
14
|
+
|
15
|
+
def hidden_puppet_lookup_value_fields(lookup_key, lookup_value, disabled)
|
16
|
+
return unless can_edit_params?
|
17
|
+
value_prefix = lookup_value_name_prefix(lookup_key.id)
|
18
|
+
hidden_field(value_prefix, :lookup_key_id, value: lookup_key.id,
|
19
|
+
disabled: disabled, class: 'send_to_remove') +
|
20
|
+
hidden_field(value_prefix, :id, value: lookup_value.id,
|
21
|
+
disabled: disabled, class: 'send_to_remove') +
|
22
|
+
hidden_field(value_prefix, :_destroy, value: false,
|
23
|
+
disabled: disabled, class: 'send_to_remove destroy')
|
24
|
+
end
|
25
|
+
|
26
|
+
def omit_puppet_lookup_check_box(lookup_key, lookup_value, disabled)
|
27
|
+
check_box(lookup_value_name_prefix(lookup_key.id), :omit,
|
28
|
+
value: lookup_value.id,
|
29
|
+
disabled: disabled || !can_edit_params?,
|
30
|
+
onchange: "toggleOmitValue(this, 'value')",
|
31
|
+
hidden: disabled,
|
32
|
+
title: _('Omit from classification output'),
|
33
|
+
checked: lookup_value.omit)
|
34
|
+
end
|
35
|
+
|
36
|
+
def puppet_override_toggle(overridden)
|
37
|
+
return unless can_edit_params?
|
38
|
+
link_to_function(icon_text('pencil-square-o', '', kind: 'fa'), 'tfm.puppetEnc.hostForm.overridePuppetclassParam(this)',
|
39
|
+
title: _('Override this value'),
|
40
|
+
'data-tag': 'override',
|
41
|
+
class: "btn btn-default btn-md btn-override #{'hide' if overridden}") +
|
42
|
+
link_to_function(icon_text('times', '', kind: 'fa'), 'tfm.puppetEnc.hostForm.overridePuppetclassParam(this)',
|
43
|
+
title: _('Remove this override'),
|
44
|
+
'data-tag': 'remove',
|
45
|
+
class: "btn btn-default btn-md btn-override #{'hide' unless overridden}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def puppet_lookup_key_with_diagnostic(obj, lookup_key, lookup_value)
|
49
|
+
value, matcher = lookup_value_matcher(obj, lookup_key)
|
50
|
+
inherited_value = LookupKey.format_value_before_type_cast(value, lookup_key.key_type)
|
51
|
+
effective_value = lookup_value.lookup_key_id.nil? ? inherited_value.to_s : lookup_value.value_before_type_cast.to_s
|
52
|
+
warnings = lookup_key_warnings(lookup_key.required, effective_value.present?)
|
53
|
+
popover_value = lookup_key.hidden_value? ? lookup_key.hidden_value : inherited_value
|
54
|
+
|
55
|
+
parameter_value_content(
|
56
|
+
"#{parameters_receiver}_lookup_values_attributes_#{lookup_key.id}_value",
|
57
|
+
effective_value,
|
58
|
+
popover: diagnostic_popover(lookup_key, matcher, popover_value, warnings),
|
59
|
+
name: "#{lookup_value_name_prefix(lookup_key.id)}[value]",
|
60
|
+
disabled: !lookup_key.overridden?(obj) || lookup_value.omit || !can_edit_params?,
|
61
|
+
inherited_value: inherited_value,
|
62
|
+
lookup_key: lookup_key,
|
63
|
+
hidden_value?: lookup_key.hidden_value?,
|
64
|
+
lookup_key_type: lookup_key.key_type
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def lookup_value_matcher(obj, lookup_key)
|
69
|
+
if parameters_receiver == 'host'
|
70
|
+
value = puppet_lookup_value_hash_host_cache(obj)[lookup_key.id]
|
71
|
+
value_for_key = value.try(:[], lookup_key.key)
|
72
|
+
if value_for_key.present?
|
73
|
+
[value_for_key[:value], "#{value_for_key[:element]} (#{value_for_key[:element_name]})"]
|
74
|
+
else
|
75
|
+
[lookup_key.default_value, _('Default value')]
|
76
|
+
end
|
77
|
+
else # hostgroup
|
78
|
+
obj.inherited_lookup_value(lookup_key)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# rubocop:disable Rails/HelperInstanceVariable
|
83
|
+
def puppet_lookup_value_hash_host_cache(host)
|
84
|
+
@puppet_lookup_value_hash_host_cache ||= {}
|
85
|
+
@puppet_lookup_value_hash_host_cache[host.id] ||= ForemanPuppet::HostInfoProviders::PuppetInfo.new(host).inherited_puppetclass_parameters
|
86
|
+
end
|
87
|
+
# rubocop:enable Rails/HelperInstanceVariable
|
88
|
+
|
89
|
+
def diagnostic_popover(lookup_key, matcher, inherited_value, warnings)
|
90
|
+
description = lookup_key_description(lookup_key, matcher, inherited_value)
|
91
|
+
popover('', description.prepend(warnings[:text]),
|
92
|
+
data: { placement: 'top' },
|
93
|
+
title: _('Original value info'),
|
94
|
+
icon: 'info-circle',
|
95
|
+
kind: 'fa')
|
96
|
+
end
|
97
|
+
|
98
|
+
def lookup_key_description(lookup_key, matcher, inherited_value)
|
99
|
+
format(_("<b>Description:</b> %{desc}<br/>
|
100
|
+
<b>Type:</b> %{type}<br/>
|
101
|
+
<b>Matcher:</b> %{matcher}<br/>
|
102
|
+
<b>Inherited value:</b> %{inherited_value}"),
|
103
|
+
desc: html_escape(lookup_key.description),
|
104
|
+
type: lookup_key.key_type,
|
105
|
+
matcher: html_escape(matcher),
|
106
|
+
inherited_value: html_escape(inherited_value))
|
107
|
+
end
|
108
|
+
|
109
|
+
def lookup_key_warnings(required, has_value)
|
110
|
+
return { text: '', icon: 'info' } if has_value
|
111
|
+
|
112
|
+
if required
|
113
|
+
{ text: _('Required parameter without value.<br/><b>Please override!</b><br/>'),
|
114
|
+
icon: 'error-circle-o' }
|
115
|
+
else
|
116
|
+
{ text: _('Optional parameter without value.<br/><i>Still managed by Foreman, the value will be empty.</i><br/>'),
|
117
|
+
icon: 'warning-triangle-o' }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Input tags used to override lookup keys need a 'name' HTML attribute to
|
122
|
+
# tell Rails which lookup_value they belong to.
|
123
|
+
# This method returns the name attribute for any combination of lookup_key
|
124
|
+
# and host/hostgroup. Other objects that may receive parameters too will need
|
125
|
+
# to override this method in their respective helpers.
|
126
|
+
def lookup_value_name_prefix(lookup_key_id)
|
127
|
+
"#{parameters_receiver}[lookup_values_attributes][#{lookup_key_id}]"
|
128
|
+
end
|
129
|
+
|
130
|
+
def parameters_receiver
|
131
|
+
return 'host' if params.key?(:host) || params[:controller] == 'hosts'
|
132
|
+
'hostgroup'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ForemanPuppet
|
2
|
+
module PuppetclassesAndEnvironmentsHelper
|
3
|
+
def class_update_text(pcs, env)
|
4
|
+
if pcs.empty?
|
5
|
+
_('Empty environment')
|
6
|
+
elsif pcs == ['_destroy_']
|
7
|
+
_('Deleted environment')
|
8
|
+
elsif pcs.delete '_destroy_'
|
9
|
+
format(_('Deleted environment %{env} and %{pcs}'), env: env, pcs: pcs.to_sentence)
|
10
|
+
elsif pcs == ['_ignored_']
|
11
|
+
_('Ignored environment')
|
12
|
+
else
|
13
|
+
module_puppetclasses(pcs.is_a?(Hash) ? pcs.keys : pcs)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def import_proxy_select(hash)
|
18
|
+
select_action_button(_('Import'), {}, import_proxy_links(hash, true))
|
19
|
+
end
|
20
|
+
|
21
|
+
def import_proxy_links(hash, import_env_text = false, classes = nil)
|
22
|
+
import_from_text = import_env_text ? _('Import environments from %s') : _('Import classes from %s')
|
23
|
+
SmartProxy.with_features('Puppet').map do |proxy|
|
24
|
+
display_link_if_authorized(import_from_text % proxy.name, hash.merge(proxy: proxy), { class: classes })
|
25
|
+
end.flatten
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def module_puppetclasses(classes)
|
31
|
+
mod_classes = {}
|
32
|
+
classes.each do |klass|
|
33
|
+
if (mod = klass.gsub(/::.*/, ''))
|
34
|
+
mod_classes[mod] ||= []
|
35
|
+
mod_classes[mod] << klass
|
36
|
+
end
|
37
|
+
end
|
38
|
+
mod_classes.keys.sort.map do |mod_name|
|
39
|
+
num = mod_classes[mod_name].size
|
40
|
+
num_tag = tag.span(num.to_s, class: 'label label-info')
|
41
|
+
tag.a(
|
42
|
+
mod_name,
|
43
|
+
rel: 'popover',
|
44
|
+
data: { content: mod_classes[mod_name].sort.join('<br>').html_safe,
|
45
|
+
"original-title": format(n_('%{name} has %{num_tag} class', '%{name} has %{num_tag} classes', num), name: mod_name, num_tag: num_tag),
|
46
|
+
trigger: 'focus',
|
47
|
+
container: 'body',
|
48
|
+
html: true },
|
49
|
+
role: 'button',
|
50
|
+
tabindex: '-1'
|
51
|
+
)
|
52
|
+
end.to_sentence.html_safe
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|