foreman_puppet 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/foreman_puppet/extensions/api_hostgroups_controller.rb +14 -16
- data/app/controllers/concerns/foreman_puppet/{api/import_puppetclasses_common_controller.rb → extensions/api_smart_proxies_controller.rb} +9 -3
- data/app/controllers/concerns/foreman_puppet/extensions/api_template_combinations_controller.rb +23 -1
- data/app/controllers/concerns/foreman_puppet/extensions/api_v2_hosts_controller.rb +15 -17
- data/app/controllers/concerns/foreman_puppet/extensions/hostgroups_controller_extensions.rb +3 -1
- data/app/controllers/concerns/foreman_puppet/extensions/hosts_controller_extensions.rb +0 -1
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_host.rb +41 -32
- data/app/controllers/concerns/foreman_puppet/extensions/parameters_hostgroup.rb +37 -34
- data/app/controllers/foreman_puppet/api/v2/environments_controller.rb +0 -1
- data/app/controllers/foreman_puppet/api/v2/hostgroup_classes_controller.rb +1 -1
- data/app/controllers/foreman_puppet/puppetclasses_controller.rb +1 -1
- data/app/helpers/foreman_puppet/environments_helper.rb +1 -1
- data/app/helpers/foreman_puppet/hosts_and_hostgroups_helper.rb +0 -5
- data/app/helpers/foreman_puppet/hosts_helper.rb +6 -10
- data/app/models/concerns/foreman_puppet/extensions/host.rb +2 -16
- data/app/models/concerns/foreman_puppet/extensions/hostgroup.rb +2 -7
- data/app/models/concerns/foreman_puppet/extensions/provisioning_template.rb +7 -12
- data/app/models/concerns/foreman_puppet/extensions/template_combination.rb +5 -10
- data/app/models/foreman_puppet/host_puppet_facet.rb +1 -1
- data/app/models/foreman_puppet/hostgroup_puppet_facet.rb +2 -0
- data/app/services/concerns/foreman_puppet/extensions/host_counter.rb +17 -0
- data/app/services/foreman_puppet/puppet_class_importer.rb +0 -6
- data/app/views/foreman_puppet/api/v2/host_puppet_facets/host_list.json.rabl +3 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/base.json.rabl +2 -0
- data/app/views/foreman_puppet/api/v2/hostgroup_puppet_facets/hostgroup_list.json.rabl +3 -0
- data/app/views/foreman_puppet/config_groups/index.html.erb +1 -1
- data/config/api_routes.rb +1 -9
- data/config/initializers/api_reroute.rb +73 -5
- data/db/migrate/20101121140000_add_environment_to_template_combinations.foreman_puppet.rb +1 -1
- data/db/migrate/20200803113803_migrate_environment_to_puppet_facet.foreman_puppet.rb +2 -0
- data/db/migrate/20200803113903_migrate_host_type_in_host_config_groups.foreman_puppet.rb +36 -20
- data/db/migrate/20201125113903_migrate_puppetclasses_to_facets.foreman_puppet.rb +0 -8
- data/db/migrate/20210924103241_remove_katello_id_from_environments.foreman_puppet.rb +5 -0
- data/db/migrate/20211111125003_drop_puppetclasses_direct_references.foreman_puppet.rb +11 -0
- data/db/migrate/20211112130803_cleanup_environment_from_core_tables.foreman_puppet.rb +10 -0
- data/db/migrate_foreman/{20090722141107_create_environments.rb → 20090722141107_create_environments.foreman_puppet.rb} +3 -3
- data/db/migrate_foreman/20090802062223_create_puppetclasses.foreman_puppet.rb +29 -0
- data/db/migrate_foreman/20090905150132_create_hostgroups_puppetclasses.foreman_puppet.rb +12 -0
- data/db/migrate_foreman/20110412103238_remove_unused_fields_from_puppet_classes.foreman_puppet.rb +9 -0
- data/db/migrate_foreman/20110712070522_create_host_class.foreman_puppet.rb +11 -0
- data/db/migrate_foreman/20120824142048_add_some_indexes.foreman_puppet.rb +21 -0
- data/db/migrate_foreman/{20120905095532_create_environment_classes.rb → 20120905095532_create_environment_classes.foreman_puppet.rb} +2 -2
- data/db/migrate_foreman/20121018152459_create_hostgroup_classes.foreman_puppet.rb +11 -0
- data/db/migrate_foreman/{20140407161817_create_config_groups.rb → 20140407161817_create_config_groups.foreman_puppet.rb} +0 -0
- data/db/migrate_foreman/{20140407162007_create_config_group_classes.rb → 20140407162007_create_config_group_classes.foreman_puppet.rb} +0 -0
- data/db/migrate_foreman/{20140407162059_create_host_config_groups.rb → 20140407162059_create_host_config_groups.foreman_puppet.rb} +0 -0
- data/db/migrate_foreman/{20161205142618_delete_orphaned_smart_class_parameters.rb → 20161205142618_delete_orphaned_smart_class_parameters.foreman_puppet.rb} +1 -1
- data/db/migrate_foreman/{20170109115157_fix_lookup_key_auditable_type.rb → 20170109115157_fix_lookup_key_auditable_type.foreman_puppet.rb} +0 -0
- data/db/migrate_foreman/20180816134832_cast_lookup_key_values.foreman_puppet.rb +5 -0
- data/db/migrate_foreman/20180831115634_add_uniqueness_to_puppetclass_name.foreman_puppet.rb +24 -0
- data/db/migrate_foreman/{20181023112532_add_environment_puppetclass_id.rb → 20181023112532_add_environment_puppetclass_id.foreman_puppet.rb} +1 -1
- data/db/migrate_foreman/{20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.rb → 20181224174419_add_index_to_environment_class_by_lookup_key_and_puppetclass.foreman_puppet.rb} +0 -0
- data/lib/foreman_puppet/engine.rb +6 -36
- data/lib/foreman_puppet/register.rb +49 -45
- data/lib/foreman_puppet/version.rb +1 -1
- data/lib/foreman_puppet.rb +1 -6
- data/locale/ca/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/ca/foreman_puppet.po +760 -0
- data/locale/cs_CZ/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/cs_CZ/foreman_puppet.edit.po +1085 -0
- data/locale/cs_CZ/foreman_puppet.po +823 -0
- data/locale/cs_CZ/foreman_puppet.po.time_stamp +0 -0
- data/locale/de/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/de/foreman_puppet.po +844 -0
- data/locale/en/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/en/foreman_puppet.edit.po +317 -162
- data/locale/en/foreman_puppet.po +119 -8
- data/locale/en_GB/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/en_GB/foreman_puppet.po +820 -0
- data/locale/es/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/es/foreman_puppet.po +827 -0
- data/locale/foreman_puppet.pot +376 -205
- data/locale/fr/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/fr/foreman_puppet.po +835 -0
- data/locale/gemspec.rb +1 -1
- data/locale/gl/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/gl/foreman_puppet.po +818 -0
- data/locale/it/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/it/foreman_puppet.po +822 -0
- data/locale/ja/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/ja/foreman_puppet.po +830 -0
- data/locale/ko/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/ko/foreman_puppet.po +819 -0
- data/locale/nl_NL/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/nl_NL/foreman_puppet.po +823 -0
- data/locale/pl/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/pl/foreman_puppet.po +822 -0
- data/locale/pt_BR/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/pt_BR/foreman_puppet.po +826 -0
- data/locale/ru/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/ru/foreman_puppet.po +827 -0
- data/locale/sv_SE/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/sv_SE/foreman_puppet.po +822 -0
- data/locale/zh_CN/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/zh_CN/foreman_puppet.po +831 -0
- data/locale/zh_TW/LC_MESSAGES/foreman_puppet.mo +0 -0
- data/locale/zh_TW/foreman_puppet.po +821 -0
- data/package.json +8 -11
- data/test/controllers/foreman_puppet/api/v2/environments_controller_test.rb +0 -231
- data/test/controllers/foreman_puppet/api/v2/smart_proxies_controller_test.rb +255 -0
- data/test/controllers/foreman_puppet/environments_controller_test.rb +2 -2
- data/test/controllers/foreman_puppet/hosts_controller_test.rb +0 -1
- data/test/factories/foreman_puppet_factories.rb +0 -2
- data/test/helpers/foreman_puppet/hosts_and_hostgroups_helper_test.rb +70 -31
- data/test/integration/foreman_puppet/dashboard_js_test.rb +31 -0
- data/test/integration/foreman_puppet/host_js_test.rb +0 -1
- data/test/integration/foreman_puppet/puppetclass_js_test.rb +1 -1
- data/test/models/foreman_puppet/host_puppet_facet_test.rb +7 -1
- data/test/models/foreman_puppet/host_test.rb +26 -0
- data/test/models/foreman_puppet/user_test.rb +1 -5
- data/test/services/foreman_puppet/host_counter_test.rb +17 -0
- data/test/unit/foreman_puppet/puppet_class_importer_test.rb +1 -1
- data/webpack/src/Components/Environments/Welcome.js +2 -2
- metadata +73 -18
- data/db/migrate_foreman/20180816134832_cast_lookup_key_values.rb +0 -35
@@ -2,7 +2,7 @@
|
|
2
2
|
<% content_for(:search_bar) { } %>
|
3
3
|
<% title _('Config Groups') %>
|
4
4
|
|
5
|
-
<% title_actions new_link(_('Create Config Group'), engine: foreman_puppet), help_button %>
|
5
|
+
<% title_actions new_link(_('Create Config Group'), { engine: foreman_puppet }, id: 'new_config_group'), help_button %>
|
6
6
|
|
7
7
|
<table class="<%= table_css_classes 'table-fixed' %>">
|
8
8
|
<thead>
|
data/config/api_routes.rb
CHANGED
@@ -2,14 +2,6 @@ ForemanPuppet::Engine.routes.draw do
|
|
2
2
|
namespace :api, defaults: { format: 'json' } do
|
3
3
|
scope '(:apiv)', module: :v2, defaults: { apiv: 'v2' }, apiv: /v1|v2/, constraints: ApiConstraints.new(version: 2, default: true) do
|
4
4
|
constraints(id: %r{[^/]+}) do
|
5
|
-
resources :puppet_smart_proxies, only: [] do
|
6
|
-
post :import_puppetclasses, on: :member, controller: 'environments'
|
7
|
-
|
8
|
-
resources :environments, only: [] do
|
9
|
-
post :import_puppetclasses, on: :member
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
5
|
resources :config_groups, except: %i[new edit]
|
14
6
|
|
15
7
|
resources :hosts, only: [] do
|
@@ -40,7 +32,7 @@ ForemanPuppet::Engine.routes.draw do
|
|
40
32
|
end
|
41
33
|
end
|
42
34
|
resources :hosts, only: %i[index show], controller: '/api/v2/hosts'
|
43
|
-
resources :template_combinations, only: %i[index], controller: '/api/v2/template_combinations'
|
35
|
+
resources :template_combinations, only: %i[index show create update], controller: '/api/v2/template_combinations'
|
44
36
|
end
|
45
37
|
|
46
38
|
resources :puppetclasses, except: %i[new edit] do
|
@@ -1,13 +1,81 @@
|
|
1
1
|
Foreman::Application.routes.prepend do
|
2
2
|
namespace :api, defaults: { format: 'json' } do
|
3
3
|
scope '(:apiv)', module: :v2, defaults: { apiv: 'v2' }, apiv: /v2/, constraints: ApiConstraints.new(version: 2, default: true) do
|
4
|
-
resources :
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
resources :smart_proxies, only: [] do
|
5
|
+
post :import_puppetclasses, on: :member
|
6
|
+
resources :environments, only: [] do
|
7
|
+
post :import_puppetclasses, on: :member, controller: '/api/v2/smart_proxies'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
8
11
|
resources :config_groups, controller: '/foreman_puppet/api/v2/config_groups', except: %i[new edit]
|
9
|
-
|
12
|
+
|
13
|
+
resources :hosts, only: [] do
|
14
|
+
resources :puppetclasses, controller: '/foreman_puppet/api/v2/puppetclasses', except: %i[new edit]
|
15
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create] do
|
16
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
17
|
+
end
|
18
|
+
resources :host_classes, path: :puppetclass_ids, controller: '/foreman_puppet/api/v2/host_classes', only: %i[index create destroy]
|
19
|
+
end
|
20
|
+
|
21
|
+
resources :hostgroups, only: [] do
|
22
|
+
resources :puppetclasses, controller: '/foreman_puppet/api/v2/puppetclasses', except: %i[new edit]
|
23
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create] do
|
24
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
25
|
+
end
|
26
|
+
resources :hostgroup_classes, path: :puppetclass_ids, controller: '/foreman_puppet/api/v2/hostgroup_classes', only: %i[index create destroy]
|
27
|
+
end
|
28
|
+
|
29
|
+
resources :environments, controller: '/foreman_puppet/api/v2/environments', except: %i[new edit] do
|
30
|
+
resources :locations, only: %i[index show]
|
31
|
+
resources :organizations, only: %i[index show]
|
32
|
+
resources :smart_proxies, only: [] do
|
33
|
+
post :import_puppetclasses, on: :member
|
34
|
+
end
|
35
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create] do
|
36
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
37
|
+
end
|
38
|
+
resources :puppetclasses, controller: '/foreman_puppet/api/v2/puppetclasses', except: %i[new edit] do
|
39
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create] do
|
40
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit destroy]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
resources :hosts, only: %i[index show]
|
44
|
+
resources :template_combinations, only: %i[index show create update]
|
45
|
+
end
|
46
|
+
|
47
|
+
resources :puppetclasses, controller: '/foreman_puppet/api/v2/puppetclasses', except: %i[new edit] do
|
48
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create] do
|
49
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
50
|
+
end
|
51
|
+
resources :environments, controller: '/foreman_puppet/api/v2/environments', only: %i[index show] do
|
52
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create] do
|
53
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
resources :smart_class_parameters, controller: '/foreman_puppet/api/v2/smart_class_parameters', except: %i[new edit create destroy] do
|
59
|
+
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
60
|
+
end
|
61
|
+
|
10
62
|
resources :override_values, controller: '/foreman_puppet/api/v2/override_values', except: %i[new edit]
|
63
|
+
|
64
|
+
resources :locations, only: [] do
|
65
|
+
resources :environments, controller: '/foreman_puppet/api/v2/environments', only: %i[index show]
|
66
|
+
|
67
|
+
resources :organizations, only: [] do
|
68
|
+
resources :environments, controller: '/foreman_puppet/api/v2/environments', only: %i[index show]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
resources :organizations, only: [] do
|
73
|
+
resources :environments, controller: '/foreman_puppet/api/v2/environments', only: %i[index show]
|
74
|
+
|
75
|
+
resources :locations, only: [] do
|
76
|
+
resources :environments, controller: '/foreman_puppet/api/v2/environments', only: %i[index show]
|
77
|
+
end
|
78
|
+
end
|
11
79
|
end
|
12
80
|
end
|
13
81
|
end
|
@@ -4,6 +4,6 @@ class AddEnvironmentToTemplateCombinations < ActiveRecord::Migration[4.2]
|
|
4
4
|
end
|
5
5
|
|
6
6
|
def down
|
7
|
-
remove_reference :template_combinations, :environment, foreign_key: true
|
7
|
+
remove_reference :template_combinations, :environment, foreign_key: true
|
8
8
|
end
|
9
9
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
class MigrateEnvironmentToPuppetFacet < ActiveRecord::Migration[6.0]
|
2
2
|
def up
|
3
|
+
return true unless column_exists?(:hosts, :environment_id)
|
3
4
|
puppet_hostgroups = ::Hostgroup.unscoped.where.not(environment_id: nil).pluck(:id, :environment_id)
|
4
5
|
puppet_hostgroups.map! { |hg_id, env_id| { hostgroup_id: hg_id, environment_id: env_id } }
|
5
6
|
ForemanPuppet::HostgroupPuppetFacet.insert_all!(puppet_hostgroups) if puppet_hostgroups.any?
|
@@ -10,6 +11,7 @@ class MigrateEnvironmentToPuppetFacet < ActiveRecord::Migration[6.0]
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def down
|
14
|
+
return true unless column_exists?(:hosts, :environment_id)
|
13
15
|
hostgroup_facet_ids = ForemanPuppet::HostgroupPuppetFacet.all.pluck(:hostgroup_id, :environment_id)
|
14
16
|
hostgroup_facet_ids.each do |hostgroup_id, env_id|
|
15
17
|
::Hostgroup.unscoped.where(id: hostgroup_id).update_all(environment_id: env_id)
|
@@ -13,26 +13,8 @@ class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def up
|
16
|
-
|
17
|
-
|
18
|
-
host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(:id)
|
19
|
-
host_groups = FakeHostConfigGroup.for_host.where(host_id: host_id)
|
20
|
-
if host_facet_id
|
21
|
-
host_groups.update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
|
22
|
-
else
|
23
|
-
deleted_groups = FakeConfigGroup.where(id: host_groups.pluck(:config_group_id)).pluck(:name)
|
24
|
-
say "deleting groups #{deleted_groups.join(', ')} from Host (id=#{host_id}) because it has no environment"
|
25
|
-
host_groups.delete_all
|
26
|
-
end
|
27
|
-
end
|
28
|
-
hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
|
29
|
-
hostgroup_config_group_ids.each do |hostgroup_id|
|
30
|
-
hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(:id)
|
31
|
-
hostgroup_facet_id ||= ForemanPuppet::HostgroupPuppetFacet.create!(hostgroup: Hostgroup.unscoped.find(hostgroup_id)).id
|
32
|
-
FakeHostConfigGroup.for_hostgroup
|
33
|
-
.where(host_id: hostgroup_id)
|
34
|
-
.update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
|
35
|
-
end
|
16
|
+
migrate_host_data_to_facets
|
17
|
+
migrate_hostgroup_data_to_facets
|
36
18
|
end
|
37
19
|
|
38
20
|
def down
|
@@ -51,4 +33,38 @@ class MigrateHostTypeInHostConfigGroups < ActiveRecord::Migration[6.0]
|
|
51
33
|
.update_all(host_type: 'Hostgroup', host_id: hostgroup_facet_ids[hostgroup_facet_id])
|
52
34
|
end
|
53
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def migrate_host_data_to_facets
|
40
|
+
host_config_group_ids = FakeHostConfigGroup.for_host.pluck(:host_id).uniq
|
41
|
+
host_config_group_ids.each do |host_id|
|
42
|
+
host_facet_id = ForemanPuppet::HostPuppetFacet.where(host_id: host_id).pick(:id)
|
43
|
+
host_groups = FakeHostConfigGroup.for_host.where(host_id: host_id)
|
44
|
+
if host_facet_id
|
45
|
+
host_groups.update_all(host_type: 'ForemanPuppet::HostPuppetFacet', host_id: host_facet_id)
|
46
|
+
else
|
47
|
+
deleted_groups = FakeConfigGroup.where(id: host_groups.pluck(:config_group_id)).pluck(:name)
|
48
|
+
say "Deleting Config groups #{deleted_groups.join(', ')} from Host (id=#{host_id}) because the Host doesn't exist or has no environment"
|
49
|
+
host_groups.delete_all
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def migrate_hostgroup_data_to_facets
|
55
|
+
hostgroup_config_group_ids = FakeHostConfigGroup.for_hostgroup.pluck(:host_id).uniq
|
56
|
+
hostgroup_config_group_ids.each do |hostgroup_id|
|
57
|
+
hostgroup = Hostgroup.unscoped.find_by(id: hostgroup_id)
|
58
|
+
hostgroup_groups = FakeHostConfigGroup.for_hostgroup.where(host_id: hostgroup_id)
|
59
|
+
if hostgroup
|
60
|
+
hostgroup_facet_id = ForemanPuppet::HostgroupPuppetFacet.where(hostgroup_id: hostgroup_id).pick(:id)
|
61
|
+
hostgroup_facet_id ||= ForemanPuppet::HostgroupPuppetFacet.create!(hostgroup: hostgroup).id
|
62
|
+
hostgroup_groups.update_all(host_type: 'ForemanPuppet::HostgroupPuppetFacet', host_id: hostgroup_facet_id)
|
63
|
+
else
|
64
|
+
deleted_groups = FakeConfigGroup.where(id: hostgroup_groups.pluck(:config_group_id)).pluck(:name)
|
65
|
+
say "Deleting Config groups #{deleted_groups.join(', ')} from Hostgroup (id=#{hostgroup_id}) because Hostgroup doesn't exist"
|
66
|
+
hostgroup_groups.delete_all
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
54
70
|
end
|
@@ -33,17 +33,9 @@ class MigratePuppetclassesToFacets < ActiveRecord::Migration[6.0]
|
|
33
33
|
hostgroup_facet ||= ForemanPuppet::HostgroupPuppetFacet.create(hostgroup: Hostgroup.unscoped.find(hostgroup_id))
|
34
34
|
ForemanPuppet::HostgroupClass.where(hostgroup_id: hostgroup_id).update_all(hostgroup_puppet_facet_id: hostgroup_facet.id)
|
35
35
|
end
|
36
|
-
|
37
|
-
change_column_null(:host_classes, :host_id, true)
|
38
|
-
change_column_null(:hostgroup_classes, :hostgroup_id, true)
|
39
|
-
# remove_reference(:host_classes, :host, index: true, foreign_key: true)
|
40
|
-
# remove_reference(:hostgroup_classes, :hostgroup, index: true, foreign_key: true)
|
41
36
|
end
|
42
37
|
|
43
38
|
def down
|
44
|
-
# add_reference :host_classes, :host, foreign_key: true, index: true
|
45
|
-
# add_reference :hostgroup_classes, :hostgroup, foreign_key: true, index: true
|
46
|
-
|
47
39
|
host_facets_ids = ForemanPuppet::HostClass.joins(:host_puppet_facet).pluck(:host_puppet_facet_id, 'host_puppet_facets.host_id')
|
48
40
|
host_facets_ids.each do |host_facet_id, host_id|
|
49
41
|
ForemanPuppet::HostClass.where(host_puppet_facet_id: host_facet_id).update_all(host_id: host_id)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class DropPuppetclassesDirectReferences < ActiveRecord::Migration[6.0]
|
2
|
+
def up
|
3
|
+
remove_reference(:host_classes, :host, index: true, foreign_key: true)
|
4
|
+
remove_reference(:hostgroup_classes, :hostgroup, index: true, foreign_key: true)
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
add_reference :host_classes, :host, foreign_key: true, index: true
|
9
|
+
add_reference :hostgroup_classes, :hostgroup, foreign_key: true, index: true
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CleanupEnvironmentFromCoreTables < ActiveRecord::Migration[6.0]
|
2
|
+
def up
|
3
|
+
::Hostgroup.update_all(environment_id: nil) if column_exists?(:hostgroups, :environment_id)
|
4
|
+
Host::Managed.update_all(environment_id: nil) if column_exists?(:hosts, :environment_id)
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
# nothing to do
|
9
|
+
end
|
10
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
class CreateEnvironments < ActiveRecord::Migration[
|
1
|
+
class CreateEnvironments < ActiveRecord::Migration[4.2]
|
2
2
|
def up
|
3
3
|
create_table :environments do |t|
|
4
4
|
t.string :name, null: false, limit: 255
|
5
5
|
t.timestamps null: true
|
6
6
|
end
|
7
7
|
create_table :environments_puppetclasses do |t|
|
8
|
-
t.references :puppetclass,
|
8
|
+
t.references :puppetclass, null: false
|
9
9
|
t.references :environment, foreign_key: true
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def down
|
14
|
-
drop_table :environments
|
15
14
|
drop_table :environments_puppetclasses
|
15
|
+
drop_table :environments
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class CreatePuppetclasses < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
create_table :puppetclasses do |t|
|
4
|
+
t.string :name, limit: 255
|
5
|
+
t.string :nameindicator, limit: 255
|
6
|
+
t.integer :operatingsystem_id
|
7
|
+
|
8
|
+
t.timestamps null: true
|
9
|
+
end
|
10
|
+
add_foreign_key(:environments_puppetclasses, :puppetclasses)
|
11
|
+
|
12
|
+
create_table :hosts_puppetclasses, id: false do |t|
|
13
|
+
t.references :puppetclass, null: false
|
14
|
+
t.references :host, null: false
|
15
|
+
end
|
16
|
+
|
17
|
+
create_table :operatingsystems_puppetclasses, id: false do |t|
|
18
|
+
t.references :puppetclass, null: false
|
19
|
+
t.references :operatingsystem, null: false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def down
|
24
|
+
drop_table :operatingsystems_puppetclasses
|
25
|
+
drop_table :hosts_puppetclasses
|
26
|
+
remove_foreign_key(:environments_puppetclasses, :puppetclasses)
|
27
|
+
drop_table :puppetclasses
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateHostgroupsPuppetclasses < ActiveRecord::Migration[6.0]
|
2
|
+
def up
|
3
|
+
create_table :hostgroups_puppetclasses, id: false, if_not_exists: true do |t|
|
4
|
+
t.references :hostgroup, foreign_key: true, null: false
|
5
|
+
t.references :puppetclass, foreign_key: true, null: false
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def down
|
10
|
+
drop_table :hostgroups_puppetclasses
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateHostClass < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
rename_table :hosts_puppetclasses, :host_classes
|
4
|
+
add_column :host_classes, :id, :primary_key
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
remove_column :host_classes, :id
|
9
|
+
rename_table :host_classes, :hosts_puppetclasses
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class AddSomeIndexes < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
# puppetclasses
|
4
|
+
add_index :puppetclasses, :name
|
5
|
+
|
6
|
+
# turn off Foreign Key checks
|
7
|
+
execute 'SET CONSTRAINTS ALL DEFERRED;' if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL'
|
8
|
+
|
9
|
+
add_foreign_key 'host_classes', 'hosts', name: 'host_classes_host_id_fk'
|
10
|
+
add_foreign_key 'host_classes', 'puppetclasses', name: 'host_classes_puppetclass_id_fk'
|
11
|
+
add_foreign_key 'operatingsystems_puppetclasses', 'operatingsystems', name: 'operatingsystems_puppetclasses_operatingsystem_id_fk'
|
12
|
+
add_foreign_key 'operatingsystems_puppetclasses', 'puppetclasses', name: 'operatingsystems_puppetclasses_puppetclass_id_fk'
|
13
|
+
end
|
14
|
+
|
15
|
+
def down
|
16
|
+
remove_foreign_key 'host_classes', 'hosts', name: 'host_classes_host_id_fk'
|
17
|
+
remove_foreign_key 'host_classes', 'puppetclasses', name: 'host_classes_puppetclass_id_fk'
|
18
|
+
remove_foreign_key 'operatingsystems_puppetclasses', 'operatingsystems', name: 'operatingsystems_puppetclasses_operatingsystem_id_fk'
|
19
|
+
remove_foreign_key 'operatingsystems_puppetclasses', 'puppetclasses', name: 'operatingsystems_puppetclasses_puppetclass_id_fk'
|
20
|
+
end
|
21
|
+
end
|
@@ -8,8 +8,8 @@ class CreateEnvironmentClasses < ActiveRecord::Migration[5.0]
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def down
|
11
|
-
remove_foreign_key :environment_classes, :
|
12
|
-
|
11
|
+
remove_foreign_key :environment_classes, :lookup_keys, column: :puppetclass_lookup_key_id
|
12
|
+
remove_column :environment_classes, :puppetclass_lookup_key_id, :integer
|
13
13
|
rename_table :environment_classes, :environments_puppetclasses
|
14
14
|
end
|
15
15
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateHostgroupClasses < ActiveRecord::Migration[4.2]
|
2
|
+
def up
|
3
|
+
rename_table :hostgroups_puppetclasses, :hostgroup_classes
|
4
|
+
add_column :hostgroup_classes, :id, :primary_key
|
5
|
+
end
|
6
|
+
|
7
|
+
def down
|
8
|
+
remove_column :hostgroup_classes, :id
|
9
|
+
rename_table :hostgroup_classes, :hostgroups_puppetclasses
|
10
|
+
end
|
11
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -2,7 +2,7 @@ class DeleteOrphanedSmartClassParameters < ActiveRecord::Migration[4.2]
|
|
2
2
|
def up
|
3
3
|
condition = 'NOT EXISTS (SELECT 1 FROM environment_classes WHERE environment_classes.puppetclass_lookup_key_id = lookup_keys.id)'
|
4
4
|
LookupValue.joins(:lookup_key).where(condition).where("lookup_keys.type = 'PuppetclassLookupKey'").delete_all
|
5
|
-
|
5
|
+
LookupKey.where(condition).where(type: 'PuppetclassLookupKey').delete_all
|
6
6
|
end
|
7
7
|
|
8
8
|
def down
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class AddUniquenessToPuppetclassName < ActiveRecord::Migration[5.1]
|
2
|
+
class FakePuppetclass < ApplicationRecord
|
3
|
+
self.table_name = 'puppetclasses'
|
4
|
+
end
|
5
|
+
|
6
|
+
def up
|
7
|
+
names = FakePuppetclass.group(:name).count.select { |_key, value| value > 1 }.keys
|
8
|
+
unless names.empty?
|
9
|
+
names.each do |name|
|
10
|
+
classes = FakePuppetclass.where name: name
|
11
|
+
say "#{classes.count} Puppet classes with duplicate name detected: #{name}"
|
12
|
+
end
|
13
|
+
raise 'Please make sure there are no duplicate Puppet classes before continuing.'
|
14
|
+
end
|
15
|
+
|
16
|
+
remove_index :puppetclasses, :name
|
17
|
+
add_index :puppetclasses, :name, unique: true
|
18
|
+
end
|
19
|
+
|
20
|
+
def down
|
21
|
+
remove_index :puppetclasses, :name
|
22
|
+
add_index :puppetclasses, :name
|
23
|
+
end
|
24
|
+
end
|
@@ -2,6 +2,6 @@
|
|
2
2
|
class AddEnvironmentPuppetclassId < ActiveRecord::Migration[5.2]
|
3
3
|
def change
|
4
4
|
add_index :environment_classes, %i[environment_id puppetclass_id]
|
5
|
-
remove_index :environment_classes, :environment_id
|
5
|
+
remove_index(:environment_classes, :environment_id) if index_exists?(:environment_classes, :environment_id)
|
6
6
|
end
|
7
7
|
end
|
File without changes
|
@@ -1,38 +1,9 @@
|
|
1
1
|
module ForemanPuppet
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
-
config.before_configuration do
|
4
|
-
unless ForemanPuppet.extracted_from_core?
|
5
|
-
require 'graphql'
|
6
|
-
|
7
|
-
module BaseObjectClassMethodPath
|
8
|
-
def field(*args, **kwargs, &block)
|
9
|
-
return if args.first == :environment && args.second.to_s == 'Types::Environment'
|
10
|
-
return if args.first == :environments && args.second.node_type.to_s == 'Types::Environment'
|
11
|
-
return if args.first == :puppetclass && args.second.to_s == 'Types::Puppetclass'
|
12
|
-
return if args.first == :puppetclasses && args.second.node_type.to_s == 'Types::Puppetclass'
|
13
|
-
|
14
|
-
super
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
module RelayClassicMutationClassMethodPath
|
19
|
-
# rubocop:disable Metrics/ParameterLists
|
20
|
-
def argument(name, type, *rest, loads: nil, **kwargs, &block)
|
21
|
-
# rubocop:enable Metrics/ParameterLists
|
22
|
-
return if [::Types::Environment, ::Types::Puppetclass].include?(loads)
|
23
|
-
|
24
|
-
super
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
GraphQL::Types::Relay::BaseObject.extend(BaseObjectClassMethodPath)
|
29
|
-
GraphQL::Schema::RelayClassicMutation.extend(RelayClassicMutationClassMethodPath)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
3
|
engine_name 'foreman_puppet'
|
34
4
|
isolate_namespace ForemanPuppet
|
35
5
|
|
6
|
+
config.paths['db/migrate'] << 'db/migrate_foreman' if Gem::Dependency.new('', ">= #{ForemanPuppet::FOREMAN_DROP_MIGRATIONS_VERSION}").match?('', SETTINGS[:version].notag)
|
36
7
|
config.paths['config/routes.rb'].unshift('config/api_routes.rb')
|
37
8
|
|
38
9
|
initializer 'foreman_puppet.register_plugin', before: :finisher_hook do |_app|
|
@@ -79,6 +50,8 @@ module ForemanPuppet
|
|
79
50
|
::TemplateCombination.include ForemanPuppet::Extensions::TemplateCombination
|
80
51
|
::ProvisioningTemplate.include ForemanPuppet::Extensions::ProvisioningTemplate
|
81
52
|
|
53
|
+
::HostCounter.prepend ForemanPuppet::Extensions::HostCounter
|
54
|
+
|
82
55
|
::Api::V2::BaseController.include ForemanPuppet::Extensions::ApiBaseController
|
83
56
|
::Api::V2::HostsController.include ForemanPuppet::Extensions::ApiV2HostsController
|
84
57
|
::Api::V2::HostgroupsController.include ForemanPuppet::Extensions::ApiHostgroupsController
|
@@ -93,15 +66,12 @@ module ForemanPuppet
|
|
93
66
|
|
94
67
|
::SmartProxiesHelper::TABBED_FEATURES << 'Puppet'
|
95
68
|
|
96
|
-
unless ForemanPuppet.extracted_from_core?
|
97
|
-
::HostInfo.local_entries.delete('HostInfoProviders::PuppetInfo'.safe_constantize)
|
98
|
-
::HostInfo.local_entries.delete('HostInfoProviders::ConfigGroupsInfo'.safe_constantize)
|
99
|
-
::ProxyStatus.status_registry.delete('ProxyStatus::Puppet'.safe_constantize)
|
100
|
-
Foreman.input_types_registry.input_types.delete('puppet_parameter')
|
101
|
-
end
|
102
69
|
Foreman.input_types_registry.register(ForemanPuppet::InputType::PuppetParameterInput)
|
103
70
|
::ProxyStatus.status_registry.add(ForemanPuppet::ProxyStatus::Puppet)
|
104
71
|
|
72
|
+
# Extend smart_proxies API functionality
|
73
|
+
::Api::V2::SmartProxiesController.include ForemanPuppet::Extensions::ApiSmartProxiesController
|
74
|
+
|
105
75
|
# GraphQL
|
106
76
|
::Types::Host.include(ForemanPuppet::Types::HostExtensions)
|
107
77
|
::Types::Hostgroup.include(ForemanPuppet::Types::HostgroupExtensions)
|