Class: ForemanAnsible::FactParser
- Inherits:
-
FactParser
- Object
- FactParser
- ForemanAnsible::FactParser
show all
- Includes:
- OperatingSystemParser
- Defined in:
- app/services/foreman_ansible/fact_parser.rb
Overview
Override methods from Foreman app/services/fact_parser so that facts representing host properties are understood when they come from Ansible.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#debian_os_major_sid, #local_os, #new_os, #operatingsystem, #os_description, #os_major, #os_minor, #os_name, #os_release, #os_release_name
Constructor Details
#initialize(facts) ⇒ FactParser
Returns a new instance of FactParser.
10
11
12
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 10
def initialize(facts)
@facts = HashWithIndifferentAccess.new(facts[:ansible_facts])
end
|
Instance Attribute Details
#facts ⇒ Object
Returns the value of attribute facts.
8
9
10
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 8
def facts
@facts
end
|
Instance Method Details
#architecture ⇒ Object
17
18
19
20
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 17
def architecture
name = facts[:ansible_architecture] || facts[:facter_architecture]
Architecture.where(:name => name).first_or_create if name.present?
end
|
#boot_timestamp ⇒ Object
71
72
73
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 71
def boot_timestamp
Time.zone.now.to_i - facts['ansible_uptime_seconds'].to_i
end
|
#cores ⇒ Object
87
88
89
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 87
def cores
facts['ansible_processor_cores'].to_i
end
|
#domain ⇒ Object
28
29
30
31
32
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 28
def domain
name = detect_fact([:ansible_domain, :facter_domain,
:ohai_domain, :domain])
Domain.where(:name => name).first_or_create if name.present?
end
|
#environment ⇒ Object
Don’t do anything as there’s no env in Ansible
15
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 15
def environment; end
|
#get_facts_for_interface(iface_name) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 54
def get_facts_for_interface(iface_name)
interface = iface_name.tr('-', '_') interface_facts = facts[:"ansible_#{interface}"]
ipaddress = ip_from_interface(interface)
ipaddress6 = ipv6_from_interface(interface)
macaddress = mac_from_interface(interface)
iface_facts = HashWithIndifferentAccess[
interface_facts.merge(:ipaddress => ipaddress,
:ipaddress6 => ipaddress6,
:macaddress => macaddress)
]
logger.debug { "Ansible interface #{interface} facts: #{iface_facts.inspect}" }
iface_facts
end
|
#get_interfaces ⇒ Object
Move ansible’s default interface first in the list of interfaces since Foreman picks the first one that is usable. If ansible has no preference otherwise at least sort the list.
This method overrides app/services/fact_parser.rb on Foreman and returns an array of interface names, [‘eth0’, ‘wlan1’, etc…]
44
45
46
47
48
49
50
51
52
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 44
def get_interfaces pref = facts[:ansible_default_ipv4] &&
facts[:ansible_default_ipv4]['interface']
if pref.present?
(facts[:ansible_interfaces] - [pref]).unshift(pref)
else
ansible_interfaces
end
end
|
#ipmi_interface ⇒ Object
69
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 69
def ipmi_interface; end
|
#model ⇒ Object
22
23
24
25
26
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 22
def model
name = detect_fact([:ansible_product_name, :facter_virtual,
:facter_productname, :facter_model, :model])
Model.where(:name => name.strip).first_or_create if name.present?
end
|
#ram ⇒ Object
79
80
81
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 79
def ram
facts['ansible_memtotal_mb'].to_i
end
|
#sockets ⇒ Object
83
84
85
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 83
def sockets
facts['ansible_processor_count'].to_i
end
|
#support_interfaces_parsing? ⇒ Boolean
34
35
36
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 34
def support_interfaces_parsing?
true
end
|
#virtual ⇒ Object
75
76
77
|
# File 'app/services/foreman_ansible/fact_parser.rb', line 75
def virtual
facts['ansible_virtualization_role'] == 'guest'
end
|