foreman_discovery 13.0.1 → 14.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/foreman/controller/discovered_extensions.rb +3 -1
  3. data/app/models/host/discovered.rb +8 -78
  4. data/app/models/host/managed_extensions.rb +3 -3
  5. data/app/models/nic/managed_extensions.rb +1 -1
  6. data/app/services/foreman_discovery/import_hook.rb +12 -0
  7. data/app/services/foreman_discovery/import_hook_service.rb +24 -0
  8. data/app/services/foreman_discovery/import_hooks/discovery_attribute.rb +33 -0
  9. data/app/services/foreman_discovery/import_hooks/lldp_neighbor.rb +11 -0
  10. data/app/services/foreman_discovery/import_hooks/lock_templates.rb +27 -0
  11. data/app/services/foreman_discovery/import_hooks/subnet_and_taxonomy.rb +63 -0
  12. data/app/views/discovered_hosts/_discovered_hosts_list.html.erb +1 -1
  13. data/app/views/foreman_discovery/debian_kexec.erb +4 -3
  14. data/app/views/foreman_discovery/redhat_kexec.erb +4 -2
  15. data/db/migrate/20141223142759_fill_discovery_attribute_sets_for_existing_hosts.rb +1 -2
  16. data/db/seeds.d/50_discovery_templates.rb +9 -2
  17. data/extra/discover-host +1 -1
  18. data/lib/foreman_discovery/engine.rb +1 -1
  19. data/lib/foreman_discovery/version.rb +1 -1
  20. data/locale/ca/LC_MESSAGES/foreman_discovery.mo +0 -0
  21. data/locale/ca/foreman_discovery.edit.po +100 -61
  22. data/locale/ca/foreman_discovery.po +31 -4
  23. data/locale/de/LC_MESSAGES/foreman_discovery.mo +0 -0
  24. data/locale/de/foreman_discovery.edit.po +111 -71
  25. data/locale/de/foreman_discovery.po +41 -13
  26. data/locale/en/foreman_discovery.edit.po +21 -17
  27. data/locale/en/foreman_discovery.po +3 -0
  28. data/locale/en_GB/LC_MESSAGES/foreman_discovery.mo +0 -0
  29. data/locale/en_GB/foreman_discovery.edit.po +101 -62
  30. data/locale/en_GB/foreman_discovery.po +31 -4
  31. data/locale/es/LC_MESSAGES/foreman_discovery.mo +0 -0
  32. data/locale/es/foreman_discovery.edit.po +102 -63
  33. data/locale/es/foreman_discovery.po +32 -5
  34. data/locale/foreman_discovery.pot +24 -19
  35. data/locale/fr/LC_MESSAGES/foreman_discovery.mo +0 -0
  36. data/locale/fr/foreman_discovery.edit.po +102 -63
  37. data/locale/fr/foreman_discovery.po +32 -5
  38. data/locale/gl/LC_MESSAGES/foreman_discovery.mo +0 -0
  39. data/locale/gl/foreman_discovery.edit.po +100 -61
  40. data/locale/gl/foreman_discovery.po +31 -4
  41. data/locale/it/LC_MESSAGES/foreman_discovery.mo +0 -0
  42. data/locale/it/foreman_discovery.edit.po +102 -63
  43. data/locale/it/foreman_discovery.po +32 -5
  44. data/locale/ja/LC_MESSAGES/foreman_discovery.mo +0 -0
  45. data/locale/ja/foreman_discovery.edit.po +102 -63
  46. data/locale/ja/foreman_discovery.po +32 -5
  47. data/locale/ko/LC_MESSAGES/foreman_discovery.mo +0 -0
  48. data/locale/ko/foreman_discovery.edit.po +101 -62
  49. data/locale/ko/foreman_discovery.po +31 -4
  50. data/locale/pt_BR/LC_MESSAGES/foreman_discovery.mo +0 -0
  51. data/locale/pt_BR/foreman_discovery.edit.po +102 -63
  52. data/locale/pt_BR/foreman_discovery.po +32 -5
  53. data/locale/ru/LC_MESSAGES/foreman_discovery.mo +0 -0
  54. data/locale/ru/foreman_discovery.edit.po +102 -63
  55. data/locale/ru/foreman_discovery.po +32 -5
  56. data/locale/sv_SE/LC_MESSAGES/foreman_discovery.mo +0 -0
  57. data/locale/sv_SE/foreman_discovery.edit.po +101 -62
  58. data/locale/sv_SE/foreman_discovery.po +32 -5
  59. data/locale/zh_CN/LC_MESSAGES/foreman_discovery.mo +0 -0
  60. data/locale/zh_CN/foreman_discovery.edit.po +101 -62
  61. data/locale/zh_CN/foreman_discovery.po +31 -4
  62. data/locale/zh_TW/LC_MESSAGES/foreman_discovery.mo +0 -0
  63. data/locale/zh_TW/foreman_discovery.edit.po +102 -63
  64. data/locale/zh_TW/foreman_discovery.po +32 -5
  65. data/test/factories/discovery_host_related.rb +1 -1
  66. data/test/factories/discovery_rule_related.rb +4 -4
  67. data/{extra/discovery → test/facts}/default.json +0 -0
  68. data/{extra/discovery/many_ems.json → test/facts/dell_npars.json} +5 -7
  69. data/test/facts/dell_vlan.json +328 -0
  70. data/test/{unit → facts}/facts_with_lldp.json +0 -0
  71. data/test/{unit → facts}/facts_with_lldp_bond_candidate.json +0 -0
  72. data/test/facts/puppet3-virtual.json +109 -0
  73. data/{extra/discovery → test/facts}/pxeless-vlan.json +0 -0
  74. data/test/{unit/facts.json → facts/regular_host.json} +0 -0
  75. data/{extra/discovery → test/facts}/rhel-dl380-1kdisks.json +0 -0
  76. data/{extra/discovery → test/facts}/rhel-r730.json +0 -0
  77. data/{extra/discovery → test/facts}/rhel7-vlan.json +0 -0
  78. data/{extra/discovery → test/facts}/simple-bond.json +0 -0
  79. data/{extra/discovery → test/facts}/suse-vmware.json +0 -0
  80. data/test/facts/vmware_local.json +226 -0
  81. data/test/functional/api/v2/discovered_hosts_controller_test.rb +1 -1
  82. data/test/functional/api/v2/discovery_rules_controller_test.rb +1 -1
  83. data/test/functional/api/v2/fact_value_extensions_test.rb +1 -1
  84. data/test/functional/api/v2/settings_controller_test.rb +1 -1
  85. data/test/functional/discovered_hosts_controller_test.rb +3 -2
  86. data/test/functional/discovery_rules_controller_test.rb +3 -2
  87. data/test/functional/foreman_discovery/concerns/hosts_controller_extensions_test.rb +1 -1
  88. data/test/integration/discovered_hosts_test.rb +1 -1
  89. data/test/models/setting_test.rb +1 -1
  90. data/test/test_helper_discovery.rb +6 -2
  91. data/test/test_plugin_helper.rb +2 -3
  92. data/test/unit/discovered_extensions_test.rb +7 -3
  93. data/test/unit/discovered_mailer_test.rb +1 -1
  94. data/test/unit/discovery_attribute_set_test.rb +2 -6
  95. data/test/unit/discovery_rule_test.rb +1 -1
  96. data/test/unit/discovery_taxonomy_extensions_test.rb +5 -6
  97. data/test/unit/fact_parser_test.rb +1 -1
  98. data/test/unit/host_discovered_test.rb +36 -36
  99. data/test/unit/lldp_neighbors_test.rb +3 -7
  100. data/test/unit/managed_extensions_test.rb +4 -7
  101. data/test/unit/setting_discovered_test.rb +1 -1
  102. data/test/unit/ui_notifications/destroy_host_test.rb +1 -5
  103. data/test/unit/ui_notifications/new_host_test.rb +2 -6
  104. metadata +38 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ffdab95d6a69414a0b99ecdb838f4c9d4c2ee9f9eba3d71ba2a5bb3fe3ef3d0
