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.
- data/CHANGELOG +31 -0
- data/Rakefile +41 -36
- data/conf/redhat/facter.spec +11 -4
- data/conf/solaris/pkginfo +1 -1
- data/install.rb +286 -286
- data/lib/facter.rb +211 -211
- data/lib/facter/Cfkey.rb +24 -24
- data/lib/facter/application.rb +1 -0
- data/lib/facter/architecture.rb +21 -29
- data/lib/facter/domain.rb +34 -34
- data/lib/facter/facterversion.rb +1 -1
- data/lib/facter/fqdn.rb +8 -8
- data/lib/facter/hardwareisa.rb +2 -2
- data/lib/facter/hardwaremodel.rb +12 -12
- data/lib/facter/hostname.rb +14 -14
- data/lib/facter/id.rb +3 -3
- data/lib/facter/interfaces.rb +13 -13
- data/lib/facter/ipaddress.rb +101 -101
- data/lib/facter/iphostnumber.rb +12 -12
- data/lib/facter/kernel.rb +7 -7
- data/lib/facter/kernelmajversion.rb +3 -3
- data/lib/facter/kernelrelease.rb +12 -12
- data/lib/facter/kernelversion.rb +5 -5
- data/lib/facter/lsb.rb +14 -14
- data/lib/facter/lsbmajdistrelease.rb +8 -8
- data/lib/facter/macaddress.rb +44 -44
- data/lib/facter/macosx.rb +21 -21
- data/lib/facter/manufacturer.rb +28 -28
- data/lib/facter/memory.rb +143 -115
- data/lib/facter/netmask.rb +4 -4
- data/lib/facter/network.rb +4 -4
- data/lib/facter/operatingsystem.rb +73 -69
- data/lib/facter/operatingsystemrelease.rb +85 -79
- data/lib/facter/osfamily.rb +31 -0
- data/lib/facter/path.rb +3 -3
- data/lib/facter/physicalprocessorcount.rb +8 -0
- data/lib/facter/processor.rb +91 -72
- data/lib/facter/ps.rb +3 -3
- data/lib/facter/puppetversion.rb +7 -7
- data/lib/facter/rubysitedir.rb +5 -5
- data/lib/facter/rubyversion.rb +1 -1
- data/lib/facter/ssh.rb +16 -16
- data/lib/facter/timezone.rb +3 -3
- data/lib/facter/uniqueid.rb +2 -2
- data/lib/facter/util/collection.rb +96 -96
- data/lib/facter/util/confine.rb +30 -30
- data/lib/facter/util/fact.rb +95 -95
- data/lib/facter/util/ip.rb +173 -173
- data/lib/facter/util/loader.rb +88 -88
- data/lib/facter/util/macosx.rb +46 -46
- data/lib/facter/util/manufacturer.rb +78 -78
- data/lib/facter/util/memory.rb +63 -63
- data/lib/facter/util/netmask.rb +34 -34
- data/lib/facter/util/plist.rb +1 -1
- data/lib/facter/util/plist/generator.rb +177 -177
- data/lib/facter/util/plist/parser.rb +166 -166
- data/lib/facter/util/processor.rb +88 -0
- data/lib/facter/util/resolution.rb +154 -154
- data/lib/facter/util/uptime.rb +42 -42
- data/lib/facter/util/values.rb +9 -9
- data/lib/facter/util/virtual.rb +68 -58
- data/lib/facter/util/vlans.rb +17 -17
- data/lib/facter/virtual.rb +105 -110
- data/lib/facter/vlans.rb +6 -6
- data/spec/fixtures/cpuinfo/amd64dual +57 -0
- data/spec/fixtures/cpuinfo/amd64quad +79 -0
- data/spec/fixtures/cpuinfo/amd64solo +23 -0
- data/spec/fixtures/cpuinfo/amd64tri +86 -0
- data/spec/fixtures/cpuinfo/bbg3-armel +12 -0
- data/spec/fixtures/cpuinfo/beaglexm-armel +12 -0
- data/spec/fixtures/cpuinfo/panda-armel +17 -0
- data/spec/fixtures/cpuinfo/ppc64 +19 -0
- data/spec/fixtures/cpuinfo/sparc +10 -0
- data/spec/fixtures/processorcount/solaris-sparc-kstat-cpu-info +1216 -0
- data/spec/fixtures/processorcount/solaris-x86_64-kstat-cpu-info +225 -0
- data/spec/integration/facter_spec.rb +18 -18
- data/spec/spec_helper.rb +10 -1
- data/spec/unit/architecture_spec.rb +54 -0
- data/spec/unit/domain_spec.rb +23 -0
- data/spec/unit/memory_spec.rb +78 -1
- data/spec/unit/physicalprocessorcount_spec.rb +41 -35
- data/spec/unit/processor_spec.rb +183 -2
- data/spec/unit/util/processor_spec.rb +62 -0
- data/spec/unit/util/uptime_spec.rb +4 -4
- data/spec/unit/util/virtual_spec.rb +26 -5
- data/spec/unit/virtual_spec.rb +47 -2
- data/spec/watchr.rb +125 -0
- metadata +20 -4
@@ -9,179 +9,179 @@ require 'facter/util/config'
|
|
9
9
|
require 'timeout'
|
10
10
|
|
11
11
|
class Facter::Util::Resolution
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
-
|
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
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
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
|
-
|
87
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
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
|
-
|
135
|
-
|
136
|
-
@interpreter = interp
|
137
|
-
end
|
145
|
+
return @suitable
|
146
|
+
end
|
138
147
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
@suitable = ! @confines.detect { |confine| ! confine.true? }
|
143
|
-
end
|
148
|
+
def to_s
|
149
|
+
return self.value()
|
150
|
+
end
|
144
151
|
|
145
|
-
|
146
|
-
|
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
|
-
|
149
|
-
return self.value()
|
150
|
-
end
|
157
|
+
starttime = Time.now.to_f
|
151
158
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|
-
|
181
|
-
|
182
|
-
|
180
|
+
finishtime = Time.now.to_f
|
181
|
+
ms = (finishtime - starttime) * 1000
|
182
|
+
Facter.show_time "#{self.name}: #{"%.2f" % ms}ms"
|
183
183
|
|
184
|
-
|
185
|
-
|
186
|
-
|
184
|
+
return nil if result == ""
|
185
|
+
return result
|
186
|
+
end
|
187
187
|
end
|
data/lib/facter/util/uptime.rb
CHANGED
@@ -3,63 +3,63 @@ require 'time'
|
|
3
3
|
# A module to gather uptime facts
|
4
4
|
#
|
5
5
|
module Facter::Util::Uptime
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
11
|
-
|
10
|
+
def self.get_uptime_seconds_win
|
11
|
+
require 'facter/util/wmi'
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
20
|
+
private
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def self.compute_uptime(time)
|
47
|
+
(Time.now - time).to_i
|
48
|
+
end
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
def self.uptime_file
|
51
|
+
"/proc/uptime"
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def self.uptime_sysctl_cmd
|
55
|
+
'sysctl -b kern.boottime'
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
def self.uptime_kstat_cmd
|
59
|
+
'kstat -p unix:::boot_time'
|
60
|
+
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
62
|
+
def self.uptime_who_cmd
|
63
|
+
'who -b'
|
64
|
+
end
|
65
65
|
end
|
data/lib/facter/util/values.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# A util module for facter containing helper methods
|
2
2
|
module Facter
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Util
|
4
|
+
module Values
|
5
|
+
module_function
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|