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 /lib/facter/util | |
| parent | a12d3d8bbf7ef6b8cb867237f3709f948b266373 (diff) | |
| parent | d9bd38835f98af5925f33e0f43adbbf89d61f1db (diff) | |
Merge branch 'master' of git://github.com/jamtur01/facter
Diffstat (limited to 'lib/facter/util')
| -rw-r--r-- | lib/facter/util/manufacturer.rb | 65 | ||||
| -rw-r--r-- | lib/facter/util/netmask.rb | 36 |
2 files changed, 57 insertions, 44 deletions
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 |
