\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/ohai-8.24.0/lib/ohai/common/

Viewing File: dmi.rb

#
# Author:: Kurt Yoder (ktyopscode@yoderhome.com)
# Copyright:: Copyright (c) 2010 Kurt Yoder
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module Ohai
  module Common
    module DMI
      # List of IDs and what they translate to
      # from 'man 8 dmidecode'
      # all-lowercase, all non-alphanumeric converted to '_'
      # 128-255 are 'oem_data_[id]'
      # Everything else is 'unknown'
      ID_TO_DESCRIPTION = {
        0 =>   "bios",
        1 =>   "system",
        2 =>   "base_board",
        3 =>   "chassis",
        4 =>   "processor",
        5 =>   "memory_controller",
        6 =>   "memory_module",
        7 =>   "cache",
        8 =>   "port_connector",
        9 =>   "system_slots",
        10 =>  "on_board_devices",
        11 =>  "oem_strings",
        12 =>  "system_configuration_options",
        13 =>  "bios_language",
        14 =>  "group_associations",
        15 =>  "system_event_log",
        16 =>  "physical_memory_array",
        17 =>  "memory_device",
        18 =>  "32_bit_memory_error",
        19 =>  "memory_array_mapped_address",
        20 =>  "memory_device_mapped_address",
        21 =>  "built_in_pointing_device",
        22 =>  "portable_battery",
        23 =>  "system_reset",
        24 =>  "hardware_security",
        25 =>  "system_power_controls",
        26 =>  "voltage_probe",
        27 =>  "cooling_device",
        28 =>  "temperature_probe",
        29 =>  "electrical_current_probe",
        30 =>  "out_of_band_remote_access",
        31 =>  "boot_integrity_services",
        32 =>  "system_boot",
        33 =>  "64_bit_memory_error",
        34 =>  "management_device",
        35 =>  "management_device_component",
        36 =>  "management_device_threshold_data",
        37 =>  "memory_channel",
        38 =>  "ipmi_device",
        39 =>  "power_supply",
        40 =>  "additional_information",
        41 =>  "onboard_devices_extended_information",
        42 =>  "management_controller_host_interfaces",
        126 => "disabled_entries",
        127 => "end_of_table_marker",
      }

      # 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.
      ID_TO_CAPTURE = [ 0, 1, 2, 3, 4, 6, 11 ]

      # look up DMI ID
      def id_lookup(id)
        begin
          id = id.to_i
          if (id >= 128) && (id <= 255)
            id = "oem_data_#{id}"
          elsif DMI::ID_TO_DESCRIPTION.has_key?(id)
            id = DMI::ID_TO_DESCRIPTION[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

      # 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
      def convenience_keys(dmi)
        dmi.each do |type, records|
          in_common = Mash.new
          next unless records.class.to_s == "Mash"
          next unless records.has_key?("all_records")
          records[:all_records].each do |record|
            record.each do |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]/, "_")
              value      = value.strip
              if in_common.has_key?(translated)
                in_common[translated] = nil unless in_common[translated] == value
              else
                in_common[translated] = value
              end
            end
          end
          in_common.each do |field, value|
            next if value == nil
            dmi[type][field] = value.strip
          end
        end
      end

      module_function :id_lookup, :convenience_keys
    end
  end
end