module Ohai::Common::DMI

Constants

IdToCapture

list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot See OHAI-260. When we can give the user a choice, this will be a default.

IdToDescription

List of IDs and what they translate to from 'man 8 dmidecode' all-lowercase, all non-alphanumeric converted to '_' 128-255 are 'oem_data_' Everything else is 'unknown'

Public Class Methods

convenience_keys(dmi) click to toggle source

create simplified convenience access keys for each record type for single occurrences of one type, copy to top level all fields and values for multiple occurrences of same type, copy to top level all fields and values that are common to all records

# File lib/ohai/common/dmi.rb, line 97
def convenience_keys(dmi)
  dmi.each{ |type, records|
    in_common = Mash.new
    next unless records.class.to_s == 'Mash'
    next unless records.has_key?('all_records')
    records[:all_records].each{ |record| 
      record.each{ |field, value| 
        next if value.class.to_s == 'Mash'
        next if field.to_s == 'application_identifier'
        next if field.to_s == 'size'
        next if field.to_s == 'record_id'
        translated = field.downcase.gsub(/[^a-z0-9]/, '_')
        if in_common.has_key?(translated)
          in_common[translated] = nil unless in_common[translated] == value
        else
          in_common[translated] = value
        end
      }
    }
    in_common.each{ |field, value|
      next if value == nil
      dmi[type][field] = value
    }
  }
end
id_lookup(id) click to toggle source

look up DMI ID

# File lib/ohai/common/dmi.rb, line 77
def id_lookup(id)
  begin
    id = id.to_i
    if (id >= 128) and (id <= 255)
      id = "oem_data_#{id}"
    elsif DMI::IdToDescription.has_key?(id)
      id = DMI::IdToDescription[id]
    else
      Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
      id = 'unknown'
    end
  rescue
    Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
    id
  end
end

Private Instance Methods

convenience_keys(dmi) click to toggle source

create simplified convenience access keys for each record type for single occurrences of one type, copy to top level all fields and values for multiple occurrences of same type, copy to top level all fields and values that are common to all records

# File lib/ohai/common/dmi.rb, line 97
def convenience_keys(dmi)
  dmi.each{ |type, records|
    in_common = Mash.new
    next unless records.class.to_s == 'Mash'
    next unless records.has_key?('all_records')
    records[:all_records].each{ |record| 
      record.each{ |field, value| 
        next if value.class.to_s == 'Mash'
        next if field.to_s == 'application_identifier'
        next if field.to_s == 'size'
        next if field.to_s == 'record_id'
        translated = field.downcase.gsub(/[^a-z0-9]/, '_')
        if in_common.has_key?(translated)
          in_common[translated] = nil unless in_common[translated] == value
        else
          in_common[translated] = value
        end
      }
    }
    in_common.each{ |field, value|
      next if value == nil
      dmi[type][field] = value
    }
  }
end
id_lookup(id) click to toggle source

look up DMI ID

# File lib/ohai/common/dmi.rb, line 77
def id_lookup(id)
  begin
    id = id.to_i
    if (id >= 128) and (id <= 255)
      id = "oem_data_#{id}"
    elsif DMI::IdToDescription.has_key?(id)
      id = DMI::IdToDescription[id]
    else
      Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
      id = 'unknown'
    end
  rescue
    Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
    id
  end
end