summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorroot <root@absinthe.lovedthanlost.net>2007-09-16 10:13:58 +1000
committerroot <root@absinthe.lovedthanlost.net>2007-09-16 10:13:58 +1000
commitc5e6f602ae71d43ec58b65ec6b2f4f540bc27649 (patch)
tree46c3cf499758c6a19d2cd2b81d6f4748c2fa3e92 /lib
parenta4698cedb19349f0763e0956f2fc14169eee2df2 (diff)
downloadfacter-c5e6f602ae71d43ec58b65ec6b2f4f540bc27649.tar.gz
facter-c5e6f602ae71d43ec58b65ec6b2f4f540bc27649.tar.xz
facter-c5e6f602ae71d43ec58b65ec6b2f4f540bc27649.zip
Adjusted :kernel confine to make it more in line with others
Replaced initial ipmess.rb with updated version and added BSD support
Diffstat (limited to 'lib')
-rw-r--r--lib/facter.rb2
-rw-r--r--lib/facter/ipmess.rb76
2 files changed, 59 insertions, 19 deletions
diff --git a/lib/facter.rb b/lib/facter.rb
index e9fe58d..802f848 100644
--- a/lib/facter.rb
+++ b/lib/facter.rb
@@ -1004,7 +1004,7 @@ class Facter
end
end
Facter.add(:ipaddress) do
- confine :kernel => :NetBSD
+ confine :kernel => %w{NetBSD}
setcode do
ip = nil
output = %x{/sbin/ifconfig -a}
diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb
index c7d8214..777084f 100644
--- a/lib/facter/ipmess.rb
+++ b/lib/facter/ipmess.rb
@@ -2,8 +2,9 @@
# ipmess.rb
# Try to get additional Facts about the machine's network interfaces on Linux
#
-# Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
-#
+# Original concept Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
+# Update and *BSD support (C) 2007 James Turnbull <james@lovedthanlost.net>
+#
# 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)
@@ -17,29 +18,68 @@
#
if Facter.kernel == "Linux"
- output = %x{/sbin/ifconfig -a}
- tmp1 = nil
- tmp2 = nil
- tmp3 = nil
- test = {}
- output.each {|s|
- tmp1 = s.split(" ")[0] if s !~ /^ /
- tmp2 = $1 if s =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/
- tmp3 = $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 && tmp3 != nil
- test["ipaddress_" + tmp1] = tmp2
- test["macaddress_" + tmp1] = tmp3
- tmp1 = nil
- tmp2 = nil
- tmp3 = nil
- end
+
+ output = %x{/sbin/ifconfig -a}
+ int = nil
+ output.scan(/^(\w+)(\d+)/) { |str|
+ output_int = %x{/sbin/ifconfig #{str}}
+ int = "#{str}"
+ 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"
+ test["ipaddress_" + int] = tmp1
+ test["macaddress_" + int] = tmp2
+ int = nil
+ tmp1 = nil
+ tmp2 = nil
+ end
}
test.each{|name,fact|
Facter.add(name) do
confine :kernel => :linux
setcode do
fact
+ 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}"
+ 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"
+ test["ipaddress_" + int] = tmp1
+ test["macaddress_" + int] = tmp2
+ int = nil
+ tmp1 = nil
+ tmp2 = nil
+ end
+ }
+ test.each{|name,fact|
+ Facter.add(name) do
+ confine :kernel => :linux
+ setcode do
+ fact
end
end
+ }
}
end
+