facter 1.5.9 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

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
@@ -1,5 +1,18 @@
1
+ # Fact: processor
2
+ #
3
+ # Purpose:
4
+ # Additional Facts about the machine's CPUs.
5
+ #
6
+ # Resolution:
7
+ # On Linux and kFreeBSD, parse '/proc/cpuinfo' for each processor.
8
+ # On AIX, parse the output of 'lsdev' for it's processor section.
9
+ # On OpenBSD, use 'uname -p' and the sysctl variable for 'hw.ncpu' for CPU
10
+ # count.
11
+ #
12
+ # Caveats:
13
+ #
14
+
1
15
  # processor.rb
2
- # Additional Facts about the machine's CPUs
3
16
  #
4
17
  # Copyright (C) 2006 Mooter Media Ltd
5
18
  # Author: Matthew Palmer <matt@solutionsfirst.com.au>
@@ -1,3 +1,15 @@
1
+ # Fact: ps
2
+ #
3
+ # Purpose: Internal fact for what to use to list all processes. Used by
4
+ # Service{} type in Puppet.
5
+ #
6
+ # Resolution:
7
+ # Assumes "ps -ef" for all operating systems other than BSD derivatives, where
8
+ # it uses "ps auxwww"
9
+ #
10
+ # Caveats:
11
+ #
12
+
1
13
  Facter.add(:ps) do
2
14
  setcode do 'ps -ef' end
3
15
  end
@@ -1,3 +1,13 @@
1
+ # Fact: puppetversion
2
+ #
3
+ # Purpose: Return the version of puppet installed.
4
+ #
5
+ # Resolution:
6
+ # Requres puppet via Ruby and returns it's version constant.
7
+ #
8
+ # Caveats:
9
+ #
10
+
1
11
  Facter.add(:puppetversion) do
2
12
  setcode do
3
13
  begin
@@ -1,3 +1,13 @@
1
+ # Fact: rubysitedir
2
+ #
3
+ # Purpose: Returns Ruby's site library directory.
4
+ #
5
+ # Resolution: Works out the version to major/minor (1.8, 1.9, etc), then joins
6
+ # that with all the $: library paths.
7
+ #
8
+ # Caveats:
9
+ #
10
+
1
11
  Facter.add :rubysitedir do
2
12
  setcode do
3
13
  version = RUBY_VERSION.to_s.sub(/\.\d+$/, '')
@@ -1,3 +1,12 @@
1
+ # Fact: rubyversion
2
+ #
3
+ # Purpose: Returns the version of Ruby facter is running under.
4
+ #
5
+ # Resolution: Returns RUBY_VERSION.
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  Facter.add(:rubyversion) do
2
11
  setcode { RUBY_VERSION.to_s }
3
12
  end
@@ -1,3 +1,12 @@
1
+ # Fact: selinux
2
+ #
3
+ # Purpose:
4
+ #
5
+ # Resolution:
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  # Fact for SElinux
2
11
  # Written by immerda admin team (admin(at)immerda.ch)
3
12
 
@@ -1,17 +1,15 @@
1
+ # Fact: ssh
2
+ #
3
+ # Purpose:
4
+ #
5
+ # Resolution:
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  ## ssh.rb
2
11
  ## Facts related to SSH
3
12
  ##
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
13
 
16
14
  ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir|
