facter 1.6.1 → 1.6.2

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 (88) hide show
  1. data/CHANGELOG +31 -0
  2. data/Rakefile +41 -36
  3. data/conf/redhat/facter.spec +11 -4
  4. data/conf/solaris/pkginfo +1 -1
  5. data/install.rb +286 -286
  6. data/lib/facter.rb +211 -211
  7. data/lib/facter/Cfkey.rb +24 -24
  8. data/lib/facter/application.rb +1 -0
  9. data/lib/facter/architecture.rb +21 -29
  10. data/lib/facter/domain.rb +34 -34
  11. data/lib/facter/facterversion.rb +1 -1
  12. data/lib/facter/fqdn.rb +8 -8
  13. data/lib/facter/hardwareisa.rb +2 -2
  14. data/lib/facter/hardwaremodel.rb +12 -12
  15. data/lib/facter/hostname.rb +14 -14
  16. data/lib/facter/id.rb +3 -3
  17. data/lib/facter/interfaces.rb +13 -13
  18. data/lib/facter/ipaddress.rb +101 -101
  19. data/lib/facter/iphostnumber.rb +12 -12
  20. data/lib/facter/kernel.rb +7 -7
  21. data/lib/facter/kernelmajversion.rb +3 -3
  22. data/lib/facter/kernelrelease.rb +12 -12
  23. data/lib/facter/kernelversion.rb +5 -5
  24. data/lib/facter/lsb.rb +14 -14
  25. data/lib/facter/lsbmajdistrelease.rb +8 -8
  26. data/lib/facter/macaddress.rb +44 -44
  27. data/lib/facter/macosx.rb +21 -21
  28. data/lib/facter/manufacturer.rb +28 -28
  29. data/lib/facter/memory.rb +143 -115
  30. data/lib/facter/netmask.rb +4 -4
  31. data/lib/facter/network.rb +4 -4
  32. data/lib/facter/operatingsystem.rb +73 -69
  33. data/lib/facter/operatingsystemrelease.rb +85 -79
  34. data/lib/facter/osfamily.rb +31 -0
  35. data/lib/facter/path.rb +3 -3
  36. data/lib/facter/physicalprocessorcount.rb +8 -0
  37. data/lib/facter/processor.rb +91 -72
  38. data/lib/facter/ps.rb +3 -3
  39. data/lib/facter/puppetversion.rb +7 -7
  40. data/lib/facter/rubysitedir.rb +5 -5
  41. data/lib/facter/rubyversion.rb +1 -1
  42. data/lib/facter/ssh.rb +16 -16
  43. data/lib/facter/timezone.rb +3 -3
  44. data/lib/facter/uniqueid.rb +2 -2
  45. data/lib/facter/util/collection.rb +96 -96
  46. data/lib/facter/util/confine.rb +30 -30
  47. data/lib/facter/util/fact.rb +95 -95
  48. data/lib/facter/util/ip.rb +173 -173
  49. data/lib/facter/util/loader.rb +88 -88
  50. data/lib/facter/util/macosx.rb +46 -46
  51. data/lib/facter/util/manufacturer.rb +78 -78
  52. data/lib/facter/util/memory.rb +63 -63
  53. data/lib/facter/util/netmask.rb +34 -34
  54. data/lib/facter/util/plist.rb +1 -1
  55. data/lib/facter/util/plist/generator.rb +177 -177
  56. data/lib/facter/util/plist/parser.rb +166 -166
  57. data/lib/facter/util/processor.rb +88 -0
  58. data/lib/facter/util/resolution.rb +154 -154
  59. data/lib/facter/util/uptime.rb +42 -42
  60. data/lib/facter/util/values.rb +9 -9
  61. data/lib/facter/util/virtual.rb +68 -58
  62. data/lib/facter/util/vlans.rb +17 -17
  63. data/lib/facter/virtual.rb +105 -110
  64. data/lib/facter/vlans.rb +6 -6
  65. data/spec/fixtures/cpuinfo/amd64dual +57 -0
  66. data/spec/fixtures/cpuinfo/amd64quad +79 -0
  67. data/spec/fixtures/cpuinfo/amd64solo +23 -0
  68. data/spec/fixtures/cpuinfo/amd64tri +86 -0
  69. data/spec/fixtures/cpuinfo/bbg3-armel +12 -0
  70. data/spec/fixtures/cpuinfo/beaglexm-armel +12 -0
  71. data/spec/fixtures/cpuinfo/panda-armel +17 -0
  72. data/spec/fixtures/cpuinfo/ppc64 +19 -0
  73. data/spec/fixtures/cpuinfo/sparc +10 -0
  74. data/spec/fixtures/processorcount/solaris-sparc-kstat-cpu-info +1216 -0
  75. data/spec/fixtures/processorcount/solaris-x86_64-kstat-cpu-info +225 -0
  76. data/spec/integration/facter_spec.rb +18 -18
  77. data/spec/spec_helper.rb +10 -1
  78. data/spec/unit/architecture_spec.rb +54 -0
  79. data/spec/unit/domain_spec.rb +23 -0
  80. data/spec/unit/memory_spec.rb +78 -1
  81. data/spec/unit/physicalprocessorcount_spec.rb +41 -35
  82. data/spec/unit/processor_spec.rb +183 -2
  83. data/spec/unit/util/processor_spec.rb +62 -0
  84. data/spec/unit/util/uptime_spec.rb +4 -4
  85. data/spec/unit/util/virtual_spec.rb +26 -5
  86. data/spec/unit/virtual_spec.rb +47 -2
  87. data/spec/watchr.rb +125 -0
  88. metadata +20 -4
