class Facter::Resolvers::Linux::Disk

Constants

DIR
FILE_PATHS

Private Class Methods

build_disks_hash() click to toggle source
# File lib/facter/resolvers/disk.rb, line 48
def build_disks_hash
  @fact_list[:disks] = {}
  directories = Dir.entries(DIR).reject { |dir| dir =~ /\.+/ }
  directories.each { |disk| @fact_list[:disks].merge!(disk => {}) }
  @fact_list[:disks].select! { |disk, _fact| File.readable?(File.join(DIR, disk, 'device')) }
end
construct_size(facts, value) click to toggle source
# File lib/facter/resolvers/disk.rb, line 55
def construct_size(facts, value)
  value = value.to_i * 512
  facts[:size_bytes] = value
  facts[:size] = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(value)
end
post_resolve(fact_name, _options) click to toggle source
# File lib/facter/resolvers/disk.rb, line 17
def post_resolve(fact_name, _options)
  @fact_list.fetch(fact_name) { read_facts(fact_name) }
end
read_facts(fact_name) click to toggle source
# File lib/facter/resolvers/disk.rb, line 21
def read_facts(fact_name)
  build_disks_hash

  FILE_PATHS.each do |key, file|
    @fact_list[:disks].each do |disk, value|
      file_path = File.join(DIR, disk, file)

      result = Facter::Util::FileHelper.safe_read(file_path).strip
      next if result.empty?

      value[key] = case key
                   when :size
                     # Linux always considers sectors to be 512 bytes long
                     # independently of the devices real block size.
                     construct_size(value, result)
                   when :type
                     result == '0' ? 'ssd' : 'hdd'
                   else
                     result
                   end
    end
  end

  @fact_list[:disks] = nil if @fact_list[:disks].empty?
  @fact_list[fact_name]
end