foreman_discovery 22.0.2 → 23.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/foreman_discovery/locale/ca/foreman_discovery.js +847 -0
  3. data/app/assets/javascripts/foreman_discovery/locale/cs_CZ/foreman_discovery.js +847 -0
  4. data/app/assets/javascripts/foreman_discovery/locale/de/foreman_discovery.js +847 -0
  5. data/app/assets/javascripts/foreman_discovery/locale/en/foreman_discovery.js +846 -0
  6. data/app/assets/javascripts/foreman_discovery/locale/en_GB/foreman_discovery.js +847 -0
  7. data/app/assets/javascripts/foreman_discovery/locale/es/foreman_discovery.js +850 -0
  8. data/app/assets/javascripts/foreman_discovery/locale/fr/foreman_discovery.js +850 -0
  9. data/app/assets/javascripts/foreman_discovery/locale/gl/foreman_discovery.js +847 -0
  10. data/app/assets/javascripts/foreman_discovery/locale/it/foreman_discovery.js +847 -0
  11. data/app/assets/javascripts/foreman_discovery/locale/ja/foreman_discovery.js +844 -0
  12. data/app/assets/javascripts/foreman_discovery/locale/ka/foreman_discovery.js +847 -0
  13. data/app/assets/javascripts/foreman_discovery/locale/ko/foreman_discovery.js +847 -0
  14. data/app/assets/javascripts/foreman_discovery/locale/pt_BR/foreman_discovery.js +850 -0
  15. data/app/assets/javascripts/foreman_discovery/locale/ru/foreman_discovery.js +851 -0
  16. data/app/assets/javascripts/foreman_discovery/locale/sv_SE/foreman_discovery.js +847 -0
  17. data/app/assets/javascripts/foreman_discovery/locale/zh_CN/foreman_discovery.js +844 -0
  18. data/app/assets/javascripts/foreman_discovery/locale/zh_TW/foreman_discovery.js +847 -0
  19. data/app/controllers/discovered_hosts_controller.rb +5 -1
  20. data/app/helpers/discovered_hosts_helper.rb +9 -2
  21. data/app/models/host/discovered.rb +3 -3
  22. data/app/services/foreman_discovery/import_hooks/lock_templates.rb +1 -1
  23. data/app/services/foreman_discovery/node_api/node_resource.rb +5 -5
  24. data/app/services/foreman_discovery/ui_notifications/failed_discovery.rb +1 -1
  25. data/app/views/discovered_hosts/_discovered_host.html.erb +1 -1
  26. data/app/views/discovered_hosts/_discovered_hosts_list.html.erb +1 -1
  27. data/db/migrate/20221102065954_fix_discovery_settings_category_to_dsl.rb +1 -1
  28. data/db/migrate/20221102075151_migrate_discovery_hostname_and_fact_column_to_array.rb +13 -0
  29. data/extra/discover-host +1 -1
  30. data/lib/foreman_discovery/engine.rb +8 -20
  31. data/lib/foreman_discovery/version.rb +1 -1
  32. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  33. data/locale/ca/foreman_discovery.edit.po +1122 -0
  34. data/locale/ca/foreman_discovery.po +22 -10
  35. data/locale/cs_CZ/LC_MESSAGES/foreman_discovery.mo +0 -0
  36. data/locale/cs_CZ/foreman_discovery.edit.po +1120 -0
  37. data/locale/cs_CZ/foreman_discovery.po +846 -0
  38. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  39. data/locale/de/foreman_discovery.edit.po +1129 -0
  40. data/locale/de/foreman_discovery.po +22 -10
  41. data/locale/en/LC_MESSAGES/foreman_discovery.mo +0 -0
  42. data/locale/en/foreman_discovery.edit.po +1115 -0
  43. data/locale/en/foreman_discovery.po +19 -7
  44. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  45. data/locale/en_GB/foreman_discovery.edit.po +1125 -0
  46. data/locale/en_GB/foreman_discovery.po +22 -10
  47. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  48. data/locale/es/foreman_discovery.edit.po +1130 -0
  49. data/locale/es/foreman_discovery.po +81 -65
  50. data/locale/foreman_discovery.pot +231 -211
  51. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  52. data/locale/fr/foreman_discovery.edit.po +1126 -0
  53. data/locale/fr/foreman_discovery.po +35 -19
  54. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  55. data/locale/gl/foreman_discovery.edit.po +1120 -0
  56. data/locale/gl/foreman_discovery.po +19 -7
  57. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  58. data/locale/it/foreman_discovery.edit.po +1123 -0
  59. data/locale/it/foreman_discovery.po +21 -8
  60. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  61. data/locale/ja/foreman_discovery.edit.po +1119 -0
  62. data/locale/ja/foreman_discovery.po +34 -22
  63. data/locale/ka/LC_MESSAGES/foreman_discovery.mo +0 -0
  64. data/locale/ka/foreman_discovery.edit.po +1120 -0
  65. data/locale/ka/foreman_discovery.po +846 -0
  66. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  67. data/locale/ko/foreman_discovery.edit.po +1119 -0
  68. data/locale/ko/foreman_discovery.po +20 -8
  69. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  70. data/locale/pt_BR/foreman_discovery.edit.po +1132 -0
  71. data/locale/pt_BR/foreman_discovery.po +61 -45
  72. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  73. data/locale/ru/foreman_discovery.edit.po +1131 -0
  74. data/locale/ru/foreman_discovery.po +21 -9
  75. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  76. data/locale/sv_SE/foreman_discovery.edit.po +1123 -0
  77. data/locale/sv_SE/foreman_discovery.po +19 -7
  78. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  79. data/locale/zh_CN/foreman_discovery.edit.po +1117 -0
  80. data/locale/zh_CN/foreman_discovery.po +31 -19
  81. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  82. data/locale/zh_TW/foreman_discovery.edit.po +1120 -0
  83. data/locale/zh_TW/foreman_discovery.po +19 -7
  84. data/package.json +0 -1
  85. data/test/functional/api/v2/fact_value_extensions_test.rb +1 -1
  86. data/test/functional/discovered_hosts_controller_test.rb +1 -1
  87. data/test/migrations/20221102075151_migrate_discovery_hostname_and_fact_column_to_array_test.rb +75 -0
  88. data/test/migrations/20221102075151_migrate_discovery_hostname_and_fact_column_to_array_test.rb.orig +81 -0
  89. data/test/test_helper_discovery.rb +1 -1
  90. data/test/unit/discovery_attribute_set_test.rb +1 -1
  91. data/test/unit/host_discovered_test.rb +3 -3
  92. data/webpack/src/ForemanDiscovery/DiscoveryRules/Components/EmptyState/EmptyState.js +1 -1
  93. metadata +50 -8
  94. data/app/models/setting/discovered.rb +0 -22
