Method: ForemanDiscovery::HostConverter.set_build_clean_facts

Defined in:
app/services/foreman_discovery/host_converter.rb

.set_build_clean_facts(host) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/foreman_discovery/host_converter.rb', line 23

def self.set_build_clean_facts(host)
  # fact cleaning
  if Setting['discovery_clean_facts']
    # clean all facts except those from Discovery
    host.define_singleton_method(:clear_facts) do
      keep_ids = FactValue.where(host_id: host.id, fact_names: { type: 'DiscoveryFactName' }).where("fact_names.name like 'discovery_%'").joins(:fact_name).pluck("fact_values.id")
      FactValue.where.not(id: keep_ids).delete_all
    end
  else
    # clean no facts (default behavior)
    host.define_singleton_method(:clear_facts) {}
  end
  # set build flag
  host.build = true
end