Class: PuppetFactParser
Constant Summary
Constants inherited
from FactParser
FactParser::ALIASES, FactParser::BONDS, FactParser::BRIDGES, FactParser::VIRTUAL, FactParser::VIRTUAL_NAMES, FactParser::VLANS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from FactParser
#class_name_humanized, #comment, #has_comment?, #hostgroup, #initialize, #parse_interfaces?, parser_for, parsers, register_fact_parser
Constructor Details
This class inherits a constructor from FactParser
Instance Attribute Details
Returns the value of attribute facts
2
3
4
|
# File 'app/services/puppet_fact_parser.rb', line 2
def facts
@facts
end
|
Instance Method Details
#architecture ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'app/services/puppet_fact_parser.rb', line 49
def architecture
name = case os_name
when /(sunos|solaris|junos)/i
facts[:hardwareisa]
else
facts[:architecture] || facts[:hardwareisa]
end
name = "x86_64" if name == "amd64"
name = "aarch64" if name == "arm64"
Architecture.where(:name => name).first_or_create if name.present?
end
|
#boot_timestamp ⇒ Object
117
118
119
120
121
|
# File 'app/services/puppet_fact_parser.rb', line 117
def boot_timestamp
uptime_seconds = facts.fetch('system_uptime', {}).fetch('seconds', nil) || facts[:uptime_seconds]
uptime_seconds.nil? ? nil : (Time.zone.now.to_i - uptime_seconds.to_i)
end
|
109
110
111
|
# File 'app/services/puppet_fact_parser.rb', line 109
def certname
facts[:clientcert]
end
|
139
140
141
|
# File 'app/services/puppet_fact_parser.rb', line 139
def cores
facts.dig('processors', 'count') || facts['processorcount']
end
|
#disks_total ⇒ Object
143
144
145
|
# File 'app/services/puppet_fact_parser.rb', line 143
def disks_total
facts['disks']&.values&.sum { |disk| disk&.fetch('size_bytes', 0).to_i }
end
|
70
71
72
73
|
# File 'app/services/puppet_fact_parser.rb', line 70
def domain
name = facts[:domain]
Domain.unscoped.where(:name => name).first_or_create if name.present?
end
|
#environment ⇒ Object
43
44
45
46
47
|
# File 'app/services/puppet_fact_parser.rb', line 43
def environment
name = facts[:environment] || facts[:agent_specified_environment] || Setting[:default_puppet_environment]
Environment.unscoped.where(:name => name).first_or_create
end
|
#interfaces ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'app/services/puppet_fact_parser.rb', line 80
def interfaces
interfaces = super
return interfaces unless use_legacy_facts?
underscore_device_regexp = /\A([^_]*)_(\d+)\z/
interfaces.clone.each do |identifier, _|
matches = identifier.match(underscore_device_regexp)
next unless matches
new_name = "#{matches[1]}.#{matches[2]}"
interfaces[new_name] = interfaces.delete(identifier)
end
interfaces
end
|
#interfaces_attribute_map(attribute) ⇒ Object
93
94
95
96
97
98
99
100
|
# File 'app/services/puppet_fact_parser.rb', line 93
def interfaces_attribute_map(attribute)
map = {
'mac' => 'macaddress',
'ip' => 'ipaddress',
'ip6' => 'ipaddress6',
}
map.has_key?(attribute) ? map[attribute] : attribute
end
|
#ipmi_interface ⇒ Object
75
76
77
78
|
# File 'app/services/puppet_fact_parser.rb', line 75
def ipmi_interface
ipmi = facts.select { |name, _| name =~ /\Aipmi_(.*)\Z/ }.map { |name, value| [name.sub(/\Aipmi_/, ''), value] }
Hash[ipmi].with_indifferent_access
end
|
63
64
65
66
67
68
|
# File 'app/services/puppet_fact_parser.rb', line 63
def model
name = facts[:productname] || facts[:model] || facts[:boardproductname]
name ||= facts[:virtual] if virtual
Model.where(:name => name.strip).first_or_create if name.present?
end
|
#operatingsystem ⇒ Object
4
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
33
34
35
36
37
38
39
40
41
|
# File 'app/services/puppet_fact_parser.rb', line 4
def operatingsystem
orel = os_release.dup
if orel.present?
major, minor = orel.split('.', 2)
major = major.to_s.gsub(/\D/, '')
minor = minor.to_s.gsub(/[^\d\.]/, '')
args = {:name => os_name, :major => major, :minor => minor}
os = Operatingsystem.find_or_initialize_by(args)
if os_name[/debian|ubuntu/i] || os.family == 'Debian'
if facts.dig(:os, :distro, :codename).presence || facts[:lsbdistcodename]
os.release_name = facts.dig(:os, :distro, :codename).presence || facts[:lsbdistcodename]
elsif os.release_name.blank?
os.release_name = 'unknown'
end
end
else
os = Operatingsystem.find_or_initialize_by(:name => os_name)
end
if os.description.blank?
if os_name == 'SLES'
os.description = os_name + ' ' + orel.gsub('.', ' SP')
elsif facts.dig(:os, :distro, :description).presence || facts[:lsbdistdescription]
family = os.deduce_family || 'Operatingsystem'
os = os.becomes(family.constantize)
os.description = os.shorten_description(facts.dig(:os, :distro, :description).presence || facts[:lsbdistdescription])
end
end
if os.new_record?
os.save!
Operatingsystem.find_by_id(os.id) else
os.save!
os
end
end
|
127
128
129
130
131
132
133
|
# File 'app/services/puppet_fact_parser.rb', line 127
def ram
if (value = facts.dig('memory', 'system', 'total_bytes'))
value / 1.megabyte
else
facts['memorysize_mb']
end
end
|
135
136
137
|
# File 'app/services/puppet_fact_parser.rb', line 135
def sockets
facts.dig('processors', 'physicalcount') || facts['physicalprocessorcount']
end
|
#suggested_primary_interface(host) ⇒ Object
102
103
104
105
106
107
|
# File 'app/services/puppet_fact_parser.rb', line 102
def suggested_primary_interface(host)
facter3_primary = facts.try(:fetch, "networking", nil).try(:fetch, "primary", nil)
return [facter3_primary, interfaces[facter3_primary]] if facter3_primary
super
end
|
#support_interfaces_parsing? ⇒ Boolean
113
114
115
|
# File 'app/services/puppet_fact_parser.rb', line 113
def support_interfaces_parsing?
true
end
|
123
124
125
|
# File 'app/services/puppet_fact_parser.rb', line 123
def virtual
facts['is_virtual']
end
|