class Facter::Resolvers::Aix::Disks

Private Class Methods

compute_size(size_hash) click to toggle source
# File lib/facter/resolvers/aix/disks.rb, line 49
def compute_size(size_hash)
  physical_partitions = size_hash['TOTAL PPs'].to_i + size_hash['FREE PPs'].to_i
  size_physical_partition = size_hash['PP SIZE']
  exp = if size_physical_partition[/mega/]
          Facter::Util::Aix::InfoExtractor::MEGABYTES_EXPONENT
        else
          Facter::Util::Aix::InfoExtractor::GIGABYTES_EXPONENT
        end
  size_physical_partition.to_i * physical_partitions * exp
end
execute_lspv(fact_name) click to toggle source
# File lib/facter/resolvers/aix/disks.rb, line 16
def execute_lspv(fact_name)
  result = Facter::Core::Execution.execute('lspv', logger: log)

  return if result.empty?

  @fact_list[:disks] = {}

  result.each_line do |line|
    disk_name = line.split(' ')[0].strip
    size = find_size(disk_name)
    @fact_list[:disks][disk_name] = size if size
  end

  @fact_list[fact_name]
end
find_size(name) click to toggle source
# File lib/facter/resolvers/aix/disks.rb, line 32
def find_size(name)
  stdout = Facter::Core::Execution.execute("lspv #{name}", logger: log)

  return if stdout.empty?

  info_size = Facter::Util::Aix::InfoExtractor.extract(stdout, :lspv)

  return unless info_size['PV STATE']

  size_bytes = compute_size(info_size)

  {
    size_bytes: size_bytes,
    size: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes)
  }
end
post_resolve(fact_name, _options) click to toggle source
# File lib/facter/resolvers/aix/disks.rb, line 12
def post_resolve(fact_name, _options)
  @fact_list.fetch(fact_name) { execute_lspv(fact_name) }
end