Class: ForemanChef::FactParser

Inherits:
FactParser
  • Object
show all
Defined in:
app/models/foreman_chef/fact_parser.rb

Constant Summary collapse

VIRTUAL =
/\A([a-z0-9]+)[:.](\d+)\Z/
VIRTUAL_NAMES =
/#{VIRTUAL}|#{BRIDGES}|#{BONDS}/

Instance Method Summary collapse

Instance Method Details

#architectureObject



57
58
59
60
61
# File 'app/models/foreman_chef/fact_parser.rb', line 57

def architecture
  name = facts['kernel::machine']
  name = "x86_64" if name == "amd64"
  Architecture.where(:name => name).first_or_create unless name.blank?
end

#boot_timestampObject



95
96
97
# File 'app/models/foreman_chef/fact_parser.rb', line 95

def boot_timestamp
  Time.zone.now.to_i - facts['system_uptime::seconds'].to_i
end

#certnameObject



83
84
85
# File 'app/models/foreman_chef/fact_parser.rb', line 83

def certname
  facts['chef_node_name']
end

#domainObject



72
73
74
75
# File 'app/models/foreman_chef/fact_parser.rb', line 72

def domain
  name = facts['domain']
  Domain.where(:name => name).first_or_create unless name.blank?
end

#environmentObject

we don’t want to parse puppet environment, foreman_chef already has its own environment



53
54
55
# File 'app/models/foreman_chef/fact_parser.rb', line 53

def environment
  nil
end

#ipmi_interfaceObject



77
78
79
80
81
# File 'app/models/foreman_chef/fact_parser.rb', line 77

def ipmi_interface
  if facts['ipmi::mac_address'].present?
    { 'ipaddress' => facts['ipmi::address'], 'macaddress' => facts['ipmi::mac_address'] }.with_indifferent_access
  end
end

#modelObject



63
64
65
66
67
68
69
70
# File 'app/models/foreman_chef/fact_parser.rb', line 63

def model
  if facts['virtualization'].present?
    name = facts['virtualization']['system']
  else
    name = facts['dmi::system::product_name']
  end
  Model.where(:name => name.strip).first_or_create unless name.blank?
end

#operatingsystemObject



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
42
43
44
45
46
47
48
49
50
# File 'app/models/foreman_chef/fact_parser.rb', line 6

def operatingsystem
  os_name = facts['lsb::id'] || facts['platform']
  release = facts['lsb::release'] || facts['platform_version']
  # if we have no release information we can't assign OS properly (e.g. missing redhat-lsb)
  if release.nil?
    major, minor = 1, nil
  else
    major, minor = release.split('.')
  end

  if facts['platform'] == 'windows'
    release_name = facts['kernel::name']
    os_name = os_name.capitalize
  else
    # to keep OS names consistent with other cfgmgt agents we skip description importing
    # description = facts['lsb::description']
    release_name = facts['lsb::codename']
  end

  # convert OHAI names to Foreman common OS names
  case os_name
    when 'RedHatEnterpriseServer'
      os_name = 'RedHat'
  end


  # So far only CentOS needs exception
  case os_name
    when 'CentOS'
      if major.to_i >= 7
        # get the minor.build number, e.g. 7.2.1511 -> 2.1511
        minor = release[2..-1]
      end
  end

  begin
    klass = os_name.constantize
  rescue NameError => e
    logger.debug "unknown operating system #{os_name}, fallback to generic type"
    klass = Operatingsystem
  end

  args = { :name => os_name, :major => major.to_s, :minor => minor.to_s }
  klass.where(args).first || klass.new(args.merge(:release_name => release_name)).tap(&:save!)
end

#parse_interfaces?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/foreman_chef/fact_parser.rb', line 91

def parse_interfaces?
  support_interfaces_parsing? && !Setting['ignore_puppet_facts_for_provisioning']
end

#support_interfaces_parsing?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/foreman_chef/fact_parser.rb', line 87

def support_interfaces_parsing?
  true
end