@@ -35,7 +35,7 @@ class DiscoveredHostsController < ::ApplicationController
35
35
  :discovery_attribute_set
36
36
  ], {:interfaces => :subnet})
37
37
  fact_array = @hosts.collect do |host|
38
- [host.id, Hash[host.fact_values.joins(:fact_name).where('fact_names.name' => Setting::Discovered.discovery_fact_column_array).pluck(:name, :value)]]
38
+ [host.id, Hash[host.fact_values.joins(:fact_name).where('fact_names.name' => Setting['discovery_fact_column']).pluck(:name, :value)]]
39
39
  end
40
40
  @host_facts = Hash[fact_array]
41
41
  end
@@ -198,6 +198,10 @@ class DiscoveredHostsController < ::ApplicationController
198
198
  end
199
199
  end
200
200
 
201
+ def resource_class
202
+ Host::Discovered
203
+ end
204
+
201
205
  private
202
206
 
203
207
  def setup_host_class_variables
@@ -94,8 +94,15 @@ module DiscoveredHostsHelper
94
94
  end
95
95
 
96
96
  def host_path(host)
97
- return super unless controller_name == 'discovered_hosts'
98
- discovered_host_path(host)
97
+ return discovered_host_path(host) if controller_name == 'discovered_hosts'
98
+ # This is a hack to fix the hostgroup selection on the discovered host edit page
99
+ # The hostgroup onChange action is replacing the form url from `/discovered_hosts/:id`
100
+ # to `/hosts/:id``, which is not correct (in this case) and it breaks the form submission
101
+ return discovered_host_path(host) if controller_name == 'hosts' &&
102
+ action_name == 'process_hostgroup' &&
103
+ Host::Discovered.find_by(id: host[:id])
104
+
105
+ super
99
106
  end
100
107
 
101
108
  def discovery_doc_version
@@ -63,15 +63,15 @@ class Host::Discovered < ::Host::Base
63
63
  bootif_mac = FacterUtils::bootif_mac(facts).try(:downcase)
64
64
  hostname = ''
65
65
  if Setting[:discovery_naming] == 'MAC-name'
66
- hostname_mac = return_first_valid_mac(Setting::Discovered.discovery_hostname_fact_array, facts) || bootif_mac
66
+ hostname_mac = return_first_valid_mac(Setting['discovery_hostname'], facts) || bootif_mac
67
67
  hostname = NameGenerator.new.generate_next_mac_name(hostname_mac)
68
68
  elsif Setting[:discovery_naming] == 'Random-name'
69
69
  hostname = NameGenerator.new.generate_next_random_name
70
70
  else
71
71
  prefix_from_settings = Setting[:discovery_prefix]
72
72
  hostname_prefix = prefix_from_settings if prefix_from_settings.present? && prefix_from_settings.match(/^[a-zA-Z].*/)
