Class: ForemanDiscovery::ImportHooks::DiscoveryAttribute
Instance Attribute Summary
#facts, #host
Instance Method Summary
collapse
#initialize
Instance Method Details
#after_populate ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'app/services/foreman_discovery/import_hooks/discovery_attribute.rb', line 5
def after_populate
if host.discovery_attribute_set
host.discovery_attribute_set.update(import_from_facts)
else
host.build_discovery_attribute_set(import_from_facts)
end
end
|
#import_from_facts ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/services/foreman_discovery/import_hooks/discovery_attribute.rb', line 17
def import_from_facts
cpu_count = facts['physicalprocessorcount'].to_i rescue 0
memory = facts['memorysize_mb'].to_f.ceil rescue 0
disks = facts.select { |key, value| key.to_s =~ /blockdevice.*_size/ }
disks_size = 0
disk_count = 0
if disks.any?
disks.values.each { |size| disks_size += (size.to_f rescue 0) }
disk_count = disks.size
disks_size = (disks_size / 1024 / 1024).ceil if disks_size > 0
end
{
cpu_count: cpu_count,
memory: memory,
disk_count: disk_count,
disks_size: disks_size
}
end
|