From 8b08d5fca8809dfa68c353b9ba9526abb600ef0e Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 13 Sep 2007 13:38:18 +1000 Subject: 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 --- lib/facter/ipmess.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/facter/ipmess.rb 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 +# +# 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 -- cgit