diff options
author | Luke Kanies <luke@madstop.com> | 2008-06-02 18:54:43 -0700 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-06-02 18:54:43 -0700 |
commit | 3bdaeeec338faee538ac6f60087dcef1016ab8fb (patch) | |
tree | 79d808d8098e5959d9746f67bb234caa707d748e | |
parent | a12d3d8bbf7ef6b8cb867237f3709f948b266373 (diff) | |
parent | d9bd38835f98af5925f33e0f43adbbf89d61f1db (diff) | |
download | facter-3bdaeeec338faee538ac6f60087dcef1016ab8fb.tar.gz facter-3bdaeeec338faee538ac6f60087dcef1016ab8fb.tar.xz facter-3bdaeeec338faee538ac6f60087dcef1016ab8fb.zip |
Merge branch 'master' of git://github.com/jamtur01/facter
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | lib/facter/manufacturer.rb | 15 | ||||
-rw-r--r-- | lib/facter/netmask.rb | 35 | ||||
-rw-r--r-- | lib/facter/util/manufacturer.rb | 65 | ||||
-rw-r--r-- | lib/facter/util/netmask.rb | 36 |
5 files changed, 65 insertions, 88 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/netmask.rb b/lib/facter/netmask.rb index 140f8f1..309ef63 100644 --- a/lib/facter/netmask.rb +++ b/lib/facter/netmask.rb @@ -6,43 +6,12 @@ # idea and originial source by Mark 'phips' Phillips # -def get_netmask - netmask = nil; - ipregex = %r{(\d{1,3}\.){3}\d{1,3}} - - ops = nil - case Facter.value(:kernel) - when 'Linux' - ops = { - :ifconfig => '/sbin/ifconfig', - :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x, - :munge => nil, - } - when 'SunOS' - ops = { - :ifconfig => '/usr/sbin/ifconfig -a', - :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x, - :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } - } - end - - %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line| - matches = line.match(ops[:regex]) - if !matches.nil? - if ops[:munge].nil? - netmask = matches[1] - else - netmask = ops[:munge].call(matches[1]) - end - end - end - netmask -end +require 'facter/util/netmask' Facter.add("netmask") do confine :kernel => [ :sunos, :linux ] setcode do - get_netmask + Facter::NetMask.get_netmask end end 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 diff --git a/lib/facter/util/netmask.rb b/lib/facter/util/netmask.rb new file mode 100644 index 0000000..71696ad --- /dev/null +++ b/lib/facter/util/netmask.rb @@ -0,0 +1,36 @@ +module Facter::NetMask + +def self.get_netmask + netmask = nil; + ipregex = %r{(\d{1,3}\.){3}\d{1,3}} + + ops = nil + case Facter.value(:kernel) + when 'Linux' + ops = { + :ifconfig => '/sbin/ifconfig', + :regex => %r{\s+ inet\saddr: #{Facter.ipaddress} .*? Mask: (#{ipregex})}x, + :munge => nil, + } + when 'SunOS' + ops = { + :ifconfig => '/usr/sbin/ifconfig -a', + :regex => %r{\s+ inet\s+? #{Facter.ipaddress} \+? mask (\w{8})}x, + :munge => Proc.new { |mask| mask.scan(/../).collect do |byte| byte.to_i(16) end.join('.') } + } + end + + %x{#{ops[:ifconfig]}}.split(/\n/).collect do |line| + matches = line.match(ops[:regex]) + if !matches.nil? + if ops[:munge].nil? + netmask = matches[1] + else + netmask = ops[:munge].call(matches[1]) + end + end + end + netmask +end + +end |