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
@@ -1,8 +1,8 @@
1
1
  #--###########################################################
2
- # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
- # Patrick May <patrick@hexane.org> #
4
- # #
5
- # Distributed under the MIT license. #
2
+ # Copyright 2006, Ben Bleything <ben@bleything.net> and #
3
+ # Patrick May <patrick@hexane.org> #
4
+ # #
5
+ # Distributed under the MIT license. #
6
6
  ##############################################################
7
7
  #++
8
8
  # Plist parses Mac OS X xml property list files into ruby data structures.
@@ -21,206 +21,206 @@ module Plist
21
21
  # If you encounter such an error, or if you have a Date element which
22
22
  # can't be parsed into a Time object, please send your plist file to
23
23
  # plist@hexane.org so that I can implement the proper support.
24
- def Plist::parse_xml( filename_or_xml )
25
- listener = Listener.new
26
- #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
27
- parser = StreamParser.new(filename_or_xml, listener)
28
- parser.parse
29
- listener.result
24
+ def Plist::parse_xml( filename_or_xml )
25
+ listener = Listener.new
26
+ #parser = REXML::Parsers::StreamParser.new(File.new(filename), listener)
27
+ parser = StreamParser.new(filename_or_xml, listener)
28
+ parser.parse
29
+ listener.result
30
+ end
31
+
32
+ class Listener
33
+ #include REXML::StreamListener
34
+
35
+ attr_accessor :result, :open
36
+
37
+ def initialize
38
+ @result = nil
39
+ @open = Array.new
30
40
  end
31
41
 
32
- class Listener
33
- #include REXML::StreamListener
34
42
 
35
- attr_accessor :result, :open
36
-
37
- def initialize
38
- @result = nil
39
- @open = Array.new
40
- end
41
-
42
-
43
- def tag_start(name, attributes)
44
- @open.push PTag::mappings[name].new
45
- end
46
-
47
- def text( contents )
48
- @open.last.text = contents if @open.last
49
- end
43
+ def tag_start(name, attributes)
44
+ @open.push PTag::mappings[name].new
45
+ end
50
46
 
51
- def tag_end(name)
52
- last = @open.pop
53
- if @open.empty?
54
- @result = last.to_ruby
55
- else
56
- @open.last.children.push last
57
- end
58
- end
47
+ def text( contents )
48
+ @open.last.text = contents if @open.last
59
49
  end
60
50
 
61
- class StreamParser
62
- def initialize( filename_or_xml, listener )
63
- @filename_or_xml = filename_or_xml
64
- @listener = listener
65
- end
51
+ def tag_end(name)
52
+ last = @open.pop
53
+ if @open.empty?
54
+ @result = last.to_ruby
55
+ else
56
+ @open.last.children.push last
57
+ end
58
+ end
59
+ end
66
60
 
