summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Helwig <jacob@puppetlabs.com>2011-04-22 13:56:39 -0700
committerJacob Helwig <jacob@puppetlabs.com>2011-04-22 13:56:39 -0700
commit6b1cd16c7ef6ac78ffa85bfb81d193076db3e4c8 (patch)
tree33d38e9a00903f73e14261ef434c947cd7a18d45
parent6e02daa1ed56f9758226f4e640ec419395868728 (diff)
downloadfacter-6b1cd16c7ef6ac78ffa85bfb81d193076db3e4c8.tar.gz
facter-6b1cd16c7ef6ac78ffa85bfb81d193076db3e4c8.tar.xz
facter-6b1cd16c7ef6ac78ffa85bfb81d193076db3e4c8.zip
(#6614) Update ipaddress6 fact to work with Ruby 1.9
Calling #to_s on an Array such as ["foo"] in Ruby 1.9 will result in the string '["foo"]', instead of stringifying the element in the array which would have given the expected result of "foo". Since the element of the array we're dealing with is already a string, we can just grab it out of the array by using #first. Paired-with: Josh Cooper <josh@puppetlabs.com>
-rw-r--r--lib/facter/ipaddress6.rb48
1 files changed, 17 insertions, 31 deletions
diff --git a/lib/facter/ipaddress6.rb b/lib/facter/ipaddress6.rb
index b494b9d..db3805b 100644
--- a/lib/facter/ipaddress6.rb
+++ b/lib/facter/ipaddress6.rb
@@ -21,21 +21,26 @@
# Used the ipaddress fact that is already part of
# Facter as a template.
+def get_address_after_token(output, token, return_first=false)
+ ip = nil
+
+ output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match|
+ match = match.first
+ unless match =~ /fe80.*/ or match == "::1"
+ ip = match
+ break if return_first
+ end
+ end
+
+ ip
+end
+
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
-
+ get_address_after_token(output, 'inet6 addr:')
end
end
@@ -43,17 +48,8 @@ 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
+ get_address_after_token(output, 'inet6')
end
end
@@ -61,17 +57,7 @@ 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
+ get_address_after_token(output, 'inet6', true)
end
end
-