@@ -9,179 +9,179 @@ require 'facter/util/config'
9
9
  require 'timeout'
10
10
 
11
11
  class Facter::Util::Resolution
12
- attr_accessor :interpreter, :code, :name, :timeout
13
-
14
- INTERPRETER = Facter::Util::Config.is_windows? ? "cmd.exe" : "/bin/sh"
15
-
16
- def self.have_which
17
- if ! defined?(@have_which) or @have_which.nil?
18
- if Facter.value(:kernel) == 'windows'
19
- @have_which = false
20
- else
21
- %x{which which >/dev/null 2>&1}
22
- @have_which = ($? == 0)
23
- end
24
- end
25
- @have_which
12
+ attr_accessor :interpreter, :code, :name, :timeout
13
+
14
+ INTERPRETER = Facter::Util::Config.is_windows? ? "cmd.exe" : "/bin/sh"
15
+
16
+ def self.have_which
17
+ if ! defined?(@have_which) or @have_which.nil?
18
+ if Facter.value(:kernel) == 'windows'
19
+ @have_which = false
20
+ else
21
+ %x{which which >/dev/null 2>&1}
22
+ @have_which = ($? == 0)
23
+ end
26
24
  end
27
-
28
- # Execute a program and return the output of that program.
25
+ @have_which
26
+ end
27
+
28
+ # Execute a program and return the output of that program.
29
+ #
30
+ # Returns nil if the program can't be found, or if there is a problem
31
+ # executing the code.
32
+ #
33
+ def self.exec(code, interpreter = nil)
34
+ Facter.warnonce "The interpreter parameter to 'exec' is deprecated and will be removed in a future version." if interpreter
35
+
36
+ # Try to guess whether the specified code can be executed by looking at the
37
+ # first word. If it cannot be found on the PATH defer on resolving the fact
38
+ # by returning nil.
39
+ # This only fails on shell built-ins, most of which are masked by stuff in
40
+ # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can
41
+ # be used to work around this limitation
29
42
  #
