diff options
author | James Turnbull <james@lovedthanlost.net> | 2007-11-08 08:20:37 +1100 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2007-11-08 08:20:37 +1100 |
commit | 85fbf8f5dca8ff144122b3b6ef685ad0d6c08a19 (patch) | |
tree | 190a239b54052b60ba63ec1adc3300eae286f232 | |
parent | be7c30b60414144d4238263fed5586283b30ebea (diff) | |
download | facter-85fbf8f5dca8ff144122b3b6ef685ad0d6c08a19.tar.gz facter-85fbf8f5dca8ff144122b3b6ef685ad0d6c08a19.tar.xz facter-85fbf8f5dca8ff144122b3b6ef685ad0d6c08a19.zip |
Added index to imess.rb fixing Ticket #43.
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | lib/facter/ipmess.rb | 34 |
2 files changed, 21 insertions, 15 deletions
@@ -2,6 +2,8 @@ Fixed ticket #44 and allowed support for Xen multiple interfaces and aliased interfaces. Supports both Linux and *BSD. + Added interfaces fact to add as index for ip/MAC address facts + 1.3.8: Fixed Rdoc::usage bug on CentOS 5 - closed Puppet #753 and Facter #40 diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb index 349d523..919d944 100644 --- a/lib/facter/ipmess.rb +++ b/lib/facter/ipmess.rb @@ -17,18 +17,24 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA # +Facter.add(:interfaces) do + setcode do + output = %x{/sbin/ifconfig -a} + int = nil + int = output.scan(/(^\w+[.:]?\d+)/).join(" ") + end +end + if Facter.kernel == "Linux" - output = %x{/sbin/ifconfig -a} - int = nil - output.scan(/^(\w+)(\.|:?)(\d+)/) { |str| - output_int = %x{/sbin/ifconfig #{str}} - int = "#{str}" + interfaces = nil + interfaces = Facter.interfaces.split(" ") + interfaces.each do |int| + output_int = %x{/sbin/ifconfig #{int}} tmp1 = nil tmp2 = nil test = {} output_int.each { |s| - int = "#{str}" tmp1 = $1 if s =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ tmp2 = $1 if s =~ /(?:ether|HWaddr) (\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/ if tmp1 != nil && tmp2 != nil && int != "lo" @@ -38,7 +44,7 @@ if Facter.kernel == "Linux" tmp1 = nil tmp2 = nil end - } + } test.each{|name,fact| Facter.add(name) do confine :kernel => :linux @@ -47,21 +53,19 @@ if Facter.kernel == "Linux" end end } - } + end end if Facter.kernel == "FreeBSD" || Facter.kernel == "OpenBSD" || Facter.kernel == "NetBSD" - output = %x{/sbin/ifconfig -a} - int = nil - output.scan(/^(\w+)(\.|:?)(\d+):/) { |str| - output_int = %x{/sbin/ifconfig #{str}} - int = "#{str}" + interfaces = nil + interfaces = Facter.interfaces.split(" ") + interfaces.each do |int| + output_int = %x{/sbin/ifconfig #{int}} tmp1 = nil tmp2 = nil test = {} output_int.each { |s| - int = "#{str}" tmp1 = $1 if s =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ tmp2 = $1 if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ if tmp1 != nil && tmp2 != nil && int != "lo" @@ -80,6 +84,6 @@ if Facter.kernel == "FreeBSD" || Facter.kernel == "OpenBSD" || Facter.kernel == end end } - } + end end |