module ForemanMaintain::Concerns::OsFacts

Constants

FALLBACK_OS_RELEASE_FILE
OS_RELEASE_FILE

Public Instance Methods

centos?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 97
def centos?
  os_id == 'centos'
end
cpu_cores() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 110
def cpu_cores
  execute('nproc')
end
deb_major_version() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 73
def deb_major_version
  os_version_id.to_i if debian?
end
debian?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 61
def debian?
  os_id == 'debian'
end
debian_or_ubuntu?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 81
def debian_or_ubuntu?
  debian? || ubuntu?
end
el8?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 57
def el8?
  el_major_version == 8
end
el?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 53
def el?
  File.exist?('/etc/redhat-release')
end
el_major_version() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 69
def el_major_version
  os_version_id.to_i if el?
end
el_short_name() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 101
def el_short_name
  "el#{el_major_version}"
end
facts() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 19
def facts
  unless defined?(@facts)
    @facts = {}
    regex = /^(["'])(.*)(\1)$/
    File.open(os_release_file) do |file|
      file.readlines.each do |line|
        line.strip! # drop any whitespace, including newlines from start and end of the line
        next if line.start_with?('#') # ignore comments
        # split at most into 2 items, if the value ever contains an =
        key, value = line.split('=', 2)
        next unless key && value
        @facts[key] = value.gsub(regex, '\2').delete('\\')
      end
    end
  end
  @facts
end
memory() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 105
def memory
  meminfo = File.read('/proc/meminfo')
  meminfo.match(/^MemTotal:\s+(?<memory>\d+) kB/)['memory']
end
os_id() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 41
def os_id
  facts.fetch('ID')
end
os_id_like_list() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 45
def os_id_like_list
  facts.fetch('ID_LIKE', '').split
end
os_name() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 49
def os_name
  facts.fetch('NAME')
end
os_release_file() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 7
def os_release_file
  if File.file?(OS_RELEASE_FILE)
    return OS_RELEASE_FILE
  elsif File.file?(FALLBACK_OS_RELEASE_FILE)
    return FALLBACK_OS_RELEASE_FILE
  else
    puts "The #{OS_RELEASE_FILE} and #{FALLBACK_OS_RELEASE_FILE} files are missing! "\
         "Can't continue the execution without Operating System's facts!"
    exit 1
  end
end
os_version() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 85
def os_version
  facts.fetch('VERSION')
end
os_version_codename() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 89
def os_version_codename
  facts.fetch('VERSION_CODENAME')
end
os_version_id() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 37
def os_version_id
  facts.fetch('VERSION_ID')
end
rhel?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 93
def rhel?
  os_id == 'rhel'
end
ubuntu?() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 65
def ubuntu?
  os_id == 'ubuntu'
end
ubuntu_major_version() click to toggle source
# File lib/foreman_maintain/concerns/os_facts.rb, line 77
def ubuntu_major_version
  os_version_id if ubuntu?
end