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
@@ -15,233 +15,233 @@
15
15
  # limitations under the License.
16
16
 
17
17
  module Facter
18
- # This is just so the other classes have the constant.
19
- module Util; end
20
-
21
- require 'facter/util/fact'
22
- require 'facter/util/collection'
23
-
24
- include Comparable
25
- include Enumerable
26
-
27
- FACTERVERSION = '1.6.1'
28
- # = Facter
29
- # Functions as a hash of 'facts' you might care about about your
30
- # system, such as mac address, IP address, Video card, etc.
31
- # returns them dynamically
32
-
33
- # == Synopsis
34
- #
35
- # Generally, treat <tt>Facter</tt> as a hash:
36
- # == Example
37
- # require 'facter'
38
- # puts Facter['operatingsystem']
39
- #
40
-
41
- # Set LANG to force i18n to C
42
- #
43
- ENV['LANG'] = 'C'
44
-
45
- GREEN = ""
46
- RESET = ""
47
- @@debug = 0
48
- @@timing = 0
49
- @@messages = {}
50
-
51
- # module methods
52
-
53
- def self.collection
54
- unless defined?(@collection) and @collection
55
- @collection = Facter::Util::Collection.new
56
- end
57
- @collection
58
- end
59
-
60
- # Return the version of the library.
61
- def self.version
62
- return FACTERVERSION
63
- end
64
-
65
- # Add some debugging
66
- def self.debug(string)
67
- if string.nil?
68
- return
69
- end
70
- if self.debugging?
71
- puts GREEN + string + RESET
72
- end
73
- end
74
-
75
- def self.debugging?
76
- @@debug != 0
77
- end
78
-
79
- # show the timing information
80
- def self.show_time(string)
81
- puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing?
82
- end
83
-
84
- def self.timing?
85
- @@timing != 0
86
- end
87
-
88
- # Return a fact object by name. If you use this, you still have to call
89
- # 'value' on it to retrieve the actual value.
90
- def self.[](name)
91
- collection.fact(name)
92
- end
93
-
94
- class << self
95
- [:fact, :flush, :list, :value].each do |method|
96
- define_method(method) do |*args|
97
- collection.send(method, *args)
98
- end
99
- end
100
-
101
- [:list, :to_hash].each do |method|
102
- define_method(method) do |*args|
103
- collection.load_all
104
- collection.send(method, *args)
105
- end
106
- end
107
- end
108
-
109
-
110
- # Add a resolution mechanism for a named fact. This does not distinguish
111
- # between adding a new fact and adding a new way to resolve a fact.
112
- def self.add(name, options = {}, &block)
113
- collection.add(name, options, &block)
114
- end
115
-
116
- def self.each
117
- # Make sure all facts are loaded.
18
+ # This is just so the other classes have the constant.
19
+ module Util; end
20
+
21
+ require 'facter/util/fact'
22
+ require 'facter/util/collection'
23
+
24
+ include Comparable
25
+ include Enumerable
26
+
27
+ FACTERVERSION = '1.6.2'
28
+ # = Facter
29
+ # Functions as a hash of 'facts' you might care about about your
30
+ # system, such as mac address, IP address, Video card, etc.
31
+ # returns them dynamically
32
+
33
+ # == Synopsis
34
+ #
35
+ # Generally, treat <tt>Facter</tt> as a hash:
36
+ # == Example
37
+ # require 'facter'
38
+ # puts Facter['operatingsystem']
39
+ #
40
+
41
+ # Set LANG to force i18n to C
42
+ #
43
+ ENV['LANG'] = 'C'
44
+
45
+ GREEN = ""
46
+ RESET = ""
47
+ @@debug = 0
48
+ @@timing = 0
49
+ @@messages = {}
50
+
51
+ # module methods
52
+
53
+ def self.collection
54
+ unless defined?(@collection) and @collection
55
+ @collection = Facter::Util::Collection.new
56
+ end
57
+ @collection
58
+ end
59
+
60
+ # Return the version of the library.
61
+ def self.version
62
+ return FACTERVERSION
63
+ end
64
+
65
+ # Add some debugging
66
+ def self.debug(string)
67
+ if string.nil?
68
+ return
69
+ end
70
+ if self.debugging?
71
+ puts GREEN + string + RESET
72
+ end
73
+ end
74
+
75
+ def self.debugging?
76
+ @@debug != 0
77
+ end
78
+
79
+ # show the timing information
80
+ def self.show_time(string)
81
+ puts "#{GREEN}#{string}#{RESET}" if string and Facter.timing?
82
+ end
83
+
84
+ def self.timing?
85
+ @@timing != 0
86
+ end
87
+
88
+ # Return a fact object by name. If you use this, you still have to call
89
+ # 'value' on it to retrieve the actual value.
90
+ def self.[](name)
91
+ collection.fact(name)
92
+ end
93
+
94
+ class << self
95
+ [:fact, :flush, :list, :value].each do |method|
96
+ define_method(method) do |*args|
97
+ collection.send(method, *args)
98
+ end
99
+ end
100
+
101
+ [:list, :to_hash].each do |method|
102
+ define_method(method) do |*args|
118
103
  collection.load_all
