diff options
author | Daniel Pittman <daniel@rimspace.net> | 2011-02-01 17:38:46 -0800 |
---|---|---|
committer | Daniel Pittman <daniel@rimspace.net> | 2011-02-17 14:32:10 -0800 |
commit | ea2948395e4eed1a33f767df60ae28133c94442e (patch) | |
tree | edc12a0307e0b5e475ea06215bd930cf7f81cba1 | |
parent | 77eb512a85619764a713744108116756969c6c3d (diff) | |
download | facter-ea2948395e4eed1a33f767df60ae28133c94442e.tar.gz facter-ea2948395e4eed1a33f767df60ae28133c94442e.tar.xz facter-ea2948395e4eed1a33f767df60ae28133c94442e.zip |
(#2270) add IPv6 support to facter core.
Now that IPocalypse has happened, IPv6 support in Facter core would be nice to
have. So, we add the appropriate code to start handling that.
The ipaddress6 fact as supplied included some smart code to try determining
the "primary" address using DNS to resolve the AAAA record for the host FQDN.
While this was smart, it actually didn't work: facter prefers the longest
confine list, so the *stupid* mechanisms that were kernel-specific would
override the smarter and more portable mechanisms.
We strip that code out for now, which also brings this into line with the
existing ipaddress fact; improving both would be good, but it should be uniform.
Paired-With: Matt Robinson <matt@puppetlabs.com>
Paired-With: Max Martin <max@puppetlabs.com>
-rw-r--r-- | lib/facter/interfaces.rb | 2 | ||||
-rw-r--r-- | lib/facter/ipaddress6.rb | 68 | ||||
-rw-r--r-- | lib/facter/util/ip.rb | 3 |
3 files changed, 72 insertions, 1 deletions
diff --git a/lib/facter/interfaces.rb b/lib/facter/interfaces.rb index 1239215..4fbaef1 100644 --- a/lib/facter/interfaces.rb +++ b/lib/facter/interfaces.rb @@ -22,7 +22,7 @@ Facter::Util::IP.get_interfaces.each do |interface| # Make a fact for each detail of each interface. Yay. # There's no point in confining these facts, since we wouldn't be able to create # them if we weren't running on a supported platform. - %w{ipaddress macaddress netmask}.each do |label| + %w{ipaddress ipaddress6 macaddress netmask}.each do |label| Facter.add(label + "_" + Facter::Util::IP.alphafy(interface)) do setcode do Facter::Util::IP.get_interface_value(interface, label) diff --git a/lib/facter/ipaddress6.rb b/lib/facter/ipaddress6.rb new file mode 100644 index 0000000..547d636 --- /dev/null +++ b/lib/facter/ipaddress6.rb @@ -0,0 +1,68 @@ +# Cody Herriges <c.a.herriges@gmail.com> +# +# Used the ipaddress fact that is already part of +# Facter as a template. + +# OS dependant code that parses the output of various networking +# tools and currently not very intelligent. Returns the first +# non-loopback and non-linklocal address found in the ouput unless +# a default route can be mapped to a routeable interface. Guessing +# an interface is currently only possible with BSD type systems +# to many assumptions have to be made on other platforms to make +# this work with the current code. Most code ported or modeled +# after the ipaddress fact for the sake of similar functionality +# and familiar mechanics. +Facter.add(:ipaddress6) do + confine :kernel => :linux + setcode do + ip = nil + output = Facter::Util::Resolution.exec('/sbin/ifconfig') + + output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str| + str = str.to_s + unless str =~ /fe80.*/ or str == "::1" + ip = str + end + } + + ip + + end +end + +Facter.add(:ipaddress6) do + confine :kernel => %w{SunOS} + setcode do + output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a') + ip = nil + + output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str| + str = str.to_s + unless str =~ /fe80.*/ or str == "::1" + ip = str + end + } + + ip + + end +end + +Facter.add(:ipaddress6) do + confine :kernel => %w{Darwin FreeBSD OpenBSD} + setcode do + output = Facter::Util::Resolution.exec('/sbin/ifconfig -a') + ip = nil + + output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str| + str = str.to_s + unless str =~ /fe80.*/ or str == "::1" + ip = str + break + end + end + + ip + end +end + diff --git a/lib/facter/util/ip.rb b/lib/facter/util/ip.rb index 62d50a4..23eeb9c 100644 --- a/lib/facter/util/ip.rb +++ b/lib/facter/util/ip.rb @@ -6,17 +6,20 @@ module Facter::Util::IP REGEX_MAP = { :linux => { :ipaddress => /inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /inet6 addr: ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, :macaddress => /(?:ether|HWaddr)\s+(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/, :netmask => /Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/ }, :bsd => { :aliases => [:openbsd, :netbsd, :freebsd, :darwin, :"gnu/kfreebsd"], :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, :netmask => /netmask\s+0x(\w{8})/ }, :sunos => { :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/, + :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/, :macaddress => /(?:ether|lladdr)\s+(\w?\w:\w?\w:\w?\w:\w?\w:\w?\w:\w?\w)/, :netmask => /netmask\s+(\w{8})/ }, |