4
- data.tar.gz: 5e721d701c1d35f93dcec4f096b41cfcb08ea605bd46aa37a538349c61c2985d
3
+ metadata.gz: 49c30c64f46b94cdebd54bcc42191a28d4657b5cac08b9b85b55e033193f3e30
4
+ data.tar.gz: 578f6f1feecbea23a712a13e5e4ece7df31a1e1fa3ec89dc0224df9472e4999b
5
5
  SHA512:
6
- metadata.gz: bac34ddb73174715645508c038e8d1951840374b8b32b0c8073f424522c0ff322645cc5dde847914cc2861f9363f8ad64aa943c9a48f04b947c37c633c48afb3
7
- data.tar.gz: 37e531b52508c10f32617eae2af3beb893c9eee65698dbad324af1bb77212ca4659ab1a71b35f77b57ddaca3825f10fde2f452b6bf1e87fd6b0628616d4e00fb
6
+ metadata.gz: 77d0a31672abf4bb351b0296c2fe2ac418b746fddefb7f3a9e8a2f58c7dd5d90ecaddf23cf35e2884ec49e187894abae9028e35b819ca83f31925adeb4ab18eb
7
+ data.tar.gz: a5703c3c800bad9be03d9110dbc4ab831c849e8ba31fa2ae4667b70e4013a5e923b1c170be7b8a0fa5d55499cec8265bcd7d71740e4cae4bb375226631c49127
@@ -51,7 +51,9 @@ module Foreman::Controller::DiscoveredExtensions
51
51
  host.discovery_rule = rule
