From 611337521e72c4bce4d52bea110abaaa348ff034 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 13 Sep 2007 08:51:11 +1000 Subject: Added macaddress fact support for FreeBSD and OpenBSD - closes #37 Added hardwareisa support for *BSD platforms - closed #38 Facter now detects the Mandriva distribution - closes #39 Facter now correctly detects ipaddress on NetBSD - closes #42 --- lib/facter.rb | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index 8a52a6a..e9fe58d 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -654,6 +654,8 @@ class Facter "Gentoo" elsif FileTest.exists?("/etc/fedora-release") "Fedora" + elsif FileTest.exists?("/etc/mandriva-release") + "Mandriva" elsif FileTest.exists?("/etc/redhat-release") txt = File.read("/etc/redhat-release") if txt =~ /centos/i @@ -917,7 +919,7 @@ class Facter Facter.add(:hardwareisa) do setcode 'uname -p', '/bin/sh' - confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo} + confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE Debian Gentoo FreeBSD OpenBSD NetBSD} end Facter.add(:macaddress) do @@ -932,6 +934,20 @@ class Facter end end + Facter.add(:macaddress) do + confine :operatingsystem => %w{FreeBSD OpenBSD} + setcode do + ether = [] + output = %x{/sbin/ifconfig} + output.each {|s| + if s =~ /(?:ether|lladdr)\s+(\w\w:\w\w:\w\w:\w\w:\w\w:\w\w)/ + ether.push($1) + end + } + ether[0] + end + end + Facter.add(:macaddress) do confine :kernel => :darwin setcode do @@ -969,7 +985,7 @@ class Facter end end Facter.add(:ipaddress) do - confine :kernel => %w{FreeBSD NetBSD OpenBSD solaris} + confine :kernel => %w{FreeBSD OpenBSD solaris} setcode do ip = nil output = %x{/sbin/ifconfig} @@ -987,6 +1003,25 @@ class Facter ip end end + Facter.add(:ipaddress) do + confine :kernel => :NetBSD + setcode do + ip = nil + output = %x{/sbin/ifconfig -a} + + output.split(/^\S/).each { |str| + if str =~ /inet ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end + end + } + + ip + end + end Facter.add(:ipaddress) do confine :kernel => %w{darwin} setcode do -- cgit 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 From a4698cedb19349f0763e0956f2fc14169eee2df2 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Thu, 13 Sep 2007 13:53:30 +1000 Subject: Updated CHANGELOG --- CHANGELOG | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 8a0d6de..43d3dac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,17 @@ +1.3.?: + Added support to return multiple interfaces and their IP addresses and + MAC addressess as facts. Returns interface_interfacename and + macaddress_interfacename. Existing ipaddress and macaddress facts are + unchanged and still returned. Currently Linux only. Closes #6. + + Added macaddress fact support for FreeBSD and OpenBSD - closes #37 + + Added hardwareisa support for *BSD platforms - closed #38 + + Facter now detects the Mandriva distribution - closes #39 + + Facter now correctly detects ipaddress on NetBSD - closes #42 + 1.3.7: A couple of small bugfixes, including fixing Facter.flush so it correctly flushes cached values, and the mac address fact only returns one -- cgit From c5e6f602ae71d43ec58b65ec6b2f4f540bc27649 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Sep 2007 10:13:58 +1000 Subject: Adjusted :kernel confine to make it more in line with others Replaced initial ipmess.rb with updated version and added BSD support --- CHANGELOG | 2 +- lib/facter.rb | 2 +- lib/facter/ipmess.rb | 76 +++++++++++++++++++++++++++++++++++++++------------- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 43d3dac..e5939a3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ Added support to return multiple interfaces and their IP addresses and MAC addressess as facts. Returns interface_interfacename and macaddress_interfacename. Existing ipaddress and macaddress facts are - unchanged and still returned. Currently Linux only. Closes #6. + unchanged and still returned. Supports bith Linux and BSD. Closes #6. Added macaddress fact support for FreeBSD and OpenBSD - closes #37 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 -# +# Original concept Copyright (C) 2007 psychedelys +# Update and *BSD support (C) 2007 James Turnbull +# # 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 + -- cgit From dce624579b327963cc1619e93020d3ccb59995bd Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Sun, 16 Sep 2007 10:26:45 +1000 Subject: Revert "Adjusted :kernel confine to make it more in line with others" This reverts commit c5e6f602ae71d43ec58b65ec6b2f4f540bc27649. --- CHANGELOG | 2 +- lib/facter.rb | 2 +- lib/facter/ipmess.rb | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e5939a3..43d3dac 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ Added support to return multiple interfaces and their IP addresses and MAC addressess as facts. Returns interface_interfacename and macaddress_interfacename. Existing ipaddress and macaddress facts are - unchanged and still returned. Supports bith Linux and BSD. Closes #6. + unchanged and still returned. Currently Linux only. Closes #6. Added macaddress fact support for FreeBSD and OpenBSD - closes #37 diff --git a/lib/facter.rb b/lib/facter.rb index 802f848..e71eb0c 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -1004,7 +1004,7 @@ class Facter end end Facter.add(:ipaddress) do - confine :kernel => %w{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 777084f..abee8a2 100644 --- a/lib/facter/ipmess.rb +++ b/lib/facter/ipmess.rb @@ -44,7 +44,7 @@ if Facter.kernel == "Linux" confine :kernel => :linux setcode do fact - end + end end } } @@ -52,16 +52,16 @@ 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}" + 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" @@ -71,7 +71,7 @@ if Facter.kernel == "FreeBSD" || Facter.kernel == "OpenBSD" || Facter.kernel == tmp1 = nil tmp2 = nil end - } + } test.each{|name,fact| Facter.add(name) do confine :kernel => :linux -- cgit From b28ce1bbda37d93d0bfd780f85ff39366f380af9 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 18 Sep 2007 11:33:22 +1000 Subject: Added require for rdoc/ri/ri_paths to address Puppet #753 and Facter #40 --- bin/facter | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/facter b/bin/facter index 3543a0a..1dec66b 100755 --- a/bin/facter +++ b/bin/facter @@ -49,6 +49,7 @@ require 'facter' $haveusage = true begin + require 'rdoc/ri/ri_paths' require 'rdoc/usage' rescue Exception $haveusage = false -- cgit From 57c76dd4e72cc090ed5e96947f1926462338c5cb Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Tue, 18 Sep 2007 13:06:39 +1000 Subject: Updated CHANGELOG --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 43d3dac..7f95a1e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,6 @@ 1.3.?: + Fixed Rdoc::usage bug on CentOS 5 - closed Puppet #753 and Facter #40 + Added support to return multiple interfaces and their IP addresses and MAC addressess as facts. Returns interface_interfacename and macaddress_interfacename. Existing ipaddress and macaddress facts are -- cgit