Class: ForemanSalt::FactParser
- Inherits:
-
FactParser
- Object
- FactParser
- ForemanSalt::FactParser
- Defined in:
- app/services/foreman_salt/fact_parser.rb
Instance Attribute Summary collapse
-
#facts ⇒ Object
readonly
Returns the value of attribute facts.
Instance Method Summary collapse
- #architecture ⇒ Object
- #domain ⇒ Object
- #environment ⇒ Object
- #interfaces ⇒ Object
- #ip ⇒ Object
- #ipmi_interface ⇒ Object
- #mac ⇒ Object
- #model ⇒ Object
- #operatingsystem ⇒ Object
- #primary_interface ⇒ Object
- #support_interfaces_parsing? ⇒ Boolean
Instance Attribute Details
#facts ⇒ Object (readonly)
Returns the value of attribute facts.
3 4 5 |
# File 'app/services/foreman_salt/fact_parser.rb', line 3 def facts @facts end |
Instance Method Details
#architecture ⇒ Object
15 16 17 18 19 |
# File 'app/services/foreman_salt/fact_parser.rb', line 15 def architecture name = facts[:osarch] name = 'x86_64' if name == 'amd64' Architecture.where(:name => name).first_or_create unless name.blank? end |
#domain ⇒ Object
30 31 32 33 |
# File 'app/services/foreman_salt/fact_parser.rb', line 30 def domain name = facts[:domain] Domain.where(:name => name).first_or_create unless name.blank? end |
#environment ⇒ Object
21 22 23 |
# File 'app/services/foreman_salt/fact_parser.rb', line 21 def environment # Don't touch the Puppet environment field end |
#interfaces ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/services/foreman_salt/fact_parser.rb', line 54 def interfaces interfaces = {} facts.each do |fact, value| next unless value && fact.to_s =~ /^ip_interfaces/ (_, interface, number) = fact.split(FactName::SEPARATOR) interface_name = if number == '0' || number.nil? interface else "#{interface}.#{number}" end if !interface.blank? && interface != 'lo' interfaces[interface_name] = {} if interfaces[interface_name].blank? interfaces[interface_name].merge!(:ipaddress => value, :macaddress => macs[interface]) end end interfaces end |
#ip ⇒ Object
35 36 37 38 |
# File 'app/services/foreman_salt/fact_parser.rb', line 35 def ip ip = facts.find { |fact, value| fact =~ /^fqdn_ip4/ && value && value != '127.0.0.1' } ip[1] if ip end |
#ipmi_interface ⇒ Object
50 51 52 |
# File 'app/services/foreman_salt/fact_parser.rb', line 50 def ipmi_interface nil end |
#mac ⇒ Object
45 46 47 48 |
# File 'app/services/foreman_salt/fact_parser.rb', line 45 def mac interface = interfaces.find { |_, value| value[:ipaddress] == ip } interface[1][:macaddress] if interface end |
#model ⇒ Object
25 26 27 28 |
# File 'app/services/foreman_salt/fact_parser.rb', line 25 def model name = facts[:productname] Model.where(:name => name.strip).first_or_create unless name.blank? end |
#operatingsystem ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/services/foreman_salt/fact_parser.rb', line 5 def os = Operatingsystem.where(os_hash).first_or_initialize if os.new_record? os.deduce_family os.release_name = facts[:lsb_distrib_codename] os.save end os if os.persisted? end |
#primary_interface ⇒ Object
40 41 42 43 |
# File 'app/services/foreman_salt/fact_parser.rb', line 40 def primary_interface interface = interfaces.find { |_, value| value[:ipaddress] == ip } interface[0] if interface end |
#support_interfaces_parsing? ⇒ Boolean
76 77 78 |
# File 'app/services/foreman_salt/fact_parser.rb', line 76 def support_interfaces_parsing? true end |