52
52
  # render hostname only when all other fields are set
53
53
  original_name = host.name
54
- host.name = host.render_template(rule.hostname) unless rule.hostname.empty?
54
+ source = Foreman::Renderer::Source::String.new(name: 'Hostname template', content: rule.hostname)
55
+ scope = Foreman::Renderer.get_scope(host: host, source: source)
56
+ host.name = Foreman::Renderer.render(source, scope)
55
57
  # fallback to the original if template did not expand
56
58
  host.name = original_name if host.name.empty?
57
59
  # explicitly set all inheritable attributes from hostgroup
@@ -5,7 +5,6 @@ class Host::Discovered < ::Host::Base
5
5
  has_many :audits, -> { where(:auditable_type => 'Host::Base') }, :foreign_key => :auditable_id, :class_name => 'Audited::Audit'
6
6
 
7
7
  include ScopedSearchExtensions
8
- include Foreman::Renderer
9
8
  include BelongsToProxies
10
9
  include ::Hostext::OperatingSystem
11
10
 
@@ -107,7 +106,7 @@ class Host::Discovered < ::Host::Base
107
106
  # record the last time it sent facts...
108
107
  self.last_report = Time.now
109
108
  # Set the correct facts type for new foreman facts importing code.
110
- facts[:_type] = :foreman_discovery if SETTINGS[:version].short > '1.16'
109
+ facts[:_type] = :foreman_discovery
111
110
  super(facts)
112
111
  end
113
112
 
@@ -121,93 +120,24 @@ class Host::Discovered < ::Host::Base
121
120
  super
122
121
  end
123
122
 
124
- def populate_fields_from_facts(*params)
125
- if SETTINGS[:version].short > '1.16'
126
- parser, type, source_proxy = params
127
- facts = parser.facts
128
- # detect interfaces and primary interface using extensions
129
- super(parser, type, source_proxy)
130
- else
131
- # backwards compatibility
132
- facts = params[0] || self.facts_hash
133
- parser = super(facts, :foreman_discovery)
134
- end
123
+ def populate_fields_from_facts(parser, type, source_proxy)
124
+ facts = parser.facts
125
+
126
+ # detect interfaces and primary interface using extensions
127
+ super(parser, type, source_proxy)
135
128
 
