diff options
author | James Turnbull <james@lovedthanlost.net> | 2008-05-22 17:39:04 +1000 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2008-05-22 17:39:04 +1000 |
commit | f9961c705f56229ccd0151cda87316ec73a8675c (patch) | |
tree | 18dd889cab82d63fde2ccfbbfece3c47b00562b0 | |
parent | 7e84cdb0a2a951eb3eb002f8846bf219c23cb384 (diff) | |
download | facter-f9961c705f56229ccd0151cda87316ec73a8675c.tar.gz facter-f9961c705f56229ccd0151cda87316ec73a8675c.tar.xz facter-f9961c705f56229ccd0151cda87316ec73a8675c.zip |
Fixes for ticket #60
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | lib/facter/manufacturer.rb | 15 | ||||
-rw-r--r-- | lib/facter/util/manufacturer.rb | 65 |
3 files changed, 27 insertions, 55 deletions
@@ -1,4 +1,6 @@ ?: + Updated dmidecode facts fixing ticket #60 + Added AIX support for some facts Add lsbmajdistrelease fact for CentOS and Red Hat diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index 0c74607..1fbc38d 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -4,14 +4,7 @@ # require 'facter/util/manufacturer' - -{:SerialNumber => "Serial Number", - :Manufacturer => "Manufacturer", - :ProductName=> "Product Name"}.each do |fact, name| - Facter.add(fact) do - confine :kernel => :linux - setcode do - Facter::Manufacturer.dmi_find_system_info(name) - end - end -end + +query = { 'System Information' => [ 'Manufacturer:', 'Product Name:' , 'Serial Number:'], 'Chassis Information' => 'Type:'} + +Facter::Manufacturer.dmi_find_system_info(query) diff --git a/lib/facter/util/manufacturer.rb b/lib/facter/util/manufacturer.rb index 18db1c9..b48ffc7 100644 --- a/lib/facter/util/manufacturer.rb +++ b/lib/facter/util/manufacturer.rb @@ -1,49 +1,26 @@ -## mamufacturer.rb -## Support methods for manufacturer specific facts -## -## This program is free software; you can redistribute it and/or -## modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation (version 2 of the License) -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## You should have received a copy of the GNU General Public License -## along with this program; if not, write to the Free Software -## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA -## - +# mamufacturer.rb +# Support methods for manufacturer specific facts module Facter::Manufacturer - def self.dmi_find_system_info(name) - return nil unless FileTest.exists?("/usr/sbin/dmidecode") - - # Do not run the command more than every five seconds. - unless defined?(@data) and defined?(@time) and (Time.now.to_i - @time.to_i < 5) - @data = {} - type = nil - @time = Time.now - # It's *much* easier to just parse the whole darn file than - # to just match a chunk of it. - %x{/usr/sbin/dmidecode 2>/dev/null}.split("\n").each do |line| - case line - when /^(\S.+)$/ - type = $1.chomp - @data[type] ||= {} - when /^\s+(\S.+): (\S.*)$/ - unless type - next - end - @data[type][$1] = $2.strip - end - end - end + def self.dmi_find_system_info(name) + return nil unless FileTest.exists?("/usr/sbin/dmidecode") - if data = @data["System Information"] - data[name] - else - nil - end - end + output=%x{/usr/sbin/dmidecode 2>/dev/null} + name.each_pair do |key,v| + v.each do |value| + output.split("Handle").each do |line| + if line =~ /#{key}/ and line =~ /#{value} (\w.*)\n*./ + result = $1 + Facter.add(value.chomp(':').gsub(' ','')) do + confine :kernel => :linux + setcode do + result + end + end + end + end + end + end +end end |