5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'app/lib/actions/import_host_facts.rb', line 5
def run
facts = input[:facts]
unless (input[:options][:host_id].nil? && facts.fetch(:status, {})[:state] == 'down')
host = determine_host(facts)
facts = try_match_interface_names(host, facts)
facts.delete(:hostnames)
::User.as :admin do
state = host.import_facts(facts)
output[:state] = state
output[:facts] = facts
end
try_set_subnet!(host)
host.smart_proxy_ids << input[:proxy_id]
output[:host_id] = host.id
output[:hostname] = host.name
scan = ::ForemanProbing::Scan.find(input[:scan_id])
host.organization_id ||= scan.organization_ids.first
host.location_id ||= scan.location_ids.first
host.scans << scan
host.save!
end
rescue ::Foreman::Exception => e
raise e unless e.code == 'ERF51-9911'
end
|