136
129
  populate_discovery_fields_from_facts(facts)
137
130
  create_notification
138
131
  parser
139
132
  end
140
133
 
134
+ # set additional discovery attributes
141
135
  def populate_discovery_fields_from_facts(facts)
142
- # set discovery search attributes first
143
- self.discovery_attribute_set = DiscoveryAttributeSet.where(:host_id => id).first_or_create
144
- self.discovery_attribute_set.update_attributes(import_from_facts)
145
- # set additional discovery attributes
146
- ::ForemanDiscovery::LldpNeighbors.eventually_make_bond(self) if Setting[:discovery_auto_bond]
147
- primary_ip = self.primary_interface.ip
148
- unless primary_ip.nil?
149
- subnet = Subnet.subnet_for(primary_ip)
150
- if subnet
151
- Rails.logger.info "Detected subnet: #{subnet} with taxonomy #{subnet.organizations.collect(&:name)}/#{subnet.locations.collect(&:name)}"
152
- else
153
- Rails.logger.warn "Subnet could not be detected for #{primary_ip}"
154
- end
155
- # set subnet
156
- self.primary_interface.subnet = subnet
157
- # set location and organization
158
- if SETTINGS[:locations_enabled]
159
- self.location = Location.find_by_title(facts["foreman_location"] || facts["discovery_location"]) ||
160
- Location.find_by_title(Setting[:discovery_location]) ||
161
- subnet.try(:locations).try(:first) ||
162
- Location.first
163
- Rails.logger.info "Assigned location: #{self.location}"
164
- end
165
- if SETTINGS[:organizations_enabled]
166
- self.organization = Organization.find_by_title(facts["foreman_organization"] || facts["discovery_organization"]) ||
167
- Organization.find_by_title(Setting[:discovery_organization]) ||
168
- subnet.try(:organizations).try(:first) ||
169
- Organization.first
170
- Rails.logger.info "Assigned organization: #{self.organization}"
171
- end
172
- else
173
- Rails.logger.warn "Unable to assign subnet - reboot trigger may not be possible, primary interface is missing IP address"
174
- end
175
-
176
- # lock the host into discovery via PXE, if feature is enabled in settings
177
- lock_templates if Setting::Discovered.discovery_lock? && self.subnet.tftp?
136
+ ForemanDiscovery::ImportHookService.new(host: self, facts: facts).after_populate
178
137
  ensure
179
138
  self.save!
180
139
  end
181
140
 
182
- def lock_templates
183
- @host = self
184
- TemplateKind::PXE.each do |kind|
185
- template_name = Setting["discovery_#{kind.downcase}_lock_template"]
186
- Rails.logger.info "Locking discovered host #{self.mac} in subnet #{subnet} via #{template_name} template"
187
- template = unattended_render(::ProvisioningTemplate.find_by_name(template_name).template)
188
- subnet.tftp_proxy.set(kind, mac, :pxeconfig => template)
189
- end
190
- rescue ::Foreman::Exception => e
191
- ::Foreman::Logging.exception("Could not set tftp_proxy from proxy", e)
192
- end
193
-
194
- def import_from_facts(facts = self.facts_hash)
195
- cpu_count = facts['physicalprocessorcount'].to_i rescue 0
196
- memory = facts['memorysize_mb'].to_f.ceil rescue 0
197
- disks = facts.select { |key, value| key.to_s =~ /blockdevice.*_size/ }
198
- disks_size = 0
199
- disk_count = 0
200
-
201
- if disks.any?
202
- disks.values.each { |size| disks_size += (size.to_f rescue 0) }
203
- disk_count = disks.size
204
- # Turning disks_size to closest Mega for easier to read UI
205
- disks_size = (disks_size / 1024 / 1024).ceil if disks_size > 0
206
- end
207
-
208
- {:cpu_count => cpu_count, :memory => memory, :disk_count => disk_count, :disks_size => disks_size}
209
- end
210
-
211
141
  def proxied?