73
- name_fact = return_first_valid_fact(Setting::Discovered.discovery_hostname_fact_array, facts)
74
- raise(::Foreman::Exception.new(N_("Invalid facts: hash does not contain a valid value for any of the facts in the discovery_hostname setting: %s"), Setting::Discovered.discovery_hostname_fact_array.join(', '))) unless name_fact && name_fact.present?
73
+ name_fact = return_first_valid_fact(Setting['discovery_hostname'], facts)
74
+ raise(::Foreman::Exception.new(N_("Invalid facts: hash does not contain a valid value for any of the facts in the discovery_hostname setting: %s"), Setting['discovery_hostname'].join(', '))) unless name_fact && name_fact.present?
75
75
  hostname = normalize_string_for_hostname("#{hostname_prefix}#{name_fact}")
76
76
  end
77
77
  Rails.logger.warn "Hostname does not start with an alphabetical character" unless hostname.downcase.match(/^[a-z]/)
@@ -3,7 +3,7 @@ module ForemanDiscovery
3
3
  module ImportHooks
4
4
  class LockTemplates < ImportHook
5
5
  def after_populate
6
- lock_templates if Setting::Discovered.discovery_lock? && host.subnet.tftp?
6
+ lock_templates if Setting['discovery_lock'] && host.subnet.tftp?
7
7
  end
8
8
 
9
9
  def lock_templates
@@ -1,8 +1,8 @@
1
1
  module ForemanDiscovery::NodeAPI
2
2
  class NodeResource
3
3
  def initialize(args)
4
- raise ArgumentError, "Options must be hash" unless args.is_a?(Hash)
5
- raise ArgumentError, "Option 'url' must be provided" unless args[:url]
4
+ raise ArgumentError, _("Options must be hash") unless args.is_a?(Hash)
5
+ raise ArgumentError, _("Option 'url' must be provided") unless args[:url]
6
6
  @args = args
