diff options
author | Luke Kanies <luke@madstop.com> | 2007-09-24 09:00:05 +0200 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-09-24 09:00:05 +0200 |
commit | cbf76f614895d8a1ba7d622ff48bdfaea10ade46 (patch) | |
tree | 3364ce4b0548873f5de68045a21610945365347e | |
parent | 00ab1f327f287795eb0dca49139abfc8574e5d37 (diff) | |
parent | 57c76dd4e72cc090ed5e96947f1926462338c5cb (diff) | |
download | facter-cbf76f614895d8a1ba7d622ff48bdfaea10ade46.tar.gz facter-cbf76f614895d8a1ba7d622ff48bdfaea10ade46.tar.xz facter-cbf76f614895d8a1ba7d622ff48bdfaea10ade46.zip |
Merge branch 'master' of /opt/rl/git/facter
-rw-r--r-- | CHANGELOG | 16 | ||||
-rwxr-xr-x | bin/facter | 1 | ||||
-rw-r--r-- | lib/facter.rb | 39 | ||||
-rw-r--r-- | lib/facter/ipmess.rb | 85 |
4 files changed, 139 insertions, 2 deletions
@@ -1,3 +1,19 @@ +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 + 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 @@ -49,6 +49,7 @@ require 'facter' $haveusage = true begin + require 'rdoc/ri/ri_paths' require 'rdoc/usage' rescue Exception $haveusage = false diff --git a/lib/facter.rb b/lib/facter.rb index 8a52a6a..e71eb0c 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 @@ -933,6 +935,20 @@ class Facter 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 ether = nil @@ -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} @@ -988,6 +1004,25 @@ class Facter end end Facter.add(:ipaddress) do + confine :kernel => %w{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 ip = nil diff --git a/lib/facter/ipmess.rb b/lib/facter/ipmess.rb new file mode 100644 index 0000000..abee8a2 --- /dev/null +++ b/lib/facter/ipmess.rb @@ -0,0 +1,85 @@ +# +# ipmess.rb +# Try to get additional Facts about the machine's network interfaces on Linux +# +# 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) +# 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} + 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 + |