30
- # Returns nil if the program can't be found, or if there is a problem
31
- # executing the code.
32
- #
33
- def self.exec(code, interpreter = nil)
34
- Facter.warnonce "The interpreter parameter to 'exec' is deprecated and will be removed in a future version." if interpreter
35
-
36
- # Try to guess whether the specified code can be executed by looking at the
37
- # first word. If it cannot be found on the PATH defer on resolving the fact
38
- # by returning nil.
39
- # This only fails on shell built-ins, most of which are masked by stuff in
40
- # /bin or of dubious value anyways. In the worst case, "sh -c 'builtin'" can
41
- # be used to work around this limitation
42
- #
43
- # Windows' %x{} throws Errno::ENOENT when the command is not found, so we
44
- # can skip the check there. This is good, since builtins cannot be found
45
- # elsewhere.
46
- if have_which and !Facter::Util::Config.is_windows?
47
- path = nil
48
- binary = code.split.first
49
- if code =~ /^\//
50
- path = binary
51
- else
52
- path = %x{which #{binary} 2>/dev/null}.chomp
53
- # we don't have the binary necessary
54
- return nil if path == "" or path.match(/Command not found\./)
55
- end
56
-
57
- return nil unless FileTest.exists?(path)
58
- end
59
-
60
- out = nil
61
-
62
- begin
63
- out = %x{#{code}}.chomp
64
- rescue Errno::ENOENT => detail
65
- # command not found on Windows
66
- return nil
67
- rescue => detail
68
- $stderr.puts detail
69
- return nil
70
- end
71
-
72
- if out == ""
73
- return nil
74
- else
75
- return out
76
- end
43
+ # Windows' %x{} throws Errno::ENOENT when the command is not found, so we
44
+ # can skip the check there. This is good, since builtins cannot be found
45
+ # elsewhere.
46
+ if have_which and !Facter::Util::Config.is_windows?
47
+ path = nil
48
+ binary = code.split.first
49
+ if code =~ /^\//
50
+ path = binary
51
+ else
52
+ path = %x{which #{binary} 2>/dev/null}.chomp
53
+ # we don't have the binary necessary
54
+ return nil if path == "" or path.match(/Command not found\./)
55
+ end
56
+
57
+ return nil unless FileTest.exists?(path)
77
58
  end
78
59
 
79
- # Add a new confine to the resolution mechanism.
80
- def confine(confines)
81
- confines.each do |fact, values|
82
- @confines.push Facter::Util::Confine.new(fact, *values)
83
- end
84
- end
60
+ out = nil
85
61
 
86
- def has_weight(weight)
87
- @weight = weight
62
+ begin
63
+ out = %x{#{code}}.chomp
64
+ rescue Errno::ENOENT => detail
65
+ # command not found on Windows
66
+ return nil
67
+ rescue => detail
68
+ $stderr.puts detail
69
+ return nil
88
70
  end
89
71
 
90
- # Create a new resolution mechanism.
91
- def initialize(name)
92
- @name = name
93
- @confines = []
94
- @value = nil
95
- @timeout = 0
96
- @weight = nil
72
+ if out == ""
73
+ return nil
74
+ else
75
+ return out
97
76
  end
77
+ end
98
78
 
99
- # Return the importance of this resolution.
100
- def weight
101
- if @weight
102
- @weight
103
- else
104
- @confines.length
105
- end
79
+ # Add a new confine to the resolution mechanism.
80
+ def confine(confines)
81
+ confines.each do |fact, values|
82
+ @confines.push Facter::Util::Confine.new(fact, *values)
106
83
  end
107
-
108
- # We need this as a getter for 'timeout', because some versions
109
- # of ruby seem to already have a 'timeout' method and we can't
110
- # seem to override the instance methods, somehow.
111
- def limit
112
- @timeout
84
+ end
85
+
86
+ def has_weight(weight)
87
+ @weight = weight
88
+ end
89
+
90
+ # Create a new resolution mechanism.
91
+ def initialize(name)
92
+ @name = name
93
+ @confines = []
94
+ @value = nil
95
+ @timeout = 0
96
+ @weight = nil
97
+ end
98
+
99
+ # Return the importance of this resolution.
100
+ def weight
101
+ if @weight
102
+ @weight
103
+ else
104
+ @confines.length
113
105
  end
114
-
115
- # Set our code for returning a value.
116
- def setcode(string = nil, interp = nil, &block)
117
- Facter.warnonce "The interpreter parameter to 'setcode' is deprecated and will be removed in a future version." if interp
118
- if string
119
- @code = string
120
- @interpreter = interp || INTERPRETER
121
- else
122
- unless block_given?
123
- raise ArgumentError, "You must pass either code or a block"
124
- end
125
- @code = block
126
- end
106
+ end
107
+
108
+ # We need this as a getter for 'timeout', because some versions
109
+ # of ruby seem to already have a 'timeout' method and we can't
110
+ # seem to override the instance methods, somehow.
111
+ def limit
112
+ @timeout
113
+ end
114
+
115
+ # Set our code for returning a value.
116
+ def setcode(string = nil, interp = nil, &block)
117
+ Facter.warnonce "The interpreter parameter to 'setcode' is deprecated and will be removed in a future version." if interp
118
+ if string
119
+ @code = string
120
+ @interpreter = interp || INTERPRETER
121
+ else
122
+ unless block_given?
123
+ raise ArgumentError, "You must pass either code or a block"
124
+ end
125
+ @code = block
127
126
  end
128
-
129
- def interpreter
130
- Facter.warnonce "The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version."
131
- @interpreter
127
+ end
128
+
129
+ def interpreter
130
+ Facter.warnonce "The 'Facter::Util::Resolution.interpreter' method is deprecated and will be removed in a future version."
131
+ @interpreter
132
+ end
133
+
134
+ def interpreter=(interp)
135
+ Facter.warnonce "The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version."
136
+ @interpreter = interp
137
+ end
138
+
139
+ # Is this resolution mechanism suitable on the system in question?
140
+ def suitable?
141
+ unless defined? @suitable
142
+ @suitable = ! @confines.detect { |confine| ! confine.true? }
132
143
  end
133
144
 
134
- def interpreter=(interp)
135
- Facter.warnonce "The 'Facter::Util::Resolution.interpreter=' method is deprecated and will be removed in a future version."
136
- @interpreter = interp
137
- end
145
+ return @suitable
146
+ end
138
147
 
139
- # Is this resolution mechanism suitable on the system in question?
140
- def suitable?
141
- unless defined? @suitable
142
- @suitable = ! @confines.detect { |confine| ! confine.true? }
143
- end
148
+ def to_s
149
+ return self.value()
150
+ end
144
151
 
145
- return @suitable
146
- end
152
+ # How we get a value for our resolution mechanism.
153
+ def value
154
+ result = nil
155
+ return result if @code == nil
147
156
 
148
- def to_s
149
- return self.value()
150
- end
157
+ starttime = Time.now.to_f
151
158
 
152
- # How we get a value for our resolution mechanism.
153
- def value
154
- result = nil
155
- return result if @code == nil
156
-
157
- starttime = Time.now.to_f
158
-
159
- begin
160
- Timeout.timeout(limit) do
161
- if @code.is_a?(Proc)
162
- result = @code.call()
163
- else
164
- result = Facter::Util::Resolution.exec(@code)
165
- end
166
- end
167
- rescue Timeout::Error => detail
168
- warn "Timed out seeking value for %s" % self.name
169
-
170
- # This call avoids zombies -- basically, create a thread that will
171
- # dezombify all of the child processes that we're ignoring because
172
- # of the timeout.
173
- Thread.new { Process.waitall }
174
- return nil
175
- rescue => details
176
- warn "Could not retrieve %s: %s" % [self.name, details]
177
- return nil
159
+ begin
160
+ Timeout.timeout(limit) do
161
+ if @code.is_a?(Proc)
162
+ result = @code.call()
163
+ else
164
+ result = Facter::Util::Resolution.exec(@code)
178
165
  end
166
+ end
167
+ rescue Timeout::Error => detail
168
+ warn "Timed out seeking value for %s" % self.name
169
+
170
+ # This call avoids zombies -- basically, create a thread that will
171
+ # dezombify all of the child processes that we're ignoring because
172
+ # of the timeout.
173
+ Thread.new { Process.waitall }
174
+ return nil
175
+ rescue => details
176
+ warn "Could not retrieve %s: %s" % [self.name, details]
177
+ return nil
178
+ end
179
179
 
180
- finishtime = Time.now.to_f
181
- ms = (finishtime - starttime) * 1000
182
- Facter.show_time "#{self.name}: #{"%.2f" % ms}ms"
180
+ finishtime = Time.now.to_f
181
+ ms = (finishtime - starttime) * 1000
182
+ Facter.show_time "#{self.name}: #{"%.2f" % ms}ms"
183
183
 
184
- return nil if result == ""
185
- return result
186
- end
184
+ return nil if result == ""
185
+ return result
186
+ end
187
187
  end
@@ -3,63 +3,63 @@ require 'time'
3
3
  # A module to gather uptime facts
4
4
  #
5
5
  module Facter::Util::Uptime
6
- def self.get_uptime_seconds_unix
7
- uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b
8
- end
6
+ def self.get_uptime_seconds_unix
7
+ uptime_proc_uptime or uptime_sysctl or uptime_kstat or uptime_who_dash_b
8
+ end
9
9
 
10
- def self.get_uptime_seconds_win
11
- require 'facter/util/wmi'
10
+ def self.get_uptime_seconds_win
11
+ require 'facter/util/wmi'
12
12
 
13
- last_boot = ""
14
- Facter::Util::WMI.execquery("select * from Win32_OperatingSystem").each do |x|
15
- last_boot = x.LastBootupTime
16
- end
17
- self.compute_uptime(Time.parse(last_boot.split('.').first))
13
+ last_boot = ""
14
+ Facter::Util::WMI.execquery("select * from Win32_OperatingSystem").each do |x|
15
+ last_boot = x.LastBootupTime
18
16
  end
17
+ self.compute_uptime(Time.parse(last_boot.split('.').first))
18
+ end
19
19
 
20
- private
20
+ private
21
21
 
22
- def self.uptime_proc_uptime
23
- if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null")
24
- output.chomp.split(" ").first.to_i
25
- end
22
+ def self.uptime_proc_uptime
23
+ if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null")
24
+ output.chomp.split(" ").first.to_i
26
25
  end
26
+ end
27
27
 
28
- def self.uptime_sysctl
29
- if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
30
- compute_uptime(Time.at(output.unpack('L').first))
31
- end
28
+ def self.uptime_sysctl
29
+ if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
30
+ compute_uptime(Time.at(output.unpack('L').first))
32
31
  end
32
+ end
33
33
 
34
- def self.uptime_kstat
35
- if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null")
36
- compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i))
37
- end
34
+ def self.uptime_kstat
35
+ if output = Facter::Util::Resolution.exec("#{uptime_kstat_cmd} 2>/dev/null")
36
+ compute_uptime(Time.at(output.chomp.split(/\s/).last.to_i))
38
37
  end
38
+ end
39
39
 
40
- def self.uptime_who_dash_b
41
- if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null")
42
- compute_uptime(Time.parse(output))
43
- end
40
+ def self.uptime_who_dash_b
41
+ if output = Facter::Util::Resolution.exec("#{uptime_who_cmd} 2>/dev/null")
42
+ compute_uptime(Time.parse(output))
44
43
  end
44
+ end
45
45
 
46
- def self.compute_uptime(time)
47
- (Time.now - time).to_i
48
- end
46
+ def self.compute_uptime(time)
47
+ (Time.now - time).to_i
48
+ end
49
49
 
50
- def self.uptime_file
51
- "/proc/uptime"
52
- end
50
+ def self.uptime_file
51
+ "/proc/uptime"
52
+ end
53
53
 
54
- def self.uptime_sysctl_cmd
55
- 'sysctl -b kern.boottime'
56
- end
54
+ def self.uptime_sysctl_cmd
55
+ 'sysctl -b kern.boottime'
56
+ end
57
57
 
58
- def self.uptime_kstat_cmd
59
- 'kstat -p unix:::boot_time'
60
- end
58
+ def self.uptime_kstat_cmd
59
+ 'kstat -p unix:::boot_time'
60
+ end
61
61
 
62
- def self.uptime_who_cmd
63
- 'who -b'
64
- end
62
+ def self.uptime_who_cmd
63
+ 'who -b'
64
+ end
65
65
  end
@@ -1,14 +1,14 @@
1
1
  # A util module for facter containing helper methods
2
2
  module Facter
3
- module Util
4
- module Values
5
- module_function
3
+ module Util
4
+ module Values
5
+ module_function
6
6
 
7
- def convert(value)
8
- value = value.to_s if value.is_a?(Symbol)
9
- value = value.downcase if value.is_a?(String)
10
- value
11
- end
12
- end
7
+ def convert(value)
8
+ value = value.to_s if value.is_a?(Symbol)
9
+ value = value.downcase if value.is_a?(String)
10
+ value
11
+ end
13
12
  end
13
+ end
14
14
  end