Class: ForemanSalt::FactParser

Inherits:
FactParser
  • Object
show all
Defined in:
app/services/foreman_salt/fact_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#factsObject (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

#architectureObject



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

#domainObject



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

#environmentObject



21
22
23
# File 'app/services/foreman_salt/fact_parser.rb', line 21

def environment
  # Don't touch the Puppet environment field
end

#interfacesObject



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

#ipObject



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_interfaceObject



50
51
52
# File 'app/services/foreman_salt/fact_parser.rb', line 50

def ipmi_interface
  nil
end

#macObject



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

#modelObject



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

#operatingsystemObject



5
6
7
8
9
10
11
12
13
# File 'app/services/foreman_salt/fact_parser.rb', line 5

def operatingsystem
  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_interfaceObject



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

Returns:

  • (Boolean)


76
77
78
# File 'app/services/foreman_salt/fact_parser.rb', line 76

def support_interfaces_parsing?
  true
end