diff options
author | Luke Kanies <luke@madstop.com> | 2008-06-17 10:59:52 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-06-17 10:59:52 -0500 |
commit | ce7b74c6a5094661f2af63dbdf992a12652f7778 (patch) | |
tree | 9b6dfa55a434f2e9b017ef007753bcb8d026b127 /lib/facter/ipaddress.rb | |
parent | 2ee5d29548b48a3c81f574c2be84db60f6ff306a (diff) | |
download | facter-ce7b74c6a5094661f2af63dbdf992a12652f7778.tar.gz facter-ce7b74c6a5094661f2af63dbdf992a12652f7778.tar.xz facter-ce7b74c6a5094661f2af63dbdf992a12652f7778.zip |
Rejustifying all of the whitespace in the facts, yay.
Diffstat (limited to 'lib/facter/ipaddress.rb')
-rw-r--r-- | lib/facter/ipaddress.rb | 270 |
1 files changed, 135 insertions, 135 deletions
diff --git a/lib/facter/ipaddress.rb b/lib/facter/ipaddress.rb index cf80c0c..942c134 100644 --- a/lib/facter/ipaddress.rb +++ b/lib/facter/ipaddress.rb @@ -1,151 +1,151 @@ - Facter.add(:ipaddress, :ldapname => "iphostnumber") do - setcode do - require 'resolv' - - begin - if hostname = Facter.value(:hostname) - ip = Resolv.getaddress(hostname) - unless ip == "127.0.0.1" - ip - end - else - nil - end - rescue Resolv::ResolvError - nil - rescue NoMethodError # i think this is a bug in resolv.rb? - nil +Facter.add(:ipaddress, :ldapname => "iphostnumber") do + setcode do + require 'resolv' + + begin + if hostname = Facter.value(:hostname) + ip = Resolv.getaddress(hostname) + unless ip == "127.0.0.1" + ip end + else + nil end + rescue Resolv::ResolvError + nil + rescue NoMethodError # i think this is a bug in resolv.rb? + nil end - - Facter.add(:ipaddress) do - setcode do - if hostname = Facter.value(:hostname) - # we need Hostname to exist for this to work - host = nil - if host = Facter::Util::Resolution.exec("host #{hostname}") - host = host.chomp.split(/\s/) - if defined? list[-1] and - list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ - list[-1] - end - else - nil - end - else - nil + end +end + +Facter.add(:ipaddress) do + setcode do + if hostname = Facter.value(:hostname) + # we need Hostname to exist for this to work + host = nil + if host = Facter::Util::Resolution.exec("host #{hostname}") + host = host.chomp.split(/\s/) + if defined? list[-1] and + list[-1] =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/ + list[-1] end + else + nil end + else + nil end + end +end - Facter.add(:ipaddress) do - confine :kernel => :linux - setcode do - ip = nil - output = %x{/sbin/ifconfig} - - output.split(/^\S/).each { |str| - if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ - tmp = $1 - unless tmp =~ /127\./ - ip = tmp - break - end - end - } - - ip +Facter.add(:ipaddress) do + confine :kernel => :linux + setcode do + ip = nil + output = %x{/sbin/ifconfig} + + output.split(/^\S/).each { |str| + if str =~ /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ + tmp = $1 + unless tmp =~ /127\./ + ip = tmp + break + end end - end - - Facter.add(:ipaddress) do - confine :kernel => %w{FreeBSD OpenBSD solaris} - setcode do - ip = nil - output = %x{/sbin/ifconfig} - - 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 + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{FreeBSD OpenBSD solaris} + setcode do + ip = nil + output = %x{/sbin/ifconfig} + + 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 - 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 + ip + 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 + iface = "" + output = %x{/usr/sbin/netstat -rn} + if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/ + iface = $1 + else + warn "Could not find a default route. Using first non-loopback interface" + end + if(iface != "") + output = %x{/sbin/ifconfig #{iface}} + else + output = %x{/sbin/ifconfig} end - Facter.add(:ipaddress) do - confine :kernel => %w{darwin} - setcode do - ip = nil - iface = "" - output = %x{/usr/sbin/netstat -rn} - if output =~ /^default\s*\S*\s*\S*\s*\S*\s*\S*\s*(\S*).*/ - iface = $1 - else - warn "Could not find a default route. Using first non-loopback interface" + 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 - if(iface != "") - output = %x{/sbin/ifconfig #{iface}} - else - output = %x{/sbin/ifconfig} - end - - 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{AIX} - setcode do - ip = nil - output = %x{/usr/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 + } + + ip + end +end + +Facter.add(:ipaddress) do + confine :kernel => %w{AIX} + setcode do + ip = nil + output = %x{/usr/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 - end + } + + ip + end +end |