foreman_puppet 0.0.1
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.
- 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,59 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module PuppetclassesHelper
|
|
3
|
+
include PuppetclassesAndEnvironmentsHelper
|
|
4
|
+
include LookupKeysHelper
|
|
5
|
+
|
|
6
|
+
def overridden?(puppetclass)
|
|
7
|
+
puppetclass.class_params.present? && puppetclass.class_params.map(&:override).all?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def puppetclass_in_environment?(environment, puppetclass)
|
|
11
|
+
return false unless environment
|
|
12
|
+
environment.puppetclasses.map(&:id).include?(puppetclass.id)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def puppetclass_group_with_icon(list, selected)
|
|
16
|
+
css_options = if (list.last - selected).empty?
|
|
17
|
+
{ class: 'hide' }
|
|
18
|
+
else
|
|
19
|
+
{}
|
|
20
|
+
end
|
|
21
|
+
link_to_function(icon_text('plus', list.first, css_options),
|
|
22
|
+
"tfm.classEditor.expandClassList(this, '#pc_#{list.first}')")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def link_to_remove_puppetclass(klass, type)
|
|
26
|
+
options = options_for_puppetclass_selection(klass, type)
|
|
27
|
+
text = link_to_remove_function(truncate(klass.name, length: 28), options)
|
|
28
|
+
tag.span(text) + link_to_remove_function('', options.merge(class: 'glyphicon glyphicon-minus-sign'))
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def link_to_remove_function(text, options)
|
|
32
|
+
options.delete_if { |key, _value| !options[key].to_s } # otherwise error during template render
|
|
33
|
+
title = (_('Click to remove %s') % options[:"data-class-name"])
|
|
34
|
+
link_to_function(text, 'tfm.classEditor.removePuppetClass(this)', options.merge!('data-original-title': title))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def link_to_add_puppetclass(klass, type)
|
|
38
|
+
options = options_for_puppetclass_selection(klass, type)
|
|
39
|
+
text = link_to_add_function(truncate(klass.name, length: 28), options)
|
|
40
|
+
tag.span(text) +
|
|
41
|
+
link_to_add_function('', options.merge(class: 'glyphicon glyphicon-plus-sign'))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def link_to_add_function(text, options)
|
|
45
|
+
link_to_function(text, 'tfm.classEditor.addPuppetClass(this)',
|
|
46
|
+
options.merge('data-original-title': _('Click to add %s') % options[:"data-class-name"]))
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def options_for_puppetclass_selection(klass, type)
|
|
50
|
+
{
|
|
51
|
+
'data-class-id': klass.id,
|
|
52
|
+
'data-class-name': klass.name,
|
|
53
|
+
'data-type': type,
|
|
54
|
+
'data-url': foreman_puppet.parameters_puppetclass_path(id: klass.id),
|
|
55
|
+
rel: 'twipsy',
|
|
56
|
+
}
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module TemplateCombinationsHelper
|
|
3
|
+
def combination(template)
|
|
4
|
+
template.template_combinations.map do |comb|
|
|
5
|
+
str = []
|
|
6
|
+
str << (comb.hostgroup_id.nil? ? _('None') : comb.hostgroup.to_s)
|
|
7
|
+
str << (comb.environment_id.nil? ? _('None') : comb.environment.to_s)
|
|
8
|
+
str.join(' / ')
|
|
9
|
+
end.to_sentence
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def how_templates_are_determined
|
|
13
|
+
text = ['<p>']
|
|
14
|
+
text << _("When editing a template, you must assign a list \
|
|
15
|
+
of operating systems which this template can be used with. Optionally, you can \
|
|
16
|
+
restrict a template to a list of host groups and/or environments.")
|
|
17
|
+
text << '</p><p>'
|
|
18
|
+
text << _("When a Host requests a template (e.g. during provisioning), Foreman \
|
|
19
|
+
will select the best match from the available templates of that type, in the \
|
|
20
|
+
following order:")
|
|
21
|
+
text << '</p><ul>'
|
|
22
|
+
text << "<li>#{_('Host group and Environment')}</li>"
|
|
23
|
+
text << "<li>#{_('Host group only')}</li>"
|
|
24
|
+
text << "<li>#{_('Environment only')}</li>"
|
|
25
|
+
text << "<li>#{_('Operating system default')}</li>"
|
|
26
|
+
text << '</ul>'
|
|
27
|
+
text << tag.p(_('The final entry, Operating System default, can be set by editing the %s page.') %
|
|
28
|
+
(link_to _('Operating System'), main_app.operatingsystems_path))
|
|
29
|
+
|
|
30
|
+
alert(class: 'alert-info', header: 'How templates are determined', text: safe_join(text))
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module Extensions
|
|
3
|
+
module Host
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
prepend PrependedMethods
|
|
8
|
+
|
|
9
|
+
env_assoc = reflect_on_association(:environment)
|
|
10
|
+
env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
|
|
11
|
+
|
|
12
|
+
include_in_clone puppet: %i[config_groups host_config_groups host_classes]
|
|
13
|
+
|
|
14
|
+
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment
|
|
15
|
+
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ '],
|
|
16
|
+
ext_method: :search_by_deprecated_class
|
|
17
|
+
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :puppetclass, only_explicit: true, operators: ['= ', '~ '],
|
|
18
|
+
ext_method: :search_by_puppetclass
|
|
19
|
+
scoped_search relation: :config_groups, on: :name, complete_value: true, rename: :config_group, only_explicit: true, operators: ['= ', '~ '],
|
|
20
|
+
ext_method: :search_by_config_group
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class_methods do
|
|
24
|
+
def search_by_deprecated_class(key, operator, value)
|
|
25
|
+
Foreman::Deprecation.deprecation_warning('3.2', 'search by `class` has been deprecated, please search by `puppetclass` instead')
|
|
26
|
+
search_by_puppetclass(key, operator, value)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def search_by_puppetclass(_key, operator, value)
|
|
30
|
+
conditions = sanitize_sql_for_conditions(["puppetclasses.name #{operator} ?", value_to_sql(operator, value)])
|
|
31
|
+
config_group_ids = ForemanPuppet::ConfigGroup.joins(:puppetclasses).where(conditions).pluck(:id)
|
|
32
|
+
host_ids = ::Host.authorized(:view_hosts, Host).joins(puppet: :puppetclasses).where(conditions).distinct.pluck(:id)
|
|
33
|
+
host_ids += ForemanPuppet::HostConfigGroup
|
|
34
|
+
.where(host_type: 'ForemanPuppet::HostPuppetFacet')
|
|
35
|
+
.where(config_group_id: config_group_ids)
|
|
36
|
+
.pluck(:host_id)
|
|
37
|
+
hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(puppet: :puppetclasses).where(conditions).map(&:subtree_ids)
|
|
38
|
+
if config_group_ids.any?
|
|
39
|
+
hostgroup_cg_ids = ForemanPuppet::HostgroupPuppetFacet.joins(:host_config_groups)
|
|
40
|
+
.where(host_config_groups: { config_group_id: config_group_ids })
|
|
41
|
+
.pluck(:hostgroup_id)
|
|
42
|
+
hostgroup_ids += ::Hostgroup.unscoped.with_taxonomy_scope.where(id: hostgroup_cg_ids).map(&:subtree_ids)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
conds = []
|
|
46
|
+
conds << "hosts.id IN(#{host_ids.join(',')})" if host_ids.present?
|
|
47
|
+
conds << "hosts.hostgroup_id IN(#{hostgroup_ids.uniq.join(',')})" if hostgroup_ids.present?
|
|
48
|
+
{ conditions: conds.join(' OR ').presence || 'hosts.id < 0' }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def search_by_config_group(_key, operator, value)
|
|
52
|
+
conditions = sanitize_sql_for_conditions(["config_groups.name #{operator} ?", value_to_sql(operator, value)])
|
|
53
|
+
host_ids = ::Host::Managed.joins(puppet: :config_groups).where(conditions).pluck(:id).uniq
|
|
54
|
+
hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(puppet: :config_groups).where(conditions).distinct.map(&:subtree_ids).flatten.uniq
|
|
55
|
+
|
|
56
|
+
conds = []
|
|
57
|
+
conds << "hosts.id IN(#{host_ids.join(',')})" if host_ids.present?
|
|
58
|
+
conds << "hosts.hostgroup_id IN(#{hostgroup_ids.join(',')})" if hostgroup_ids.present?
|
|
59
|
+
{ conditions: conds.join(' OR ').presence || 'hosts.id < 0' }
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
module PrependedMethods
|
|
64
|
+
def provisioning_template(opts = {})
|
|
65
|
+
opts[:environment_id] ||= puppet&.environment_id
|
|
66
|
+
super(opts)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def available_template_kinds(provisioning = nil)
|
|
70
|
+
kinds = template_kinds(provisioning)
|
|
71
|
+
kinds.map do |kind|
|
|
72
|
+
ProvisioningTemplate.find_template({ kind: kind.name,
|
|
73
|
+
operatingsystem_id: operatingsystem_id,
|
|
74
|
+
hostgroup_id: hostgroup_id,
|
|
75
|
+
environment_id: puppet&.environment_id })
|
|
76
|
+
end.compact
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# rubocop:disable Naming/MethodName
|
|
80
|
+
def importNode(nodeinfo)
|
|
81
|
+
facet = puppet || build_puppet
|
|
82
|
+
facet.import_puppet_node(nodeinfo)
|
|
83
|
+
end
|
|
84
|
+
# rubocop:enable Naming/MethodName
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module Extensions
|
|
3
|
+
module Hostgroup
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
class << self
|
|
8
|
+
prepend PatchedClassMethods
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
env_assoc = reflect_on_association(:environment)
|
|
12
|
+
env_assoc.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
|
|
13
|
+
|
|
14
|
+
include_in_clone puppet: %i[host_config_groups config_groups hostgroup_classes]
|
|
15
|
+
|
|
16
|
+
# will need through relation to work properly
|
|
17
|
+
scoped_search relation: :environment, on: :name, complete_value: true, rename: :environment, only_explicit: true
|
|
18
|
+
scoped_search relation: :puppetclasses, on: :name, complete_value: true, rename: :class, only_explicit: true, operators: ['= ', '~ ']
|
|
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
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Temporary, can be ordinary class_methods do, when removed from core
|
|
28
|
+
module PatchedClassMethods
|
|
29
|
+
def search_by_config_group(_key, operator, value)
|
|
30
|
+
conditions = sanitize_sql_for_conditions(["config_groups.name #{operator} ?", value_to_sql(operator, value)])
|
|
31
|
+
hostgroup_ids = ::Hostgroup.unscoped.with_taxonomy_scope.joins(puppet: :config_groups).where(conditions).map(&:subtree_ids).flatten.uniq
|
|
32
|
+
|
|
33
|
+
opts = 'hostgroups.id < 0'
|
|
34
|
+
opts = "hostgroups.id IN(#{hostgroup_ids.join(',')})" if hostgroup_ids.present?
|
|
35
|
+
{ conditions: opts }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module Extensions
|
|
3
|
+
module ProvisioningTemplate
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
if ForemanPuppet.extracted_from_core?
|
|
8
|
+
has_many :environments, through: :template_combinations
|
|
9
|
+
before_destroy EnsureNotUsedBy.new(:environments)
|
|
10
|
+
|
|
11
|
+
scoped_search relation: :environments, on: :name, rename: :environment, complete_value: true
|
|
12
|
+
|
|
13
|
+
class << base
|
|
14
|
+
prepend PrependedClassMethods
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
prepend PrependedMethods
|
|
18
|
+
else
|
|
19
|
+
env_assoc = reflect_on_association(:environments)
|
|
20
|
+
env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
module PrependedClassMethods
|
|
25
|
+
def templates_by_template_combinations(templates, hosts_or_conditions)
|
|
26
|
+
if hosts_or_conditions.is_a?(Hash)
|
|
27
|
+
conditions = hosts_or_conditions
|
|
28
|
+
conditions[:hostgroup_id] = Array.wrap(conditions[:hostgroup_id]) | [nil]
|
|
29
|
+
conditions[:environment_id] = Array.wrap(conditions[:environment_id]) | [nil]
|
|
30
|
+
else
|
|
31
|
+
conditions = {}
|
|
32
|
+
conditions[:hostgroup_id] = hosts_or_conditions.pluck(:hostgroup_id) | [nil]
|
|
33
|
+
conditions[:environment_id] = hosts_or_conditions.pluck(:environment_id) | [nil]
|
|
34
|
+
end
|
|
35
|
+
at = TemplateCombination.arel_table
|
|
36
|
+
arel = at[:hostgroup_id].in(conditions[:hostgroup_id])
|
|
37
|
+
arel = arel.and(at[:environment_id].in(conditions[:environment_id]))
|
|
38
|
+
templates.joins(:template_combinations).where(arel).distinct
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def template_includes
|
|
42
|
+
includes = super
|
|
43
|
+
tc_include = includes.detect { |i| i.key?(:template_combinations) }
|
|
44
|
+
tc_include ||= includes << {}
|
|
45
|
+
tc_include[:template_combinations] = %i[hostgroup environment]
|
|
46
|
+
includes
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
module PrependedMethods
|
|
51
|
+
def reject_template_combination_attributes?(params)
|
|
52
|
+
params[:environment_id].blank? && super(params)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# check if our template is a snippet, and remove its associations just in case they were selected.
|
|
56
|
+
def check_for_snippet_assoications
|
|
57
|
+
super
|
|
58
|
+
return unless snippet
|
|
59
|
+
environments.clear
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module Extensions
|
|
3
|
+
module Taxonomy
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
has_many :environments, through: :taxable_taxonomies, source: :taxable, source_type: 'ForemanPuppet::Environment'
|
|
8
|
+
|
|
9
|
+
has_many :puppetclasses, through: :environments
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def dup
|
|
13
|
+
new = super
|
|
14
|
+
new.environments = environments
|
|
15
|
+
new
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module Extensions
|
|
3
|
+
module TemplateCombination
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
if ForemanPuppet.extracted_from_core?
|
|
8
|
+
belongs_to :environment
|
|
9
|
+
|
|
10
|
+
validates :environment_id, uniqueness: { scope: %i[hostgroup_id provisioning_template_id] }
|
|
11
|
+
|
|
12
|
+
callback = __callbacks[:validate].detect do |v|
|
|
13
|
+
v.filter.is_a?(ActiveRecord::Validations::UniquenessValidator) && v.filter.attributes.include?(:hostgroup_id)
|
|
14
|
+
end
|
|
15
|
+
callback.filter.options[:scope] << :environment_id
|
|
16
|
+
else
|
|
17
|
+
env_assoc = reflect_on_association(:environment)
|
|
18
|
+
env_assoc&.instance_variable_set(:@class_name, 'ForemanPuppet::Environment')
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
module Extensions
|
|
3
|
+
module User
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
def visible_environments
|
|
7
|
+
authorized_scope = Environment.unscoped.authorized(:view_environments)
|
|
8
|
+
authorized_scope = authorized_scope
|
|
9
|
+
.joins(:taxable_taxonomies)
|
|
10
|
+
.where('taxable_taxonomies.taxonomy_id' => taxonomy_ids[:organizations] + taxonomy_ids[:locations])
|
|
11
|
+
result = authorized_scope.distinct.pluck(:name)
|
|
12
|
+
if User.current.admin?
|
|
13
|
+
# Admin users can also see Environments that do not have any organization or location, even when
|
|
14
|
+
# organizations and locations are enabled.
|
|
15
|
+
untaxed_environments = Environment.unscoped.where.not(id: TaxableTaxonomy.where(taxable_type: 'ForemanPuppet::Environment').distinct.select(:taxable_id)).pluck(:name)
|
|
16
|
+
result += untaxed_environments
|
|
17
|
+
end
|
|
18
|
+
result
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
module ForemanPuppet
|
|
2
|
+
# Common methods between host and hostgroup
|
|
3
|
+
# mostly for template rendering consistency
|
|
4
|
+
module HostCommon
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
included do
|
|
8
|
+
belongs_to :environment
|
|
9
|
+
has_many :host_config_groups, as: :host, dependent: :destroy
|
|
10
|
+
has_many :config_groups, through: :host_config_groups
|
|
11
|
+
has_many :config_group_classes, through: :config_groups
|
|
12
|
+
has_many :group_puppetclasses, through: :config_groups, source: :puppetclasses
|
|
13
|
+
|
|
14
|
+
alias_method :all_puppetclasses, :classes
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def parent_name
|
|
18
|
+
if is_a?(ForemanPuppet::HostPuppetFacet)
|
|
19
|
+
host.hostgroup&.name
|
|
20
|
+
elsif is_a?(ForemanPuppet::HostgroupPuppetFacet)
|
|
21
|
+
hostgroup.parent&.name
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def cg_class_ids
|
|
26
|
+
cg_ids = if is_a?(ForemanPuppet::HostgroupPuppetFacet)
|
|
27
|
+
hostgroup.path.each.map { |hg| hg.puppet&.config_group_ids }.compact.flatten.uniq
|
|
28
|
+
else
|
|
29
|
+
host.hostgroup ? host.hostgroup.path.each.map { |hg| hg.puppet&.config_group_ids }.compact.flatten.uniq : []
|
|
30
|
+
end
|
|
31
|
+
ForemanPuppet::ConfigGroupClass.where(config_group_id: (config_group_ids + cg_ids)).pluck(:puppetclass_id)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def hg_class_ids
|
|
35
|
+
hg_ids = if is_a?(HostgroupPuppetFacet)
|
|
36
|
+
hostgroup.path_ids
|
|
37
|
+
elsif host.hostgroup
|
|
38
|
+
host.hostgroup.path_ids
|
|
39
|
+
end
|
|
40
|
+
ForemanPuppet::HostgroupClass.joins(:hostgroup_puppet_facet)
|
|
41
|
+
.where(ForemanPuppet::HostgroupPuppetFacet.arel_table[:hostgroup_id].in(hg_ids))
|
|
42
|
+
.pluck(:puppetclass_id)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def host_class_ids
|
|
46
|
+
(is_a?(ForemanPuppet::HostPuppetFacet) ? host_classes : hostgroup_classes).map(&:puppetclass_id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def all_puppetclass_ids
|
|
50
|
+
cg_class_ids + hg_class_ids + host_class_ids
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def classes(env = environment)
|
|
54
|
+
conditions = { id: all_puppetclass_ids }
|
|
55
|
+
if env
|
|
56
|
+
env.puppetclasses.where(conditions)
|
|
57
|
+
else
|
|
58
|
+
ForemanPuppet::Puppetclass.where(conditions)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def puppetclass_ids
|
|
63
|
+
classes.reorder('').pluck('puppetclasses.id')
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def classes_in_groups
|
|
67
|
+
conditions = { id: cg_class_ids }
|
|
68
|
+
if environment
|
|
69
|
+
environment.puppetclasses.where(conditions) - parent_classes
|
|
70
|
+
else
|
|
71
|
+
ForemanPuppet::Puppetclass.where(conditions) - parent_classes
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Returns Puppetclasses of a Host or Hostgroup
|
|
76
|
+
#
|
|
77
|
+
# It does not include Puppetclasses of it's ConfigGroupClasses
|
|
78
|
+
#
|
|
79
|
+
def individual_puppetclasses
|
|
80
|
+
ids = host_class_ids - cg_class_ids
|
|
81
|
+
return puppetclasses if ids.blank? && new_record?
|
|
82
|
+
ForemanPuppet::Puppetclass.includes(:environments).where(id: ids)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def available_puppetclasses
|
|
86
|
+
return ForemanPuppet::Puppetclass.all.authorized(:view_puppetclasses) if environment.blank?
|
|
87
|
+
environment.puppetclasses - parent_classes
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|