Module: ForemanMaintain::Concerns::OsFacts
- Included in:
- ForemanMaintain, SystemHelpers, RepositoryManager::El
- Defined in:
- lib/foreman_maintain/concerns/os_facts.rb
Constant Summary collapse
- OS_RELEASE_FILE =
'/etc/os-release'.freeze
- FALLBACK_OS_RELEASE_FILE =
'/usr/lib/os-release'.freeze
Instance Method Summary collapse
- #centos? ⇒ Boolean
- #cpu_cores ⇒ Object
- #deb_major_version ⇒ Object
- #debian? ⇒ Boolean
- #debian_or_ubuntu? ⇒ Boolean
- #el8? ⇒ Boolean
- #el? ⇒ Boolean
- #el_major_version ⇒ Object
- #el_short_name ⇒ Object
- #facts ⇒ Object
- #memory ⇒ Object
- #os_id ⇒ Object
- #os_id_like_list ⇒ Object
- #os_name ⇒ Object
- #os_release_file ⇒ Object
- #os_version ⇒ Object
- #os_version_codename ⇒ Object
- #os_version_id ⇒ Object
- #rhel? ⇒ Boolean
- #ubuntu? ⇒ Boolean
- #ubuntu_major_version ⇒ Object
Instance Method Details
#centos? ⇒ Boolean
97 98 99 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 97 def centos? os_id == 'centos' end |
#cpu_cores ⇒ Object
110 111 112 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 110 def cpu_cores execute('nproc') end |
#deb_major_version ⇒ Object
73 74 75 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 73 def deb_major_version os_version_id.to_i if debian? end |
#debian? ⇒ Boolean
61 62 63 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 61 def debian? os_id == 'debian' end |
#debian_or_ubuntu? ⇒ Boolean
81 82 83 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 81 def debian_or_ubuntu? debian? || ubuntu? end |
#el8? ⇒ Boolean
57 58 59 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 57 def el8? el_major_version == 8 end |
#el? ⇒ Boolean
53 54 55 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 53 def el? File.exist?('/etc/redhat-release') end |
#el_major_version ⇒ Object
69 70 71 |
# 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 ⇒ Object
101 102 103 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 101 def el_short_name "el#{el_major_version}" end |
#facts ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 ⇒ Object
105 106 107 108 |
# 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 ⇒ Object
41 42 43 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 41 def os_id facts.fetch('ID') end |
#os_id_like_list ⇒ Object
45 46 47 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 45 def os_id_like_list facts.fetch('ID_LIKE', '').split end |
#os_name ⇒ Object
49 50 51 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 49 def os_name facts.fetch('NAME') end |
#os_release_file ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# 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 ⇒ Object
85 86 87 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 85 def os_version facts.fetch('VERSION') end |
#os_version_codename ⇒ Object
89 90 91 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 89 def os_version_codename facts.fetch('VERSION_CODENAME') end |
#os_version_id ⇒ Object
37 38 39 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 37 def os_version_id facts.fetch('VERSION_ID') end |
#rhel? ⇒ Boolean
93 94 95 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 93 def rhel? os_id == 'rhel' end |
#ubuntu? ⇒ Boolean
65 66 67 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 65 def ubuntu? os_id == 'ubuntu' end |
#ubuntu_major_version ⇒ Object
77 78 79 |
# File 'lib/foreman_maintain/concerns/os_facts.rb', line 77 def ubuntu_major_version os_version_id if ubuntu? end |