summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Turnbull <james@lovedthanlost.net>2007-09-13 13:38:18 +1000
committerJames Turnbull <james@lovedthanlost.net>2007-09-13 13:38:18 +1000
commit8b08d5fca8809dfa68c353b9ba9526abb600ef0e (patch)
treeaeae62e95a25376d577236428a6e93c4bf9d755b
parent611337521e72c4bce4d52bea110abaaa348ff034 (diff)
downloadfacter-8b08d5fca8809dfa68c353b9ba9526abb600ef0e.tar.gz
facter-8b08d5fca8809dfa68c353b9ba9526abb600ef0e.tar.xz
facter-8b08d5fca8809dfa68c353b9ba9526abb600ef0e.zip
Added support to return multiple interfaces and their IP addresses as facts. Existing ipaddress fact which returns IP address of first interface on node is still available. Currently Linux only. Closes #6
-rw-r--r--lib/facter/ipmess.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb
new file mode 100644
index 0000000..c7d8214
--- /dev/null
+++ b/lib/facter/ipmess.rb
@@ -0,0 +1,45 @@
+#
+# ipmess.rb
+# Try to get additional Facts about the machine's network interfaces on Linux
+#
+# Copyright (C) 2007 psychedelys <psychedelys@gmail.com>
+#
+# 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
+#
+
+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
+ }
+ test.each{|name,fact|
+ Facter.add(name) do
+ confine :kernel => :linux
+ setcode do
+ fact
+ end
+ end
+ }
+end