7
7
  @connect_params = {
8
8
  :headers => { :accept => :json },
@@ -38,19 +38,19 @@ module ForemanDiscovery::NodeAPI
38
38
  def scheme
39
39
  URI.parse(url).scheme
40
40
  rescue Exception => e
41
- raise ArgumentError, "Option 'url' must be valid URI: #{e}"
41
+ raise ArgumentError, _("Option 'url' must be valid URI: %s") % e
42
42
  end
43
43
 
44
44
  def port
45
45
  URI.parse(url).port
46
46
  rescue Exception => e
47
- raise ArgumentError, "Option 'url' must be valid URI: #{e}"
47
+ raise ArgumentError, _("Option 'url' must be valid URI: %s") % e
48
48
  end
49
49
 
50
50
  def root_path
51
51
  URI.parse(url).path
52
52
  rescue Exception => e
53
- raise ArgumentError, "Option 'url' must be valid URI: #{e}"
53
+ raise ArgumentError, _("Option 'url' must be valid URI: %s") % e
54
54
  end
55
55
 
56
56
  def is_proxy?
@@ -21,7 +21,7 @@ module ForemanDiscovery
21
21
  Notification.create!(
22
22
  initiator: initiator,
23
23
  audience: ::Notification::AUDIENCE_ADMIN,
24
- message: _("One or more hosts with failed discovery due to error: #{@message}"),
24
+ message: _("One or more hosts with failed discovery due to error: %s") % @message,
25
25
  notification_blueprint: blueprint,
26
26
  )
27
27
  end
@@ -6,7 +6,7 @@
6
6
  <td class="hidden-tablet hidden-xs"><%= discovery_attribute(host, :disk_count) %></td>
7
7
  <td class="hidden-tablet hidden-xs"><%= number_to_human_size(discovery_attribute(host, :disks_size, 0) * 1024 * 1024) %></td>
8
8
  <%
9
- Setting::Discovered.discovery_fact_column_array.each do |name|
9
+ Setting['discovery_fact_column'].each do |name|
10
10
  %>
11
11
  <td class="hidden-tablet hidden-xs"><%= @host_facts[host.id][name] || 'N/A' %></td>
12
12
  <% end %>
@@ -10,7 +10,7 @@
10
10
  <th class="hidden-tablet hidden-xs"><%= sort :memory, :as => _('Memory') %></th>
11
11
  <th class="hidden-tablet hidden-xs"><%= sort :disk_count, :as => _('Disk Count') %></th>
12
12
  <th class="hidden-tablet hidden-xs"><%= sort :disks_size, :as => _('Disks Size') %></th>
13
- <% Setting::Discovered.discovery_fact_column_array.each do |fact_column| %>
13
+ <% Setting['discovery_fact_column'].each do |fact_column| %>
14
14
  <th class="hidden-tablet hidden-xs"><%= fact_column.capitalize %></th>
15
15
  <% end %>
16
16
  <th class="hidden-tablet hidden-xs"><%= sort :location, :as => _('Location') %></th>
@@ -3,7 +3,7 @@
3
3
  class FixDiscoverySettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4
4
  def up
5
5
  # rubocop:disable Rails/SkipsModelValidations
6
- Setting.where(category: 'Setting::Discovered').update_all(category: 'Setting')
6
+ Setting.where(category: 'Setting::Discovered').update_all(category: 'Setting') if column_exists?(:settings, :category)
7
7
  # rubocop:enable Rails/SkipsModelValidations
8
8
  end
9
9
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class MigrateDiscoveryHostnameAndFactColumnToArray < ActiveRecord::Migration[6.0]
4
+ def up
5
+ ['discovery_hostname', 'discovery_fact_column'].each do |setting_name|
6
+ setting = Setting.find_by(name: setting_name)
7
+ if !setting.nil? && setting.value.is_a?(String)
8
+ setting.value = setting.value.split(",").map(&:strip)
9
+ setting.save
10
+ end
11
+ end
12
+ end
13
+ end
data/extra/discover-host CHANGED
@@ -6,7 +6,7 @@ require 'rest-client'
6
6
  def find_base name = "default"
7
7
  return name if File.exist?(name)
8
8
 
9
- file = File.absolute_path(File.dirname(__FILE__) + "../../test/facts/#{name}.json")
9
+ file = File.absolute_path(File.dirname(__FILE__) + "/../test/facts/#{name}.json")
10
10
  raise "Unable to find file #{file}" unless File.exist?(file)
11
11
 
12
12
  file
@@ -15,25 +15,12 @@ module ForemanDiscovery
15
15
  config.autoload_paths += Dir["#{config.root}/app/models/concerns"]
16
16
  config.autoload_paths += Dir["#{config.root}/app/services"]
17
17
 
18
- # Load this before the Foreman config initializers, so that the Setting.descendants
19
- # list includes the plugin STI setting class
20
- initializer 'foreman_discovery.load_default_settings', :before => :load_config_initializers do |app|
21
- require_dependency File.expand_path("../../../app/models/setting/discovered.rb", __FILE__) if (Setting.table_exists? rescue(false))
22
- end
23
-
24
18
  initializer "foreman_discovery.add_rabl_view_path" do |app|
25
19
  Rabl.configure do |config|
26
20
  config.view_paths << ForemanDiscovery::Engine.root.join('app', 'views')
27
21
  end
28
22
  end
29
23
 
30
- initializer 'foreman_discovery.register_gettext', :after => :load_config_initializers do |app|
31
- locale_dir = File.join(File.expand_path('../../..', __FILE__), 'locale')
32
- locale_domain = 'foreman_discovery'
33
-
34
- Foreman::Gettext::Support.add_text_domain locale_domain, locale_dir
35
- end
36
-
37
24
  # Add any db migrations
38
25
  initializer "foreman_discovery.load_app_instance_data" do |app|
39
26
  ForemanDiscovery::Engine.paths['db/migrate'].existent.each do |path|
@@ -43,7 +30,8 @@ module ForemanDiscovery
43
30
 
44
31
  initializer 'foreman_discovery.register_plugin', :before => :finisher_hook do |app|
45
32
  Foreman::Plugin.register :foreman_discovery do
46
- requires_foreman '>= 3.3'
33
+ requires_foreman '>= 3.8'
34
+ register_gettext
47
35
 
48
36
  # settings
49
37
  settings do
@@ -85,10 +73,10 @@ module ForemanDiscovery
85
73
  description: N_("Clean all reported facts during provisioning (except discovery facts)")
86
74
 
87
75
  setting "discovery_hostname",
88
- type: :string,
89
- default: "discovery_bootif",
76
+ type: :array,
77
+ default: ["discovery_bootif"],
90
78
  full_name: N_("Hostname facts"),
91
- description: N_("List of facts to use for the hostname (separated by comma, first wins)")
79
+ description: N_("List of facts to use for the hostname (first wins)")
92
80
 
93
81
  validates "discovery_hostname", presence: true
94
82
 
@@ -113,10 +101,10 @@ module ForemanDiscovery
113
101
  validates "discovery_prefix", presence: true
114
102
 
115
103
  setting "discovery_fact_column",
116
- type: :string,
117
- default: "",
104
+ type: :array,
105
+ default: [],
118
106
  full_name: N_("Fact columns"),
119
- description: N_("Extra facter columns to show in host lists (separate by comma)")
107
+ description: N_("Extra facter columns to show in host lists")
120
108
 
121
109
  setting "discovery_facts_highlights",
122
110
  type: :string,
@@ -1,3 +1,3 @@
1
1
  module ForemanDiscovery
2
- VERSION = "22.0.2"
2
+ VERSION = "23.0.0"
3
3
  end