facter 1.5.9 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (79) hide show
  1. data/CHANGELOG +39 -0
  2. data/LICENSE +11 -13
  3. data/README.md +24 -0
  4. data/bin/facter +2 -2
  5. data/conf/redhat/facter.spec +5 -2
  6. data/conf/solaris/pkginfo +1 -1
  7. data/install.rb +1 -1
  8. data/lib/facter.rb +12 -15
  9. data/lib/facter/Cfkey.rb +11 -11
  10. data/lib/facter/application.rb +3 -4
  11. data/lib/facter/architecture.rb +13 -0
  12. data/lib/facter/domain.rb +20 -0
  13. data/lib/facter/facterversion.rb +9 -0
  14. data/lib/facter/fqdn.rb +11 -0
  15. data/lib/facter/hardwareisa.rb +12 -0
  16. data/lib/facter/hardwaremodel.rb +13 -0
  17. data/lib/facter/hostname.rb +13 -0
  18. data/lib/facter/id.rb +13 -0
  19. data/lib/facter/interfaces.rb +9 -0
  20. data/lib/facter/ipaddress.rb +24 -0
  21. data/lib/facter/ipaddress6.rb +35 -40
  22. data/lib/facter/iphostnumber.rb +11 -0
  23. data/lib/facter/kernel.rb +11 -0
  24. data/lib/facter/kernelmajversion.rb +10 -0
  25. data/lib/facter/kernelrelease.rb +13 -0
  26. data/lib/facter/kernelversion.rb +12 -0
  27. data/lib/facter/lsb.rb +13 -12
  28. data/lib/facter/lsbmajdistrelease.rb +12 -0
  29. data/lib/facter/macaddress.rb +21 -0
  30. data/lib/facter/macosx.rb +13 -11
  31. data/lib/facter/manufacturer.rb +13 -0
  32. data/lib/facter/memory.rb +35 -18
  33. data/lib/facter/netmask.rb +9 -0
  34. data/lib/facter/network.rb +12 -0
  35. data/lib/facter/operatingsystem.rb +13 -0
  36. data/lib/facter/operatingsystemrelease.rb +17 -0
  37. data/lib/facter/path.rb +9 -0
  38. data/lib/facter/physicalprocessorcount.rb +53 -4
  39. data/lib/facter/processor.rb +14 -1
  40. data/lib/facter/ps.rb +12 -0
  41. data/lib/facter/puppetversion.rb +10 -0
  42. data/lib/facter/rubysitedir.rb +10 -0
  43. data/lib/facter/rubyversion.rb +9 -0
  44. data/lib/facter/selinux.rb +9 -0
  45. data/lib/facter/ssh.rb +9 -11
  46. data/lib/facter/timezone.rb +9 -0
  47. data/lib/facter/uptime.rb +11 -0
  48. data/lib/facter/uptime_days.rb +9 -0
  49. data/lib/facter/uptime_hours.rb +9 -0
  50. data/lib/facter/uptime_seconds.rb +14 -0
  51. data/lib/facter/util/collection.rb +5 -1
  52. data/lib/facter/util/fact.rb +1 -3
  53. data/lib/facter/util/loader.rb +1 -0
  54. data/lib/facter/util/macosx.rb +0 -11
  55. data/lib/facter/util/memory.rb +1 -13
  56. data/lib/facter/util/resolution.rb +12 -3
  57. data/lib/facter/util/virtual.rb +1 -1
  58. data/lib/facter/virtual.rb +49 -3
  59. data/lib/facter/vlans.rb +10 -0
  60. data/lib/facter/xendomains.rb +11 -0
  61. data/spec/fixtures/uptime/sysctl_kern_boottime_big_endian +0 -0
  62. data/spec/fixtures/uptime/{sysctl_kern_boottime → sysctl_kern_boottime_little_endian} +0 -0
  63. data/spec/spec_helper.rb +1 -0
  64. data/spec/unit/interfaces_spec.rb +2 -5
  65. data/spec/unit/memory_spec.rb +3 -1
  66. data/spec/unit/operatingsystem_spec.rb +2 -0
  67. data/spec/unit/physicalprocessorcount_spec.rb +40 -0
  68. data/spec/unit/util/fact_spec.rb +11 -11
  69. data/spec/unit/util/loader_spec.rb +4 -0
  70. data/spec/unit/util/resolution_spec.rb +20 -2
  71. data/spec/unit/util/uptime_spec.rb +6 -1
  72. data/spec/unit/util/virtual_spec.rb +1 -0
  73. data/spec/unit/virtual_spec.rb +34 -4
  74. metadata +133 -135
  75. data/COPYING +0 -339
  76. data/README +0 -8
  77. data/README.rst +0 -26
  78. data/TODO +0 -4
  79. data/lib/facter/util/#uptime.rb# +0 -64