119
-
120
- collection.each do |*args|
121
- yield(*args)
122
- end
123
- end
124
-
125
- class << self
126
- # Allow users to call fact names directly on the Facter class,
127
- # either retrieving the value or comparing it to an existing value.
128
- def method_missing(name, *args)
129
- question = false
130
- if name.to_s =~ /\?$/
131
- question = true
132
- name = name.to_s.sub(/\?$/,'')
104
+ collection.send(method, *args)
105
+ end
106
+ end
107
+ end
108
+
109
+
110
+ # Add a resolution mechanism for a named fact. This does not distinguish
111
+ # between adding a new fact and adding a new way to resolve a fact.
112
+ def self.add(name, options = {}, &block)
113
+ collection.add(name, options, &block)
114
+ end
115
+
116
+ def self.each
117
+ # Make sure all facts are loaded.
118
+ collection.load_all
119
+
120
+ collection.each do |*args|
121
+ yield(*args)
122
+ end
123
+ end
124
+
125
+ class << self
126
+ # Allow users to call fact names directly on the Facter class,
127
+ # either retrieving the value or comparing it to an existing value.
128
+ def method_missing(name, *args)
129
+ question = false
130
+ if name.to_s =~ /\?$/
131
+ question = true
132
+ name = name.to_s.sub(/\?$/,'')
133
+ end
134
+
135
+ if fact = collection.fact(name)
136
+ if question
137
+ value = fact.value.downcase
138
+ args.each do |arg|
139
+ if arg.to_s.downcase == value
140
+ return true
133
141
  end
142
+ end
134
143
 
135
- if fact = collection.fact(name)
136
- if question
137
- value = fact.value.downcase
138
- args.each do |arg|
139
- if arg.to_s.downcase == value
140
- return true
141
- end
142
- end
143
-
144
- # If we got this far, there was no match.
145
- return false
146
- else
147
- return fact.value
148
- end
149
- else
150
- # Else, fail like a normal missing method.
151
- raise NoMethodError, "Could not find fact '%s'" % name
152
- end
144
+ # If we got this far, there was no match.
145
+ return false
146
+ else
147
+ return fact.value
153
148
  end
154
- end
155
-
156
- # Clear all facts. Mostly used for testing.
157
- def self.clear
158
- Facter.flush
159
- Facter.reset
160
- end
161
-
162
- # Clear all messages. Used only in testing. Can't add to self.clear
163
- # because we don't want to warn multiple times for items that are warnonce'd
164
- def self.clear_messages
165
- @@messages.clear
166
- end
167
-
168
- # Set debugging on or off.
169
- def self.debugging(bit)
170
- if bit
171
- case bit
172
- when TrueClass; @@debug = 1
173
- when FalseClass; @@debug = 0
174
- when Fixnum
175
- if bit > 0
176
- @@debug = 1
177
- else
178
- @@debug = 0
179
- end
180
- when String;
181
- if bit.downcase == 'off'
182
- @@debug = 0
183
- else
184
- @@debug = 1
185
- end
186
- else
187
- @@debug = 0
188
- end
149
+ else
150
+ # Else, fail like a normal missing method.
151
+ raise NoMethodError, "Could not find fact '%s'" % name
152
+ end
153
+ end
154
+ end
155
+
156
+ # Clear all facts. Mostly used for testing.
157
+ def self.clear
158
+ Facter.flush
159
+ Facter.reset
160
+ end
161
+
162
+ # Clear all messages. Used only in testing. Can't add to self.clear
163
+ # because we don't want to warn multiple times for items that are warnonce'd
164
+ def self.clear_messages
165
+ @@messages.clear
166
+ end
167
+
168
+ # Set debugging on or off.
169
+ def self.debugging(bit)
170
+ if bit
171
+ case bit
172
+ when TrueClass; @@debug = 1
173
+ when FalseClass; @@debug = 0
174
+ when Fixnum
175
+ if bit > 0
176
+ @@debug = 1
189
177
  else
190
- @@debug = 0
178
+ @@debug = 0
191
179
  end