67
- TEXT = /([^<]+)/
68
- XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
69
- DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
70
- COMMENT_START = /\A<!--/u
71
- COMMENT_END = /.*?-->/um
72
-
73
- def parse
74
- plist_tags = PTag::mappings.keys.join('|')
75
- start_tag = /<(#{plist_tags})([^>]*)>/i
76
- end_tag = /<\/(#{plist_tags})[^>]*>/i
77
-
78
- require 'strscan'
79
-
80
- contents = (
81
- if (File.exists? @filename_or_xml)
82
- File.open(@filename_or_xml) {|f| f.read}
83
- else
84
- @filename_or_xml
85
- end
86
- )
87
-
88
- @scanner = StringScanner.new( contents )
89
- until @scanner.eos?
90
- if @scanner.scan(COMMENT_START)
91
- @scanner.scan(COMMENT_END)
92
- elsif @scanner.scan(XMLDECL_PATTERN)
93
- elsif @scanner.scan(DOCTYPE_PATTERN)
94
- elsif @scanner.scan(start_tag)
95
- @listener.tag_start(@scanner[1], nil)
96
- if (@scanner[2] =~ /\/$/)
97
- @listener.tag_end(@scanner[1])
98
- end
99
- elsif @scanner.scan(TEXT)
100
- @listener.text(@scanner[1])
101
- elsif @scanner.scan(end_tag)
102
- @listener.tag_end(@scanner[1])
103
- else
104
- raise "Unimplemented element"
105
- end
106
- end
107
- end
61
+ class StreamParser
62
+ def initialize( filename_or_xml, listener )
63
+ @filename_or_xml = filename_or_xml
64
+ @listener = listener
108
65
  end
109
66
 
110
- class PTag
111
- @@mappings = { }
112
- def PTag::mappings
113
- @@mappings
114
- end
67
+ TEXT = /([^<]+)/
68
+ XMLDECL_PATTERN = /<\?xml\s+(.*?)\?>*/um
69
+ DOCTYPE_PATTERN = /\s*<!DOCTYPE\s+(.*?)(\[|>)/um
70
+ COMMENT_START = /\A<!--/u
71
+ COMMENT_END = /.*?-->/um
72
+
73
+ def parse
74
+ plist_tags = PTag::mappings.keys.join('|')
75
+ start_tag = /<(#{plist_tags})([^>]*)>/i
76
+ end_tag = /<\/(#{plist_tags})[^>]*>/i
77
+
78
+ require 'strscan'
79
+
80
+ contents = (
81
+ if (File.exists? @filename_or_xml)
82
+ File.open(@filename_or_xml) {|f| f.read}
83
+ else
84
+ @filename_or_xml
85
+ end
86
+ )
87
+
88
+ @scanner = StringScanner.new( contents )
89
+ until @scanner.eos?
90
+ if @scanner.scan(COMMENT_START)
91
+ @scanner.scan(COMMENT_END)
92
+ elsif @scanner.scan(XMLDECL_PATTERN)
93
+ elsif @scanner.scan(DOCTYPE_PATTERN)
94
+ elsif @scanner.scan(start_tag)
95
+ @listener.tag_start(@scanner[1], nil)
96
+ if (@scanner[2] =~ /\/$/)
97
+ @listener.tag_end(@scanner[1])
98
+ end
99
+ elsif @scanner.scan(TEXT)
100
+ @listener.text(@scanner[1])
101
+ elsif @scanner.scan(end_tag)
102
+ @listener.tag_end(@scanner[1])
103
+ else
104
+ raise "Unimplemented element"
105
+ end
106
+ end
107
+ end
108
+ end
115
109
 
116
- def PTag::inherited( sub_class )
117
- key = sub_class.to_s.downcase
118
- key.gsub!(/^plist::/, '' )
119
- key.gsub!(/^p/, '') unless key == "plist"
110
+ class PTag
111
+ @@mappings = { }
112
+ def PTag::mappings
113
+ @@mappings
114
+ end
120
115
 
121
- @@mappings[key] = sub_class
122
- end
116
+ def PTag::inherited( sub_class )
117
+ key = sub_class.to_s.downcase
118
+ key.gsub!(/^plist::/, '' )
119
+ key.gsub!(/^p/, '') unless key == "plist"
123
120
 
124
- attr_accessor :text, :children
125
- def initialize
126
- @children = Array.new
127
- end
121
+ @@mappings[key] = sub_class
122
+ end
128
123
 
129
- def to_ruby
130
- raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}"
131
- end
124
+ attr_accessor :text, :children
125
+ def initialize
126
+ @children = Array.new
132
127
  end
133
128
 
134
- class PList < PTag
135
- def to_ruby
136
- children.first.to_ruby if children.first
137
- end
129
+ def to_ruby
130
+ raise "Unimplemented: " + self.class.to_s + "#to_ruby on #{self.inspect}"
138
131
  end
132
+ end
139
133
 
140
- class PDict < PTag
141
- def to_ruby
142
- dict = Hash.new
143
- key = nil
134
+ class PList < PTag
135
+ def to_ruby
136
+ children.first.to_ruby if children.first
137
+ end
138
+ end
144
139
 
145
- children.each do |c|
146
- if key.nil?
147
- key = c.to_ruby
148
- else
149
- dict[key] = c.to_ruby
150
- key = nil
151
- end
152
- end
140
+ class PDict < PTag
141
+ def to_ruby
142
+ dict = Hash.new
143
+ key = nil
153
144
 
154
- dict
145
+ children.each do |c|
146
+ if key.nil?
147
+ key = c.to_ruby
148
+ else
149
+ dict[key] = c.to_ruby
150
+ key = nil
155
151
  end
156
- end
152
+ end
157
153
 
158
- class PKey < PTag
159
- def to_ruby
160
- CGI::unescapeHTML(text || '')
161
- end
154
+ dict
162
155
  end
156
+ end
163
157
 
164
- class PString < PTag
165
- def to_ruby
166
- CGI::unescapeHTML(text || '')
167
- end
158
+ class PKey < PTag
159
+ def to_ruby
160
+ CGI::unescapeHTML(text || '')
168
161
  end
162
+ end
169
163
 
170
- class PArray < PTag
171
- def to_ruby
172
- children.collect do |c|
173
- c.to_ruby
174
- end
175
- end
164
+ class PString < PTag
165
+ def to_ruby
166
+ CGI::unescapeHTML(text || '')
176
167
  end
168
+ end
177
169
 
178
- class PInteger < PTag
179
- def to_ruby
180
- text.to_i
181
- end
170
+ class PArray < PTag
171
+ def to_ruby
172
+ children.collect do |c|
173
+ c.to_ruby
174
+ end
182
175
  end
176
+ end
183
177
 
184
- class PTrue < PTag
185
- def to_ruby
186
- true
187
- end
178
+ class PInteger < PTag
179
+ def to_ruby
180
+ text.to_i
188
181
  end
182
+ end
189
183
 
190
- class PFalse < PTag
191
- def to_ruby
192
- false
193
- end
184
+ class PTrue < PTag
185
+ def to_ruby
186
+ true
194
187
  end
188
+ end
195
189
 
196
- class PReal < PTag
197
- def to_ruby
198
- text.to_f
199
- end
190
+ class PFalse < PTag
191
+ def to_ruby
192
+ false
200
193
  end
194
+ end
201
195
 
202
- require 'date'
203
- class PDate < PTag
204
- def to_ruby
205
- DateTime.parse(text)
206
- end
196
+ class PReal < PTag
197
+ def to_ruby
198
+ text.to_f
207
199
  end
200
+ end
208
201
 
209
- require 'base64'
210
- class PData < PTag
211
- def to_ruby
212
- data = Base64.decode64(text.gsub(/\s+/, ''))
213
-
214
- begin
215
- return Marshal.load(data)
216
- rescue Exception => e
217
- io = StringIO.new
218
- io.write data
219
- io.rewind
220
- return io
221
- end
222
- end
202
+ require 'date'
203
+ class PDate < PTag
204
+ def to_ruby
205
+ DateTime.parse(text)
206
+ end
207
+ end
208
+
209
+ require 'base64'
210
+ class PData < PTag
211
+ def to_ruby
212
+ data = Base64.decode64(text.gsub(/\s+/, ''))
213
+
214
+ begin
215
+ return Marshal.load(data)
216
+ rescue Exception => e
217
+ io = StringIO.new
218
+ io.write data
219
+ io.rewind
220
+ return io
221
+ end
223
222
  end
223
+ end
224
224
  end
225
225
 
226
226
  # $Id: parser.rb 1781 2006-10-16 01:01:35Z luke $
@@ -0,0 +1,88 @@
1
+ module Facter::Util::Processor
2
+ def self.enum_cpuinfo
3
+ processor_num = -1
4
+ processor_list = []
5
+ cpuinfo = "/proc/cpuinfo"
6
+
7
+ if File.exists?(cpuinfo)
8
+ model = Facter.value(:architecture)
9
+ case model
10
+ when "x86_64", "amd64", "i386", /parisc/, "hppa", "ia64"
11
+ Thread::exclusive do
12
+ File.readlines(cpuinfo).each do |l|
13
+ if l =~ /processor\s+:\s+(\d+)/
14
+ processor_num = $1.to_i
15
+ elsif l =~ /model name\s+:\s+(.*)\s*$/
16
+ processor_list[processor_num] = $1 unless processor_num == -1
17
+ processor_num = -1
18
+ elsif l =~ /processor\s+(\d+):\s+(.*)/
19
+ processor_num = $1.to_i
20
+ processor_list[processor_num] = $2 unless processor_num == -1
21
+ end
22
+ end
23
+ end
24
+
25
+ when "ppc64"
26
+ Thread::exclusive do
27
+ File.readlines(cpuinfo).each do |l|
28
+ if l =~ /processor\s+:\s+(\d+)/
29
+ processor_num = $1.to_i
30
+ elsif l =~ /cpu\s+:\s+(.*)\s*$/
31
+ processor_list[processor_num] = $1 unless processor_num == -1
32
+ processor_num = -1
33
+ end
34
+ end
35
+ end
36
+
37
+ when /arm/
38
+ Thread::exclusive do
39
+ File.readlines(cpuinfo).each do |l|
40
+ if l =~ /Processor\s+:\s+(.+)/
41
+ processor_num += 1
42
+ processor_list[processor_num] = $1.chomp
43
+ elsif l =~ /processor\s+:\s+(\d+)\s*$/
44
+ proc_num = $1.to_i
45
+ if proc_num != 0
46
+ processor_num += 1
47
+ processor_list[processor_num] = processor_list[processor_num-1]
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ when /sparc/
54
+ Thread::exclusive do
55
+ File.readlines(cpuinfo).each do |l|
56
+ if l =~ /cpu\s+:\s+(.*)\s*$/
57
+ processor_num += 1
58
+ processor_list[processor_num] = $1
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ processor_list
65
+ end
66
+
67
+ def self.enum_lsdev
68
+ processor_num = -1
69
+ processor_list = {}
70
+ Thread::exclusive do
71
+ procs = Facter::Util::Resolution.exec('lsdev -Cc processor')
72
+ if procs
73
+ procs.each_line do |proc|
74
+ if proc =~ /^proc(\d+)/
75
+ processor_num = $1.to_i
76
+ # Not retrieving the frequency since AIX 4.3.3 doesn't support the
77
+ # attribute and some people still use the OS.
78
+ proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a type')
79
+ if proctype =~ /^type\s+(\S+)\s+/
80
+ processor_list[processor_num] = $1
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ processor_list
87
+ end
88
+ end