17
15
  {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub"}.each do |name,file|
@@ -1,3 +1,12 @@
1
+ # Fact: timezone
2
+ #
3
+ # Purpose: Return the machine's time zone.
4
+ #
5
+ # Resolution: Uses's Ruby's Time module's Time.new call.
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  Facter.add("timezone") do
2
11
  setcode do
3
12
  Time.new.zone
@@ -1,3 +1,14 @@
1
+ # Fact: uptime
2
+ #
3
+ # Purpose: return the system uptime in a human readable format.
4
+ #
5
+ # Resolution:
6
+ # Does basic maths on the "uptime_seconds" fact to return a count of
7
+ # days, hours and minutes of uptime
8
+ #
9
+ # Caveats:
10
+ #
11
+
1
12
  require 'facter/util/uptime'
2
13
 
3
14
  Facter.add(:uptime) do
@@ -1,3 +1,12 @@
1
+ # Fact: uptime_days
2
+ #
3
+ # Purpose: Return purely number of days of uptime.
4
+ #
5
+ # Resolution: Divides uptime_hours fact by 24.
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  Facter.add(:uptime_days) do
2
11
  setcode do
3
12
  hours = Facter.value(:uptime_hours)
@@ -1,3 +1,12 @@
1
+ # Fact: uptime_hours
2
+ #
3
+ # Purpose: Return purely number of hours of uptime.
4
+ #
5
+ # Resolution: Divides uptime_seconds fact by 3600.
6
+ #
7
+ # Caveats:
8
+ #
9
+
1
10
  Facter.add(:uptime_hours) do
2
11
  setcode do
3
12
  seconds = Facter.value(:uptime_seconds)
@@ -1,3 +1,17 @@
1
+ # Fact: uptime_seconds
2
+ #
3
+ # Purpose: Return purely number of seconds of uptime.
4
+ #
5
+ # Resolution:
6
+ # Using the 'facter/util/uptime.rb' module, try a verity of methods to acquire
7
+ # the uptime on Unix.
8
+ #
9
+ # On Windows, the module calculates the uptime by the "LastBootupTime" Windows
10
+ # management value.
11
+ #
12
+ # Caveats:
13
+ #
14
+
1
15
  require 'facter/util/uptime'
2
16
 
3
17
  Facter.add(:uptime_seconds) do
@@ -66,9 +66,13 @@ class Facter::Util::Collection
66
66
  def fact(name)
67
67
  name = canonize(name)
68
68
 
69
+ # Try to load the fact if necessary
69
70
  loader.load(name) unless @facts[name]
70
71
 
71
- return @facts[name]
72
+ # Try HARDER
73
+ loader.load_all unless @facts[name]
74
+
75
+ @facts[name]
72
76
  end
73
77
 
74
78
  # Flush all cached values.
@@ -41,9 +41,7 @@ class Facter::Util::Fact
41
41
 
42
42
  # Immediately sort the resolutions, so that we always have
43
43
  # a sorted list for looking up values.
44
- # We always want to look them up in the order of number of
45
- # confines, so the most restricted resolution always wins.
46
- @resolves.sort! { |a, b| b.length <=> a.length }
44
+ @resolves.sort! { |a, b| b.weight <=> a.weight }
47
45
 
48
46
  return resolve
49
47
  end
@@ -90,6 +90,7 @@ class Facter::Util::Loader
90
90
  next if fact and env_name != fact
91
91
 
92
92
  Facter.add($1) do
93
+ has_weight 1_000_000
93
94
  setcode { value }
94
95
  end
95
96
 
@@ -4,17 +4,6 @@
4
4
  ## Copyright (C) 2007 Jeff McCune
5
5
  ## Author: Jeff McCune <jeff.mccune@northstarlabs.net>
6
6
  ##
7
- ## This program is free software; you can redistribute it and/or
8
- ## modify it under the terms of the GNU General Public License
9
- ## as published by the Free Software Foundation (version 2 of the License)
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.
14
- ## You should have received a copy of the GNU General Public License
15
- ## along with this program; if not, write to the Free Software
16
- ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
17
- ##
18
7
 
19
8
  module Facter::Util::Macosx
20
9
  require 'thread'
@@ -1,17 +1,6 @@
1
1
  ## memory.rb
2
2
  ## Support module for memory related facts
3
3
  ##
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
4
 
16
5
  module Facter::Memory
17
6
  require 'thread'
@@ -75,7 +64,7 @@ module Facter::Memory
75
64
  memspecfree = 0
76
65
 
77
66
  vmstats = Facter::Util::Resolution.exec('vm_stat')
78
- vmstats.each do |vmline|
67
+ vmstats.each_line do |vmline|
79
68
  case
80
69
  when vmline =~ /page\ssize\sof\s(\d+)\sbytes/
81
70
  pagesize = $1.to_i
@@ -94,4 +83,3 @@ module Facter::Memory
94
83
  end
95
84
  end
96
85
  end
97
-
@@ -85,17 +85,26 @@ class Facter::Util::Resolution
85
85
  end
86
86
  end
87
87
 
88
+ def has_weight(weight)
89
+ @weight = weight
90
+ end
91
+
88
92
  # Create a new resolution mechanism.
89
93
  def initialize(name)
90
94
  @name = name
91
95
  @confines = []
92
96
  @value = nil
93
97
  @timeout = 0
98
+ @weight = nil
94
99
  end
95
100
 
96
- # Return the number of confines.
97
- def length
98
- @confines.length
101
+ # Return the importance of this resolution.
102
+ def weight
103
+ if @weight
104
+ @weight
105
+ else
106
+ @confines.length
107
+ end
99
108
  end
100
109
 
101
110
  # We need this as a getter for 'timeout', because some versions
@@ -1,6 +1,6 @@
1
1
  module Facter::Util::Virtual
2
2
  def self.openvz?
3
- FileTest.directory?("/proc/vz")
3
+ FileTest.directory?("/proc/vz") and FileTest.exists?( '/proc/vz/veinfo' )
4
4
  end
5
5
 
6
6
  def self.openvz_type
@@ -1,3 +1,30 @@
1
+ # Fact: virtual
2
+ #
3
+ # Purpose: Determine if the system's hardware is real or virtualised.
4
+ #
5
+ # Resolution:
6
+ # Assumes physical unless proven otherwise.
7
+ #
8
+ # On Darwin, use the macosx util module to acquire the SPDisplaysDataType,
9
+ # from that parse it to see if it's VMWare or Parallels pretending to be the
10
+ # display.
11
+ #
12
+ # On Linux, BSD, Solaris and HPUX:
13
+ # Much of the logic here is obscured behind util/virtual.rb, which rather
14
+ # than document here, which would encourage drift, just refer to it.
15
+ # The Xen tests in here rely on /sys and /proc, and check for the presence and
16
+ # contents of files in there.
17
+ # If after all the other tests, it's still seen as physical, then it tries to
18
+ # parse the output of the "lspci", "dmidecode" and "prtdiag" and parses them
19
+ # for obvious signs of being under VMWare or Parallels.
20
+ # Finally it checks for the existence of vmware-vmx, which would hint it's
21
+ # VMWare.
22
+ #
23
+ # Caveats:
24
+ # Virtualbox detection isn't implemented.
25
+ # Many checks rely purely on existence of files.
26
+ #
27
+
1
28
  require 'facter/util/virtual'
2
29
 
3
30
  Facter.add("virtual") do
@@ -25,7 +52,7 @@ Facter.add("virtual") do
25
52
 
26
53
  setcode do
27
54
 
28
- if Facter::Util::Virtual.zone? and Facter.value(:operatingsystem) == "Solaris"
55
+ if Facter.value(:operatingsystem) == "Solaris" and Facter::Util::Virtual.zone?
29
56
  result = "zone"
30
57
  end
31
58
 
@@ -77,6 +104,9 @@ Facter.add("virtual") do
77
104
  # --- look for the vmware video card to determine if it is virtual => vmware.
78
105
  # --- 00:0f.0 VGA compatible controller: VMware Inc [VMware SVGA II] PCI Display Adapter
79
106
  result = "vmware" if p =~ /VM[wW]are/
107
+ # --- look for virtualbox video card to determine if it is virtual => virtualbox.
108
+ # --- 00:02.0 VGA compatible controller: InnoTek Systemberatung GmbH VirtualBox Graphics Adapter
109
+ result = "virtualbox" if p =~ /VirtualBox/
80
110
  # --- look for pci vendor id used by Parallels video card
81
111
  # --- 01:00.0 VGA compatible controller: Unknown device 1ab8:4005
82
112
  result = "parallels" if p =~ /1ab8:|[Pp]arallels/
@@ -87,13 +117,18 @@ Facter.add("virtual") do
87
117
  output.each_line do |pd|
88
118
  result = "parallels" if pd =~ /Parallels/
89
119
  result = "vmware" if pd =~ /VMware/
120
+ result = "virtualbox" if pd =~ /VirtualBox/
90
121
  end
91
- else
92
- output = Facter::Util::Resolution.exec('prtdiag')
122
+ elsif Facter.value(:kernel) == 'SunOS'
123
+ res = Facter::Util::Resolution.new('prtdiag')
124
+ res.timeout = 6
125
+ res.setcode('prtdiag')
126
+ output = res.value
93
127
  if not output.nil?
94
128
  output.each_line do |pd|
95
129
  result = "parallels" if pd =~ /Parallels/
96
130
  result = "vmware" if pd =~ /VMware/
131
+ result = "virtualbox" if pd =~ /VirtualBox/
97
132
  end
98
133
  end
99
134
  end
@@ -108,6 +143,17 @@ Facter.add("virtual") do
108
143
  end
109
144
  end
110
145
 
146
+ # Fact: is_virtual
147
+ #
148
+ # Purpose: returning true or false for if a machine is virtualised or not.
149
+ #
150
+ # Resolution: The Xen domain 0 machine is virtualised to a degree, but is generally
151
+ # not viewed as being a virtual machine. This checks that the machine is not
152
+ # physical nor xen0, if that is the case, it is virtual.
153
+ #
154
+ # Caveats:
155
+ #
156
+
111
157
  Facter.add("is_virtual") do
112
158
  confine :kernel => %w{Linux FreeBSD OpenBSD SunOS HP-UX Darwin GNU/kFreeBSD}
113
159
 
@@ -1,3 +1,13 @@
1
+ # Fact: vlans
2
+ #
3
+ # Purpose: On Linux, return a list of all the VLANs on the system.
4
+ #
5
+ # Resolution: On Linux only, checks for and reads /proc/net/vlan/config and
6
+ # parses it.
7
+ #
8
+ # Caveats:
9
+ #
10
+
1
11
  require 'facter/util/vlans'
2
12
 
3
13
  Facter.add("vlans") do
@@ -1,3 +1,14 @@
1
+ # Fact: xendomains
2
+ #
3
+ # Purpose: Return the list of Xen domains on the Dom0.
4
+ #
5
+ # Resolution:
6
+ # On a Xen Dom0 host, return a list of Xen domains using the 'util/xendomains'
7
+ # library.
8
+ #
9
+ # Caveats:
10
+ #
11
+
1
12
  require 'facter/util/xendomains'
2
13
 
3
14
  Facter.add("xendomains") do