212
142
  subnet.present? && subnet.discovery.present?
213
143
  end
@@ -17,7 +17,7 @@ module Host::ManagedExtensions
17
17
  return
18
18
  end
19
19
  return if new_record? # Discovered Hosts already exist, and new_records will break `find`
20
- return unless type_changed? and ::Host::Base.find(self.id).type == "Host::Discovered"
20
+ return unless will_save_change_to_attribute?(:type, from: 'Host::Discovered')
21
21
  # reboot task must be high priority and there is no compensation action apparently
22
22
  if facts['discovery_kexec'] && provisioning_template(:kind => 'kexec')
23
23
  post_queue.create(:name => _("Reloading kernel on %s") % self, :priority => 10000, :action => [self, :setKexec])
@@ -63,12 +63,12 @@ module Host::ManagedExtensions
63
63
 
64
64
  def delete_discovery_attribute_set
65
65
  return if new_record?
66
- DiscoveryAttributeSet.where(:host_id => self.id).destroy_all if type_changed?
66
+ DiscoveryAttributeSet.where(:host_id => self.id).destroy_all if saved_change_to_attribute?(:type)
67
67
  end
68
68
 
69
69
  def update_notifications
70
70
  return if new_record?
71
- return unless type_changed?
71
+ return unless saved_change_to_attribute?(:type)
72
72
  ForemanDiscovery::UINotifications::DestroyHost.deliver!(self)
73
73
  end
74
74
  end
@@ -8,7 +8,7 @@ module Nic::ManagedExtensions
8
8
  def discovery_queue_rebuild_dns
9
9
  return unless (dns? || dns6? || reverse_dns? || reverse_dns6?) && errors.empty? && Setting[:discovery_always_rebuild_dns]
10
10
  return if self.host.new_record? || old.nil? # Discovered Hosts already exist, and new_records will break `find`
11
- return unless self.host.type_changed? and ::Host::Base.find(self.host.id).type == "Host::Discovered"
11
+ return unless self.host.will_save_change_to_attribute?(:type, from: 'Host::Discovered')
12
12
  return if self.pending_dns_record_changes?
13
13
  logger.debug "Queuing DNS rebuild for #{self}"
14
14
  queue.create(:name => _("Rebuild DNS for %s") % self, :priority => 10, :action => [self, :set_discovery_rebuild_dns])
