Puppet: System Administration Automated

Support

Ticket #1182: facter-manufacturer.patch

File facter-manufacturer.patch, 1.5 kB (added by dhill, 8 months ago)

Implement desired facts as nested hash

  • manufacturer.rb

    old new  
    22#            
    33     
    44module Facter::Manufacturer 
    5     def self.dmi_find_system_info(name
     5    def self.dmi_find_system_info(name, area
    66        return nil unless FileTest.exists?("/usr/sbin/dmidecode") 
    77 
    88        # Do not run the command more than every five seconds. 
     
    2626            end 
    2727        end 
    2828 
    29         if data = @data["System Information"
     29        if data = @data[area
    3030            data[name] 
    31         else 
     31       else 
    3232            nil 
    3333        end 
    3434    end 
    3535end          
    3636         
    37 # Add the facts to Facter 
     37# Define the sections and keys we want. 
     38sections_and_keys = {  
     39        "System Information" =>  
     40                {:SerialNumber => "Serial Number", :Manufacturer => "Manufacturer", :ProductName=> "Product Name"}, 
     41        "Chassis Information" => 
     42                {:ChassisType => "Type"}, 
     43        } 
    3844 
    39 {:SerialNumber => "Serial Number", 
    40  :Manufacturer => "Manufacturer", 
    41  :ProductName=> "Product Name"}.each do |fact, name| 
    42     Facter.add(fact) do 
    43         confine :kernel => :linux 
    44         setcode do 
    45             Facter::Manufacturer.dmi_find_system_info(name) 
    46         end 
    47     end   
     45# Add the facts to Facter 
     46sections_and_keys.each_pair do |section, dmikeys| 
     47        dmikeys.each do |fact, name| 
     48            Facter.add(fact) do 
     49                confine :kernel => :linux 
     50                setcode do 
     51                    Facter::Manufacturer.dmi_find_system_info(name, section) 
     52                end 
     53            end   
     54        end 
    4855end