(#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>
Jacob Helwig
13 years ago
20 | 20 | # Used the ipaddress fact that is already part of |
21 | 21 | # Facter as a template. |
22 | 22 | |
23 | def get_address_after_token(output, token, return_first=false) | |
24 | ip = nil | |
25 | ||
26 | output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match| | |
27 | match = match.first | |
28 | unless match =~ /fe80.*/ or match == "::1" | |
29 | ip = match | |
30 | break if return_first | |
31 | end | |
32 | end | |
33 | ||
34 | ip | |
35 | end | |
36 | ||
23 | 37 | Facter.add(:ipaddress6) do |
24 | 38 | confine :kernel => :linux |
25 | 39 | setcode do |
26 | ip = nil | |
27 | 40 | output = Facter::Util::Resolution.exec('/sbin/ifconfig') |
28 | 41 | |
29 | output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str| | |
30 | str = str.to_s | |
31 | unless str =~ /fe80.*/ or str == "::1" | |
32 | ip = str | |
33 | end | |
34 | } | |
35 | ||
36 | ip | |
37 | ||
42 | get_address_after_token(output, 'inet6 addr:') | |
38 | 43 | end |
39 | 44 | end |
40 | 45 | |
42 | 47 | confine :kernel => %w{SunOS} |
43 | 48 | setcode do |
44 | 49 | output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a') |
45 | ip = nil | |
46 | 50 | |
47 | output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str| | |
48 | str = str.to_s | |
49 | unless str =~ /fe80.*/ or str == "::1" | |
50 | ip = str | |
51 | end | |
52 | } | |
53 | ||
54 | ip | |
55 | ||
51 | get_address_after_token(output, 'inet6') | |
56 | 52 | end |
57 | 53 | end |
58 | 54 | |
60 | 56 | confine :kernel => %w{Darwin FreeBSD OpenBSD} |
61 | 57 | setcode do |
62 | 58 | output = Facter::Util::Resolution.exec('/sbin/ifconfig -a') |
63 | ip = nil | |
64 | 59 | |
65 | output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str| | |
66 | str = str.to_s | |
67 | unless str =~ /fe80.*/ or str == "::1" | |
68 | ip = str | |
69 | break | |
70 | end | |
71 | end | |
72 | ||
73 | ip | |
60 | get_address_after_token(output, 'inet6', true) | |
74 | 61 | end |
75 | 62 | end |
76 |