diff options
author | James Turnbull <james@lovedthanlost.net> | 2007-12-09 19:38:04 +1100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2007-12-09 19:38:04 +1100 |
commit | 2af364c1837f4aacfe1aab5b78d238e3a997f099 (patch) | |
tree | 580758b12fdaec84730d95f6de2038fb4849f790 | |
parent | 85fbf8f5dca8ff144122b3b6ef685ad0d6c08a19 (diff) | |
download | facter-2af364c1837f4aacfe1aab5b78d238e3a997f099.tar.gz facter-2af364c1837f4aacfe1aab5b78d238e3a997f099.tar.xz facter-2af364c1837f4aacfe1aab5b78d238e3a997f099.zip |
Added Mandrake support for operatingsystem fact - closed ticket #47
Fixed ticket #45
Added netmask.rb closing ticket #46
-rw-r--r-- | CHANGELOG | 6 | ||||
-rw-r--r-- | lib/facter.rb | 2 | ||||
-rw-r--r-- | lib/facter/manufacturer.rb | 2 | ||||
-rw-r--r-- | lib/facter/netmask.rb | 46 |
4 files changed, 55 insertions, 1 deletions
@@ -4,6 +4,12 @@ Added interfaces fact to add as index for ip/MAC address facts + Added Mandrake support for operatingsystem fact - closed ticket #47 + + Fixed ticket #45 + + Added netmask.rb closing ticket #46 + 1.3.8: Fixed Rdoc::usage bug on CentOS 5 - closed Puppet #753 and Facter #40 diff --git a/lib/facter.rb b/lib/facter.rb index daa9efa..1c8e8ff 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -656,6 +656,8 @@ class Facter "Fedora" elsif FileTest.exists?("/etc/mandriva-release") "Mandriva" + elsif FileTest.exists?("/etc/mandrake-release") + "Mandrake" elsif FileTest.exists?("/etc/redhat-release") txt = File.read("/etc/redhat-release") if txt =~ /centos/i diff --git a/lib/facter/manufacturer.rb b/lib/facter/manufacturer.rb index be36871..9007539 100644 --- a/lib/facter/manufacturer.rb +++ b/lib/facter/manufacturer.rb @@ -21,7 +21,7 @@ module Facter::Manufacturer unless type next end - @data[type][$1] = $2 + @data[type][$1] = $2.strip end end end diff --git a/lib/facter/netmask.rb b/lib/facter/netmask.rb new file mode 100644 index 0000000..1feb406 --- /dev/null +++ b/lib/facter/netmask.rb @@ -0,0 +1,46 @@ +# netmask.rb -- find the netmask of the primary ipaddress +# Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at> +# Copyright (C) 2007 Mark 'phips' Phillips +# See LICENSE for the full license granted to you. +# 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.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 + +Facter.add("netmask") do + confine :kernel => [ :sunos, :linux ] + setcode do + get_netmask + end +end + |