@@ -0,0 +1,12 @@
1
+ module ForemanDiscovery
2
+ class ImportHook
3
+ attr_reader :host, :facts
4
+
5
+ def initialize(host:, facts:)
6
+ @host = host
7
+ @facts = facts
8
+ end
9
+
10
+ delegate :logger, to: Rails
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module ForemanDiscovery
2
+ class ImportHookService
3
+ HOOKS = [
4
+ ForemanDiscovery::ImportHooks::DiscoveryAttribute,
5
+ ForemanDiscovery::ImportHooks::LldpNeighbor,
6
+ ForemanDiscovery::ImportHooks::SubnetAndTaxonomy,
7
+ ForemanDiscovery::ImportHooks::LockTemplates
8
+ ]
9
+
10
+ attr_reader :host, :facts
11
+
12
+ def initialize(host:, facts:)
13
+ @host = host
14
+ @facts = facts
15
+ end
16
+
17
+ def after_populate
18
+ HOOKS.each do |hook_class|
19
+ hook = hook_class.new(host: host, facts: facts)
20
+ hook.after_populate
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ # set discovery search attributes first
2
+ module ForemanDiscovery
3
+ module ImportHooks
4
+ class DiscoveryAttribute < ImportHook
5
+ def after_populate
6
+ host.discovery_attribute_set = DiscoveryAttributeSet.where(host_id: host.id).first_or_create
7
+ host.discovery_attribute_set.update(import_from_facts)
8
+ end
9
+
10
+ def import_from_facts
11
+ cpu_count = facts['physicalprocessorcount'].to_i rescue 0
12
+ memory = facts['memorysize_mb'].to_f.ceil rescue 0
13
+ disks = facts.select { |key, value| key.to_s =~ /blockdevice.*_size/ }
14
+ disks_size = 0
15
+ disk_count = 0
16
+
17
+ if disks.any?
18
+ disks.values.each { |size| disks_size += (size.to_f rescue 0) }
19
+ disk_count = disks.size
20
+ # Turning disks_size to closest Mega for easier to read UI
21
+ disks_size = (disks_size / 1024 / 1024).ceil if disks_size > 0
22
+ end
23
+
24
+ {
25
+ cpu_count: cpu_count,
26
+ memory: memory,
27
+ disk_count: disk_count,
28
+ disks_size: disks_size
29
+ }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,11 @@
1
+ # Automatically bonds interfaces based on lldp facts
2
+ module ForemanDiscovery
3
+ module ImportHooks
4
+ class LldpNeighbor < ImportHook
5
+ def after_populate
6
+ return unless Setting[:discovery_auto_bond]
7
+ ::ForemanDiscovery::LldpNeighbors.eventually_make_bond(host)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ # lock the host into discovery via PXE if feature is enabled in settings
2
+ module ForemanDiscovery
3
+ module ImportHooks
4
+ class LockTemplates < ImportHook
5
+ def after_populate
6
+ lock_templates if Setting::Discovered.discovery_lock? && host.subnet.tftp?
7
+ end
8
+
9
+ def lock_templates
10
+ TemplateKind::PXE.each do |kind|
11
+ setting = "discovery_#{kind.downcase}_lock_template"
12
+ template_name = Setting[setting]
13
+ logger.info "Locking discovered host #{host.mac} in subnet #{host.subnet} via #{template_name} template"
14
+ template = ::ProvisioningTemplate.unscoped.find_by_name(template_name)
15
+ if template.nil?
16
+ logger.warn "Template '#{template_name}' provided by setting '#{setting}' does not exist, not locking"
17
+ next
18
+ end
19
+ rendered_template = host.render_template(template: template, params: { host: host })
20
+ host.subnet.tftp_proxy.set(kind, host.mac, pxeconfig: rendered_template)
21
+ end
22
+ rescue ::Foreman::Exception => e
23
+ ::Foreman::Logging.exception('Could not set tftp_proxy from proxy', e)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,63 @@
1
+ # Sets subnet, location and organization of a host based on the discovery facts
2
+ module ForemanDiscovery
3
+ module ImportHooks
4
+ class SubnetAndTaxonomy < ImportHook
5
+ def after_populate
6
+ primary_ip = host.primary_interface.ip
7
+
8
+ unless primary_ip
9
+ logger.warn "Unable to assign subnet - reboot trigger may not be possible, primary interface is missing IP address"
10
+ return
11
+ end
12
+
13
+ # set subnet
14
+ set_subnet(primary_ip)
15
+ # set location and organization
16
+ set_location
17
+ set_organization
18
+ end
19
+
20
+ private
21
+
22
+ def set_subnet(ip)
23
+ host.primary_interface.subnet = suggested_subnet(ip)
24
+ end
25
+
26
+ def suggested_subnet(ip)
27
+ subnet = Subnet.subnet_for(ip)
28
+ if subnet
29
+ logger.info "Detected subnet: #{subnet} with taxonomy #{subnet.organizations.collect(&:name)}/#{subnet.locations.collect(&:name)}"
30
+ else
31
+ logger.warn "Subnet could not be detected for #{ip}"
32
+ end
33
+ subnet
34
+ end
35
+
36
+ def set_location
37
+ return unless SETTINGS[:locations_enabled]
38
+ host.location = suggested_location
39
+ logger.info "Assigned location: #{host.location}"
40
+ end
41
+
42
+ def suggested_location
43
+ Location.find_by_title(facts["foreman_location"] || facts["discovery_location"]) ||
44
+ Location.find_by_title(Setting[:discovery_location]) ||
45
+ host.subnet.try(:locations).try(:first) ||
46
+ Location.first
47
+ end
48
+
49
+ def set_organization
50
+ return unless SETTINGS[:organizations_enabled]
51
+ host.organization = suggested_organization
52
+ logger.info "Assigned organization: #{host.organization}"
53
+ end
54
+
55
+ def suggested_organization
56
+ Organization.find_by_title(facts["foreman_organization"] || facts["discovery_organization"]) ||
57
+ Organization.find_by_title(Setting[:discovery_organization]) ||
58
+ host.subnet.try(:organizations).try(:first) ||
59
+ Organization.first
60
+ end
61
+ end
62
+ end
63
+ end
@@ -21,7 +21,7 @@
21
21
  <% end -%>
