Class: ForemanResourceQuota::ResourceOrigins::FactsOrigin
Constant Summary
collapse
- FACTS_KEYS_CPU_CORES =
[
'ansible_processor_cores',
'facter_processors::cores',
'proc_cpuinfo::common::cpu_cores',
'processors::cores',
].freeze
- FACTS_KEYS_MEMORY_B =
[
'facter_memory::system::total_bytes',
'memory::system::total_bytes',
'memory::memtotal',
].freeze
- FACTS_REGEX_DISK_B =
[
/^disks::(\w+)::size_bytes$/,
/^facter_disks::(\w+)::size_bytes$/,
].freeze
ForemanResourceQuota::ResourceOrigin::RESOURCE_FUNCTION_MAP
Instance Method Summary
collapse
#collect_resources!
Instance Method Details
32
33
34
35
36
37
38
|
# File 'app/services/foreman_resource_quota/resource_origins/facts_origin.rb', line 32
def (param)
common_keys = param.keys & FACTS_KEYS_CPU_CORES
return param[common_keys.first].to_i if common_keys.any?
nil
rescue StandardError
nil
end
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/services/foreman_resource_quota/resource_origins/facts_origin.rb', line 48
def (param)
total_gb = nil
FACTS_REGEX_DISK_B.each do |regex|
relevant_keys = param.keys.grep(regex)
next unless relevant_keys.any?
total_gb = sum_disk_space(param, relevant_keys)
end
total_gb&.to_i
rescue StandardError
nil
end
|
40
41
42
43
44
45
46
|
# File 'app/services/foreman_resource_quota/resource_origins/facts_origin.rb', line 40
def (param)
common_keys = param.keys & FACTS_KEYS_MEMORY_B
return (param[common_keys.first].to_i / ResourceQuotaHelper::FACTOR_B_TO_MB).to_i if common_keys.any?
nil
rescue StandardError
nil
end
|
#host_attribute_eager_name ⇒ Object
24
25
26
|
# File 'app/services/foreman_resource_quota/resource_origins/facts_origin.rb', line 24
def host_attribute_eager_name
:fact_values
end
|
#host_attribute_name ⇒ Object
28
29
30
|
# File 'app/services/foreman_resource_quota/resource_origins/facts_origin.rb', line 28
def host_attribute_name
:facts
end
|
#sum_disk_space(facts, keys) ⇒ Object
63
64
65
|
# File 'app/services/foreman_resource_quota/resource_origins/facts_origin.rb', line 63
def sum_disk_space(facts, keys)
keys.map { |key| facts[key].to_i }.sum / ResourceQuotaHelper::FACTOR_B_TO_GB unless keys.empty?
end
|