192
- end
193
-
194
- # Set timing on or off.
195
- def self.timing(bit)
196
- if bit
197
- case bit
198
- when TrueClass; @@timing = 1
199
- when Fixnum
200
- if bit > 0
201
- @@timing = 1
202
- else
203
- @@timing = 0
204
- end
205
- end
180
+ when String;
181
+ if bit.downcase == 'off'
182
+ @@debug = 0
206
183
  else
207
- @@timing = 0
184
+ @@debug = 1
208
185
  end
209
- end
210
-
211
- def self.warn(msg)
212
- if Facter.debugging? and msg and not msg.empty?
213
- msg = [msg] unless msg.respond_to? :each
214
- msg.each { |line| Kernel.warn line }
186
+ else
187
+ @@debug = 0
188
+ end
189
+ else
190
+ @@debug = 0
191
+ end
192
+ end
193
+
194
+ # Set timing on or off.
195
+ def self.timing(bit)
196
+ if bit
197
+ case bit
198
+ when TrueClass; @@timing = 1
199
+ when Fixnum
200
+ if bit > 0
201
+ @@timing = 1
202
+ else
203
+ @@timing = 0
215
204
  end
205
+ end
206
+ else
207
+ @@timing = 0
216
208
  end
209
+ end
217
210
 
218
- # Warn once.
219
- def self.warnonce(msg)
220
- if msg and not msg.empty? and @@messages[msg].nil?
221
- @@messages[msg] = true
222
- Kernel.warn(msg)
223
- end
211
+ def self.warn(msg)
212
+ if Facter.debugging? and msg and not msg.empty?
213
+ msg = [msg] unless msg.respond_to? :each
214
+ msg.each { |line| Kernel.warn line }
224
215
  end
216
+ end
225
217
 
226
- # Remove them all.
227
- def self.reset
228
- @collection = nil
218
+ # Warn once.
219
+ def self.warnonce(msg)
220
+ if msg and not msg.empty? and @@messages[msg].nil?
221
+ @@messages[msg] = true
222
+ Kernel.warn(msg)
229
223
  end
224
+ end
230
225
 
231
- # Load all of the default facts, and then everything from disk.
232
- def self.loadfacts
233
- collection.load_all
234
- end
226
+ # Remove them all.
227
+ def self.reset
228
+ @collection = nil
229
+ end
235
230
 
236
- @search_path = []
231
+ # Load all of the default facts, and then everything from disk.
232
+ def self.loadfacts
233
+ collection.load_all
234
+ end
237
235
 
238
- # Register a directory to search through.
239
- def self.search(*dirs)
240
- @search_path += dirs
241
- end
236
+ @search_path = []
242
237
 
243
- # Return our registered search directories.
244
- def self.search_path
245
- @search_path.dup
246
- end
238
+ # Register a directory to search through.
239
+ def self.search(*dirs)
240
+ @search_path += dirs
241
+ end
242
+
243
+ # Return our registered search directories.
244
+ def self.search_path
245
+ @search_path.dup
246
+ end
247
247
  end
@@ -14,29 +14,29 @@
14
14
  ##
15
15
 
16
16
  Facter.add(:Cfkey) do
17
- setcode do
18
- value = nil
19
- ["/usr/local/etc/cfkey.pub",
20
- "/etc/cfkey.pub",
21
- "/var/cfng/keys/localhost.pub",
22
- "/var/cfengine/ppkeys/localhost.pub",
23
- "/var/lib/cfengine/ppkeys/localhost.pub",
24
- "/var/lib/cfengine2/ppkeys/localhost.pub"
25
- ].each do |file|
26
- if FileTest.file?(file)
27
- File.open(file) { |openfile|
28
- value = openfile.readlines.reject { |line|
29
- line =~ /PUBLIC KEY/
30
- }.collect { |line|
31
- line.chomp
32
- }.join("")
33
- }
34
- end
35
- if value
36
- break
37
- end
38
- end
39
-
40
- value
17
+ setcode do
18
+ value = nil
19
+ ["/usr/local/etc/cfkey.pub",
20
+ "/etc/cfkey.pub",
21
+ "/var/cfng/keys/localhost.pub",
22
+ "/var/cfengine/ppkeys/localhost.pub",
23
+ "/var/lib/cfengine/ppkeys/localhost.pub",
24
+ "/var/lib/cfengine2/ppkeys/localhost.pub"
25
+ ].each do |file|
26
+ if FileTest.file?(file)
27
+ File.open(file) { |openfile|
28
+ value = openfile.readlines.reject { |line|
29
+ line =~ /PUBLIC KEY/
30
+ }.collect { |line|
31
+ line.chomp
32
+ }.join("")
33
+ }
34
+ end
35
+ if value
36
+ break
37
+ end
41
38
  end
39
+
40
+ value
41
+ end
42
42
  end