22
22
  <th class="hidden-tablet hidden-xs"><%= sort :subnet, :as => _("Subnet") %></th>
23
23
  <th class="hidden-tablet hidden-xs"><%= sort :last_report, :as => _("Last Facts Upload") %></th>
24
- <th></th>
24
+ <th class="hidden-tablet hidden-xs"><%= _("Actions") %></th>
25
25
  </tr>
26
26
  <% @hosts.each do |host| -%>
27
27
  <tr>
@@ -24,16 +24,17 @@ Please read kexec(8) man page for more information about semantics.
24
24
  mask = @host.facts['discovery_netmask']
25
25
  gw = @host.facts['discovery_gateway']
26
26
  dns = @host.facts['discovery_dns']
27
- append = @host.facts['append']
28
- options = ["auto=true"]
27
+ options = ["nomodeset", "auto=true"]
28
+ options << @host.facts['append']
29
29
  options << "domain=#{@host.domain}"
30
30
  options << 'console-setup/ask_detect=false console-setup/layout=USA console-setup/variant=USA keyboard-configuration/layoutcode=us localechooser/translation/warn-light=true localechooser/translation/warn-severe=true'
31
31
  options << "locale=#{@host.params['lang'] || 'en_US'}"
32
+ options << "inst.stage2=#{@host.operatingsystem.medium_uri(@host)}" if @host.operatingsystem.name.match(/Atomic/i)
32
33
  -%>
33
34
  {
34
35
  "comment": "WARNING: Both kernel and initram are not set in preview mode due to http://projects.theforeman.org/issues/19737",
35
36
  "kernel": "<%= @kexec_kernel %>",
36
37
  "initram": "<%= @kexec_initrd %>",
37
- "append": "url=<%= foreman_url('provision') + "&static=yes" %> interface=<%= mac %> netcfg/get_ipaddress=<%= ip %> netcfg/get_netmask=<%= mask %> netcfg/get_gateway=<%= gw %> netcfg/get_nameservers=<%= dns %> netcfg/disable_dhcp=true netcfg/get_hostname=<%= @host.name %> BOOTIF=<%= bootif %> <%= options.join(' ') %>",
38
+ "append": "url=<%= foreman_url('provision') + "&static=yes" %> interface=<%= mac %> netcfg/get_ipaddress=<%= ip %> netcfg/get_netmask=<%= mask %> netcfg/get_gateway=<%= gw %> netcfg/get_nameservers=<%= dns %> netcfg/disable_dhcp=true netcfg/get_hostname=<%= @host.name %> BOOTIF=<%= bootif %> <%= options.compact.join(' ') %>",
38
39
  "extra": []
39
40
  }
@@ -34,7 +34,9 @@ Please read kexec(8) man page for more information about semantics.
34
34
  mask = @host.facts['discovery_netmask']
35
35
  gw = @host.facts['discovery_gateway']
36
36
  dns = @host.facts['discovery_dns']
37
- append = @host.facts['append']
37
+ options = ["nomodeset"]
38
+ options << @host.facts['append']
39
+ options << "inst.stage2=#{@host.operatingsystem.medium_uri(@host)}" if @host.operatingsystem.name.match(/Atomic/i)
38
40
  -%>