data/CHANGELOG CHANGED
@@ -1,3 +1,42 @@
1
+ 1.6.0
2
+ ===
3
+ 9404a7a (#7670) Add an acceptance test
4
+ 0c23845 maint: Fix spelling of acceptance directory
5
+ 926e912 (#7670) Stop preloading all facts in the application
6
+ 2255abe (#7670) Never fail to find a fact that is present
7
+ 8002c24 (#7507) Fix 1.9.2 test failure
8
+ 0635822 Removed inappropriately uncredited Ohai method from ec2 fact
9
+ 6b1cd16 (#6614) Update ipaddress6 fact to work with Ruby 1.9
10
+ 21fe217 (#6612) Changed uptime spec to be endian agnostic
11
+ 19f96b5 (#6728) Facter improperly detects openvzve on CloudLinux systems
12
+ 5b10173 (#5135) Fix faulty logic in physicalprocessorcount
13
+ 53cd946 Ensures that ARP facts are returned only on EC2 hosts
14
+ bfa038d Fixed #6974 - Moved to Apache 2.0 license
15
+ d56bca8 refactor the mechanism for allowing for resolution ordering to be influenced
16
+ 9f4c5c6 (#6740) facter doesn't always respect facts in environment variables
17
+ 7441b32 Partial fix for #6971 - Fix for virtual tests
18
+ 7f3e89d (#2714) Fixed faulty test
19
+ bfc16f6 (#2714) Added timeout to prtdiag resulution
20
+ c2ff833 (#5135) Refactored physicalprocessorcount
21
+ 0c4a98b Re-factor. Do not use pure-Ruby file reading against "/proc/cpuinfo" and possibly any entry under "/sys" from the sysfs file system.
22
+ cb52b06 Fix. Using sysfs file system entries to count the number of physical CPUs. Fall-back to "/proc/cpuinfo" included for backward-compatibility with legacy systems.
23
+ 3efa9d7 (#3856) Add virtualbox detection via lspci (graphics card), dmidecode, and prtdiag for Solaris and corresponding tests. Darwin case is not handled yet.
24
+ 7c80172 (#6883) Update Facter install.rb to be slightly more informative.
25
+ d31e3f9 (#5394) Document each Facter fact.
26
+ af4947c (#6862) Add a default subject for the mail_patches rake task
27
+ d6967a0 (#6613) Switch solaris macaddress fact to netstat
28
+ e056218 (#6817) Fix for Ruby 1.9 by calling .each_line on a string
29
+ 861c2b2 maint: cleanup whitespace
30
+ f6c9927 (#6719) Corrected faulty logic in bugfix
31
+ e42e57c (#3856) Add virtualbox detection via lspci (graphics card), dmidecode, and prtdiag for Solaris and corresponding tests. Darwin case is not handled yet.
32
+ 0b5b546 (#6883) Update Facter install.rb to be slightly more informative.
33
+ 7c08270 (#5394) Document each Facter fact.
34
+ 06eb3f5 (#6883) Update Facter install.rb to be slightly more informative.
35
+ 1063753 (#6862) Add a default subject for the mail_patches rake task
36
+ 56b5f10 (#6613) Switch solaris macaddress fact to netstat
37
+ fd4f31c (#6817) Fix for Ruby 1.9 by calling .each_line on a string
38
+ 72996ff maint: cleanup whitespace
39
+
1
40
  1.5.9
2
41
  =====
3
42
  4de8b20 Updated CHANGELOG for 1.5.9rc6
data/LICENSE CHANGED
@@ -1,17 +1,15 @@
1
- Facter - Host Fact Detection and Reporting. Copyright (C) 2005 Reductive Labs LLC
1
+ Facter - Host Fact Detection and Reporting
2
2
 
3
- Reductive Labs can be contacted at: info@reductivelabs.com
3
+ Copyright 2011 Puppet Labs Inc
4
4
 
5
- This program and entire repository is free software; you can
6
- redistribute it and/or modify it under the terms of the GNU
7
- General Public License as published by the Free Software
8
- Foundation; either version 2 of the License, or any later version.
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
9
8
 
10
- This program is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
9
+ http://www.apache.org/licenses/LICENSE-2.0
14
10
 
15
- You should have received a copy of the GNU General Public License
16
- along with this program; if not, write to the Free Software
17
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
@@ -0,0 +1,24 @@
1
+ Facter
2
+ ======
3
+
4
+ This package is largely meant to be a library for collecting facts about your
5
+ system. These facts are mostly strings (i.e., not numbers), and are things
6
+ like the output of `uname`, public ssh and cfengine keys, the number of
7
+ processors, etc.
8
+
9
+ See `bin/facter` for an example of the interface.
10
+
11
+ Running Facter
12
+ --------------
13
+
14
+ Run the `facter` binary on the command for a full list of facts supported on your host.
15
+
16
+ Adding your own facts
17
+ ---------------------
18
+
19
+ See the [Adding Facts](http://docs.puppetlabs.com/guides/custom_facts.html) page for details of how to add your own custom facts to Facter.
20
+
21
+ Further Information
22
+ -------------------
23
+
24
+ See http://www.puppetlabs.com/puppet/related-projects/facter for more details.
data/bin/facter CHANGED
@@ -52,8 +52,8 @@
52
52
  #
53
53
  # = Copyright
54
54
  #
55
- # Copyright (c) 2006 Reductive Labs, LLC
56
- # Licensed under the GNU Public License
55
+ # Copyright (c) 2011 Puppet Labs, Inc
56
+ # Licensed under the Apache 2.0 license
57
57
 
58
58
  require 'facter/application'
59
59
 
@@ -5,9 +5,9 @@
5
5
 
6
6
  Summary: Ruby module for collecting simple facts about a host operating system
7
7
  Name: facter
8
- Version: 1.5.8
8
+ Version: 1.6.0
9
9
  Release: 1%{?dist}
10
- License: GPLv2+
10
+ License: Apache 2.0
11
11
  Group: System Environment/Base
12
12
  URL: http://www.puppetlabs.com/puppet/related-projects/%{name}/
13
13
  Source0: http://puppetlabs.com/downloads/%{name}/%{name}-%{version}.tar.gz
@@ -52,6 +52,9 @@ rm -rf %{buildroot}
52
52
 
53
53
 
54
54
  %changelog
55
+ * Thu Jun 23 2011 Michael Stahnke <stahnma@puppetlabs.com> - 1.6.0-1
56
+ - Update to 1.6.0
57
+
55
58
  * Sat Aug 28 2010 Todd Zullinger <tmz@pobox.com> - 1.5.8-1
56
59
  - Update to 1.5.8
57
60
 
@@ -1,6 +1,6 @@
1
1
  PKG=CSWfacter
2
2
  NAME=facter - System Fact Gatherer
3
- VERSION=1.3.5
3
+ VERSION=1.6.0
4
4
  CATEGORY=application
5
5
  VENDOR=http://www.puppetlabs.com/puppet/related-projects/facter
6
6
  HOTLINE=http://puppetlabs.com/cgi-bin/facter.cgi
data/install.rb CHANGED
@@ -119,7 +119,7 @@ def check_prereqs
119
119
  begin
120
120
  require pre
121
121
  rescue LoadError
122
- puts "Could not load %s; cannot install" % pre
122
+ puts "Could not load #{pre} Ruby library; cannot install"
123
123
  exit -1
124
124
  end
125
125
  }
@@ -1,21 +1,18 @@
1
- #--
2
- # Copyright 2006 Luke Kanies <luke@madstop.com>
1
+ # Facter - Host Fact Detection and Reporting
3
2
  #
4
- # This library is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU Lesser General Public
6
- # License as published by the Free Software Foundation; either
7
- # version 2.1 of the License, or (at your option) any later version.
3
+ # Copyright 2011 Puppet Labs Inc
8
4
  #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
13
8
  #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
9
+ # http://www.apache.org/licenses/LICENSE-2.0
17
10
  #
18
- #--
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
19
16
 
20
17
  module Facter
21
18
  # This is just so the other classes have the constant.
@@ -27,7 +24,7 @@ module Facter
27
24
  include Comparable
28
25
  include Enumerable
29
26
 
30
- FACTERVERSION = '1.5.9'
27
+ FACTERVERSION = '1.6.0'
31
28
  # = Facter
32
29
  # Functions as a hash of 'facts' you might care about about your
33
30
  # system, such as mac address, IP address, Video card, etc.
@@ -1,17 +1,17 @@
1
+ # Fact: Cfkey
2
+ #
3
+ # Purpose: Return the public key(s) for CFengine.
4
+ #
5
+ # Resolution:
6
+ # Tries each file of standard localhost.pub & cfkey.pub locations,
7
+ # checks if they appear to be a public key, and then join them all together.
8
+ #
9
+ # Caveats:
10
+ #
11
+
1
12
  ## Cfkey.rb
2
13
  ## Facts related to cfengine
3
14
  ##
4
- ## This program is free software; you can redistribute it and/or
5
- ## modify it under the terms of the GNU General Public License
6
- ## as published by the Free Software Foundation (version 2 of the License)
7
- ## This program is distributed in the hope that it will be useful,
8
- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
9
- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
- ## GNU General Public License for more details.
11
- ## You should have received a copy of the GNU General Public License
12
- ## along with this program; if not, write to the Free Software
13
- ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
14
- ##
15
15
 
16
16
  Facter.add(:Cfkey) do
17
17
  setcode do
@@ -10,10 +10,6 @@ module Facter
10
10
  names = argv
11
11
 
12
12
  # Create the facts hash that is printed to standard out.
13
- # Pre-load all of the facts, since we can have multiple facts
14
- # per file, and since we can't know ahead of time which file a
15
- # fact will be in, we'll need to load every file.
16
- facts = Facter.to_hash
17
13
  unless names.empty?
18
14
  facts = {}
19
15
  names.each do |name|
@@ -26,6 +22,9 @@ module Facter
26
22
  end
27
23
  end
28
24
 
25
+ # Print everything if they didn't ask for specific facts.
26
+ facts ||= Facter.to_hash
27
+
29
28
  # Print the facts as YAML and exit
30
29
  if options[:yaml]
31
30
  require 'yaml'
@@ -1,3 +1,16 @@
1
+ # Fact: architecture
2
+ #
3
+ # Purpose:
4
+ # Return the CPU hardware architecture.
5
+ #
6
+ # Resolution:
7
+ # On OpenBSD, Linux and Debian's kfreebsd, use the hardwaremodel fact.
8
+ # Gentoo and Debian call "x86_86" "amd64".
9
+ # Gentoo also calls "i386" "x86".
10
+ #
11
+ # Caveats:
12
+ #
13
+
1
14
  Facter.add(:architecture) do
2
15
  confine :kernel => [:linux, :"gnu/kfreebsd"]
3
16
  setcode do
@@ -1,3 +1,23 @@
1
+ # Fact: domain
2
+ #
3
+ # Purpose:
4
+ # Return the host's primary DNS domain name.
5
+ #
6
+ # Resolution:
7
+ # On UNIX (excluding Darwin), first try and use the hostname fact,
8
+ # which uses the hostname system command, and then parse the output
9
+ # of that.
10
+ # Failing that it tries the dnsdomainname system command.
11
+ # Failing that it uses /etc/resolv.conf and takes the domain from that, or as
12
+ # a final resort, the search from that.
13
+ # Otherwise returns nil.
14
+ #
15
+ # On Windows uses the win32ole gem and winmgmts to get the DNSDomain value
16
+ # from the Win32 networking stack.
17
+ #
18
+ # Caveats:
19
+ #
20
+
1
21
  Facter.add(:domain) do
2
22
  setcode do
3
23
  # Get the domain from various sources; the order of these
@@ -1,3 +1,12 @@
1
+ # Fact: facterversion
2
+ #
3
+ # Purpose: returns the version of the facter module.
4
+ #
5
+ # Resolution: Uses the version constant.
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  Facter.add(:facterversion) do
2
11
  setcode { Facter::FACTERVERSION.to_s }
3
12
  end
@@ -1,3 +1,14 @@
1
+ # Fact: fqdn
2
+ #
3
+ # Purpose: Returns the fully qualified domain name of the host.
4
+ #
5
+ # Resolution: Simply joins the hostname fact with the domain name fact.
6
+ #
7
+ # Caveats: No attempt is made to check that the two facts are accurate or that
8
+ # the two facts go together. At no point is there any DNS resolution made
9
+ # either.
10
+ #
11
+
1
12
  Facter.add(:fqdn) do
2
13
  setcode do
3
14
  host = Facter.value(:hostname)
@@ -1,3 +1,15 @@
1
+ # Fact: hardwareisa
2
+ #
3
+ # Purpose:
4
+ # Returns hardware processor type.
5
+ #
6
+ # Resolution:
7
+ # On Solaris, Linux and the BSDs simply uses the output of "uname -p"
8
+ #
9
+ # Caveats:
10
+ # Some linuxes return unknown to uname -p with relative ease.
11
+ #
12
+
1
13
  Facter.add(:hardwareisa) do
2
14
  setcode 'uname -p', '/bin/sh'
3
15
  confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS SuSE SLES Debian Ubuntu Gentoo FreeBSD OpenBSD NetBSD OEL OVS GNU/kFreeBSD}
@@ -1,3 +1,16 @@
1
+ # Fact: hardwaremodel
2
+ #
3
+ # Purpose:
4
+ # Returns the hardware model of the system.
5
+ #
6
+ # Resolution:
7
+ # Uses purely "uname -m" on all platforms other than AIX and Windows.
8
+ # On AIX uses the parsed "modelname" output of "lsattr -El sys0 -a modelname".
9
+ # On Windows uses the 'host_cpu' pulled out of Ruby's config.
10
+ #
11
+ # Caveats:
12
+ #
13
+
1
14
  Facter.add(:hardwaremodel) do
2
15
  setcode 'uname -m'
3
16
  end
@@ -1,3 +1,16 @@
1
+ # Fact: hostname
2
+ #
3
+ # Purpose: Return the system's short hostname.
4
+ #
5
+ # Resolution:
6
+ # On all system bar Darwin, parses the output of the "hostname" system command
7
+ # to everything before the first period.
8
+ # On Darwin, uses the system configuration util to get the LocalHostName
9
+ # variable.
10
+ #
11
+ # Caveats:
12
+ #
13
+
1
14
  Facter.add(:hostname, :ldapname => "cn") do
2
15
  setcode do
3
16
  hostname = nil
@@ -1,3 +1,16 @@
1
+ # Fact: id
2
+ #
3
+ # Purpose: Internal fact used to specity the program to return the currently
4
+ # running user id.
5
+ #
6
+ # Resolution:
7
+ # On all Unixes bar Solaris, just returns "whoami".
8
+ # On Solaris, parses the output of the "id" command to grab the username, as
9
+ # Solaris doesn't have the whoami command.
10
+ #
11
+ # Caveats:
12
+ #
13
+
1
14
  Facter.add(:id) do
2
15
  setcode "whoami"
3
16
  end
@@ -1,3 +1,12 @@
1
+ # Fact: interfaces
2
+ #
3
+ # Purpose:
4
+ #
5
+ # Resolution:
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  # interfaces.rb
2
11
  # Try to get additional Facts about the machine's network interfaces
3
12
  #
@@ -1,3 +1,27 @@
1
+ # Fact: ipaddress
2
+ #
3
+ # Purpose: Return the main IP address for a host.
4
+ #
5
+ # Resolution:
6
+ # On the Unixes does an ifconfig, and returns the first non 127.0.0.0/8
7
+ # subnetted IP it finds.
8
+ # On Windows, it attempts to use the socket library and resolve the machine's
9
+ # hostname via DNS.
10
+ #
11
+ # On LDAP based hosts it tries to use either the win32/resolv library to
12
+ # resolve the hostname to an IP address, or on Unix, it uses the resolv
13
+ # library.
14
+ #
15
+ # As a fall back for undefined systems, it tries to run the "host" command to
16
+ # resolve the machine's hostname using the system DNS.
17
+ #
18
+ # Caveats:
19
+ # DNS resolution relies on working DNS infrastructure and resolvers on the
20
+ # host system.
21
+ # The ifconfig parsing purely takes the first IP address it finds without any
22
+ # checking this is a useful IP address.
23
+ #
24
+
1
25
  Facter.add(:ipaddress) do
2
26
  confine :kernel => :linux
3
27
  setcode do
@@ -1,32 +1,46 @@
1
+ # Fact: ipaddress6
2
+ #
3
+ # Purpose: Returns the "main" IPv6 IP address of a system.
4
+ #
5
+ # Resolution:
6
+ # OS dependant code that parses the output of various networking
7
+ # tools and currently not very intelligent. Returns the first
8
+ # non-loopback and non-linklocal address found in the ouput unless
9
+ # a default route can be mapped to a routeable interface. Guessing
10
+ # an interface is currently only possible with BSD type systems
11
+ # to many assumptions have to be made on other platforms to make
12
+ # this work with the current code. Most code ported or modeled
13
+ # after the ipaddress fact for the sake of similar functionality
14
+ # and familiar mechanics.
15
+ #
16
+ # Caveats:
17
+ #
18
+
1
19
  # Cody Herriges <c.a.herriges@gmail.com>
2
20
  #
3
21
  # Used the ipaddress fact that is already part of
4
22
  # Facter as a template.
5
23
 
6
- # OS dependant code that parses the output of various networking
7
- # tools and currently not very intelligent. Returns the first
8
- # non-loopback and non-linklocal address found in the ouput unless
9
- # a default route can be mapped to a routeable interface. Guessing
10
- # an interface is currently only possible with BSD type systems
11
- # to many assumptions have to be made on other platforms to make
12
- # this work with the current code. Most code ported or modeled
13
- # after the ipaddress fact for the sake of similar functionality
14
- # and familiar mechanics.
24
+ def get_address_after_token(output, token, return_first=false)
25
+ ip = nil
26
+
27
+ output.scan(/#{token} ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |match|
28
+ match = match.first
29
+ unless match =~ /fe80.*/ or match == "::1"
30
+ ip = match
31
+ break if return_first
32
+ end
33
+ end
34
+
35
+ ip
36
+ end
37
+
15
38
  Facter.add(:ipaddress6) do
16
39
  confine :kernel => :linux
17
40
  setcode do
18
- ip = nil
19
41
  output = Facter::Util::Resolution.exec('/sbin/ifconfig')
20
42
 
21
- output.scan(/inet6 addr: ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
22
- str = str.to_s
23
- unless str =~ /fe80.*/ or str == "::1"
24
- ip = str
25
- end
26
- }
27
-
28
- ip
29
-
43
+ get_address_after_token(output, 'inet6 addr:')
30
44
  end
31
45
  end
32
46
 
@@ -34,17 +48,8 @@ Facter.add(:ipaddress6) do
34
48
  confine :kernel => %w{SunOS}
35
49
  setcode do
36
50
  output = Facter::Util::Resolution.exec('/usr/sbin/ifconfig -a')
37
- ip = nil
38
-
39
- output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{0,2})+[0-9,a-f,A-F]{0,4})/).each { |str|
40
- str = str.to_s
41
- unless str =~ /fe80.*/ or str == "::1"
42
- ip = str
43
- end
44
- }
45
-
46
- ip
47
51
 
52
+ get_address_after_token(output, 'inet6')
48
53
  end
49
54
  end
50
55
 
@@ -52,17 +57,7 @@ Facter.add(:ipaddress6) do
52
57
  confine :kernel => %w{Darwin FreeBSD OpenBSD}
53
58
  setcode do
54
59
  output = Facter::Util::Resolution.exec('/sbin/ifconfig -a')
55
- ip = nil
56
-
57
- output.scan(/inet6 ((?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/).each do |str|
58
- str = str.to_s
59
- unless str =~ /fe80.*/ or str == "::1"
60
- ip = str
61
- break
62
- end
63
- end
64
60
 
65
- ip
61
+ get_address_after_token(output, 'inet6', true)
66
62
  end
67
63
  end
68
-