39
41
  {
40
42
  "comment": "WARNING: Both kernel and initram are not set in preview mode due to http://projects.theforeman.org/issues/19737",
@@ -44,7 +46,7 @@ Please read kexec(8) man page for more information about semantics.
44
46
  (@host.operatingsystem.name != 'Fedora' and @host.operatingsystem.major.to_i >= 7) -%>
45
47
  "append": "ks=<%= foreman_url('provision') + "&static=yes" %> inst.ks.sendmac <%= "ip=#{ip}::#{gw}:#{mask}:::none nameserver=#{dns} ksdevice=bootif BOOTIF=#{bootif} nomodeset #{append}" %>",
46
48
  <% else -%>
47
- "append": "ks=<%= foreman_url('provision') + "&static=yes" %> kssendmac nicdelay=5 <%= "ip=#{ip} netmask=#{mask} gateway=#{gw} dns=#{dns} ksdevice=#{mac} BOOTIF=#{bootif} nomodeset #{append}" %>",
49
+ "append": "ks=<%= foreman_url('provision') + "&static=yes" %> kssendmac nicdelay=5 <%= "ip=#{ip} netmask=#{mask} gateway=#{gw} dns=#{dns} ksdevice=#{mac} BOOTIF=#{bootif} " + options.compact.join(' ') %>",
48
50
  <% end -%>
49
51
  "extra": []
50
52
  }
@@ -7,8 +7,7 @@ class FillDiscoveryAttributeSetsForExistingHosts < ActiveRecord::Migration[4.2]
7
7
  FakeDiscoveredHost.where(:type => "Host::Discovered").all.each do |host|
8
8
  begin
9
9
  say "Populating attribute set for discovered host #{host.name}"
10
- host.discovery_attribute_set = DiscoveryAttributeSet.where(:host_id => host.id).first_or_create
11
- host.discovery_attribute_set.update_attributes(host.import_from_facts)
10
+ ForemanDiscovery::ImportHooks::DiscoveryAttribute.new(host: host, facts: host.facts_hash).after_populate
12
11
  host.save!
13
12
  rescue Exception => e
14
13
  say "Error while populating host #{host.name}, deleting: #{e.message}:\n" + e.backtrace.join("\n")
@@ -1,4 +1,9 @@
1
- kind = TemplateKind.unscoped.where(:name => 'kexec').first_or_create
1
+ organizations = Organization.unscoped.all
2
+ locations = Location.unscoped.all
3
+
4
+ kind = TemplateKind.unscoped.find_or_create_by(name: 'kexec')
5
+ kind.description = N_("Command line options for kexec during PXE-less provisioning.")
6
+ kind.save!
2
7
 
3
8
  ProvisioningTemplate.without_auditing do
4
9
  [['redhat_kexec.erb', 'Red Hat'], ['debian_kexec.erb', 'Debian']].each do |tmpl_names|
@@ -12,8 +17,10 @@ ProvisioningTemplate.without_auditing do
12
17
  :template => content,
13
18
  :default => true,
14
19
  :vendor => "Foreman Discovery",
15
- :locked => false
20
+ :locked => true
16
21
  }
22
+ tmpl.organizations = organizations if SETTINGS[:organizations_enabled]
23
+ tmpl.locations = locations if SETTINGS[:locations_enabled]
17
24
  tmpl.save!(:validate => false) if tmpl.changes.present?
18
25
  end
19
26
  end
@@ -5,7 +5,7 @@ require 'rest-client'
5
5
 
6
6
  def find_base name="default"
7
7
  return name if File.exists?(name)
8
- file = File.absolute_path(File.dirname(__FILE__) + "/discovery/#{name}.json")
8
+ file = File.absolute_path(File.dirname(__FILE__) + "../../test/facts/#{name}.json")
9
9
  raise "Unable to find file #{file}" unless File.exists?(file)
10
10
  file
11
11
  end