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
data/lib/facter/processor.rb
CHANGED
@@ -19,90 +19,87 @@
|
|
19
19
|
#
|
20
20
|
|
21
21
|
require 'thread'
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
processor_num = -1
|
33
|
-
elsif l =~ /processor\s+(\d+):\s+(.*)/
|
34
|
-
processor_num = $1.to_i
|
35
|
-
processor_list[processor_num] = $2 unless processor_num == -1
|
36
|
-
end
|
37
|
-
end
|
22
|
+
require 'facter/util/processor'
|
23
|
+
|
24
|
+
Facter.add("ProcessorCount") do
|
25
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
26
|
+
setcode do
|
27
|
+
processor_list = Facter::Util::Processor.enum_cpuinfo
|
28
|
+
|
29
|
+
## If this returned nothing, then don't resolve the fact
|
30
|
+
if processor_list.length != 0
|
31
|
+
processor_list.length.to_s
|
38
32
|
end
|
33
|
+
end
|
34
|
+
end
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
Facter.add("ProcessorCount") do
|
37
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
38
|
+
setcode do
|
39
|
+
## The method above is preferable since it provides the description of the CPU as well
|
40
|
+
## but if that returned 0, then we enumerate sysfs
|
41
|
+
sysfs_cpu_directory = '/sys/devices/system/cpu'
|
42
|
+
if File.exists?(sysfs_cpu_directory)
|
43
|
+
lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu[0-9]*"
|
44
|
+
cpuCount = Dir.glob(lookup_pattern).length
|
45
|
+
cpuCount.to_s
|
45
46
|
end
|
47
|
+
end
|
48
|
+
end
|
46
49
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
50
|
+
Facter.add("ProcessorCount") do
|
51
|
+
confine :kernel => :aix
|
52
|
+
setcode do
|
53
|
+
processor_list = Facter::Util::Processor.enum_lsdev
|
54
|
+
|
55
|
+
processor_list.length.to_s
|
56
|
+
end
|
55
57
|
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
if proc =~ /^proc(\d+)/
|
64
|
-
processor_num = $1.to_i
|
65
|
-
# Not retrieving the frequency since AIX 4.3.3 doesn't support the
|
66
|
-
# attribute and some people still use the OS.
|
67
|
-
proctype = Facter::Util::Resolution.exec('lsattr -El proc0 -a type')
|
68
|
-
if proctype =~ /^type\s+(\S+)\s+/
|
69
|
-
processor_list["processor#{processor_num}"] = $1
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
59
|
+
Facter.add("Processor") do
|
60
|
+
confine :kernel => :openbsd
|
61
|
+
setcode do
|
62
|
+
Facter::Util::Resolution.exec("uname -p")
|
63
|
+
end
|
64
|
+
end
|
74
65
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
66
|
+
Facter.add("ProcessorCount") do
|
67
|
+
confine :kernel => :openbsd
|
68
|
+
setcode do
|
69
|
+
Facter::Util::Resolution.exec("sysctl -n hw.ncpu")
|
70
|
+
end
|
71
|
+
end
|
81
72
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
73
|
+
Facter.add("ProcessorCount") do
|
74
|
+
confine :kernel => :Darwin
|
75
|
+
setcode do
|
76
|
+
Facter::Util::Resolution.exec("sysctl -n hw.ncpu")
|
77
|
+
end
|
90
78
|
end
|
91
79
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
Facter::Util::Resolution.exec("uname -p")
|
97
|
-
end
|
98
|
-
end
|
80
|
+
## We have to enumerate these outside a Facter.add block to get the processorN descriptions iteratively
|
81
|
+
## (but we need them inside the Facter.add block above for tests on processorcount to work)
|
82
|
+
processor_list = Facter::Util::Processor.enum_cpuinfo
|
83
|
+
processor_list_aix = Facter::Util::Processor.enum_lsdev
|
99
84
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
85
|
+
if processor_list.length != 0
|
86
|
+
processor_list.each_with_index do |desc, i|
|
87
|
+
Facter.add("Processor#{i}") do
|
88
|
+
confine :kernel => [ :linux, :"gnu/kfreebsd" ]
|
89
|
+
setcode do
|
90
|
+
desc
|
91
|
+
end
|
105
92
|
end
|
93
|
+
end
|
94
|
+
elsif processor_list_aix.length != 0
|
95
|
+
processor_list_aix.each_with_index do |desc, i|
|
96
|
+
Facter.add("Processor#{i}") do
|
97
|
+
confine :kernel => [ :aix ]
|
98
|
+
setcode do
|
99
|
+
desc
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
106
103
|
end
|
107
104
|
|
108
105
|
if Facter.value(:kernel) == "windows"
|
@@ -142,3 +139,25 @@ if Facter.value(:kernel) == "windows"
|
|
142
139
|
end
|
143
140
|
end
|
144
141
|
end
|
142
|
+
|
143
|
+
Facter.add("Processor") do
|
144
|
+
confine :kernel => :dragonfly
|
145
|
+
setcode do
|
146
|
+
Facter::Util::Resolution.exec("sysctl -n hw.model")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
Facter.add("ProcessorCount") do
|
151
|
+
confine :kernel => :dragonfly
|
152
|
+
setcode do
|
153
|
+
Facter::Util::Resolution.exec("sysctl -n hw.ncpu")
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
Facter.add("processorcount") do
|
158
|
+
confine :kernel => :sunos
|
159
|
+
setcode do
|
160
|
+
kstat = Facter::Util::Resolution.exec("/usr/bin/kstat cpu_info")
|
161
|
+
kstat.scan(/\bcore_id\b\s+\d+/).uniq.length
|
162
|
+
end
|
163
|
+
end
|
data/lib/facter/ps.rb
CHANGED
@@ -11,12 +11,12 @@
|
|
11
11
|
#
|
12
12
|
|
13
13
|
Facter.add(:ps) do
|
14
|
-
|
14
|
+
setcode do 'ps -ef' end
|
15
15
|
end
|
16
16
|
|
17
17
|
Facter.add(:ps) do
|
18
|
-
|
19
|
-
|
18
|
+
confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin DragonFly}
|
19
|
+
setcode do 'ps auxwww' end
|
20
20
|
end
|
21
21
|
|
22
22
|
Facter.add(:ps) do
|
data/lib/facter/puppetversion.rb
CHANGED
@@ -9,12 +9,12 @@
|
|
9
9
|
#
|
10
10
|
|
11
11
|
Facter.add(:puppetversion) do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
12
|
+
setcode do
|
13
|
+
begin
|
14
|
+
require 'puppet'
|
15
|
+
Puppet::PUPPETVERSION.to_s
|
16
|
+
rescue LoadError
|
17
|
+
nil
|
19
18
|
end
|
19
|
+
end
|
20
20
|
end
|
data/lib/facter/rubysitedir.rb
CHANGED
@@ -9,10 +9,10 @@
|
|
9
9
|
#
|
10
10
|
|
11
11
|
Facter.add :rubysitedir do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
12
|
+
setcode do
|
13
|
+
version = RUBY_VERSION.to_s.sub(/\.\d+$/, '')
|
14
|
+
$:.find do |dir|
|
15
|
+
dir =~ /#{File.join("site_ruby", version)}$/
|
17
16
|
end
|
17
|
+
end
|
18
18
|
end
|
data/lib/facter/rubyversion.rb
CHANGED
data/lib/facter/ssh.rb
CHANGED
@@ -12,20 +12,20 @@
|
|
12
12
|
##
|
13
13
|
|
14
14
|
["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
15
|
+
{"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_key.pub", "SSHECDSAKey" => "ssh_host_ecdsa_key.pub"}.each do |name,file|
|
16
|
+
Facter.add(name) do
|
17
|
+
setcode do
|
18
|
+
value = nil
|
19
|
+
filepath = File.join(dir,file)
|
20
|
+
if FileTest.file?(filepath)
|
21
|
+
begin
|
22
|
+
File.open(filepath) { |f| value = f.read.chomp.split(/\s+/)[1] }
|
23
|
+
rescue
|
24
|
+
value = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
value
|
28
|
+
end # end of proc
|
29
|
+
end # end of add
|
30
|
+
end # end of hash each
|
31
31
|
end # end of dir each
|
data/lib/facter/timezone.rb
CHANGED
data/lib/facter/uniqueid.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
Facter.add(:uniqueid) do
|
2
|
-
|
3
|
-
|
2
|
+
setcode 'hostid'
|
3
|
+
confine :operatingsystem => %w{Solaris Linux Fedora RedHat CentOS Scientific SLC SuSE SLES Debian Ubuntu Gentoo AIX OEL OracleLinux OVS GNU/kFreeBSD}
|
4
4
|
end
|
@@ -5,126 +5,126 @@ require 'facter/util/loader'
|
|
5
5
|
# Manage which facts exist and how we access them. Largely just a wrapper
|
6
6
|
# around a hash of facts.
|
7
7
|
class Facter::Util::Collection
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# Add a resolution mechanism for a named fact. This does not distinguish
|
15
|
-
# between adding a new fact and adding a new way to resolve a fact.
|
16
|
-
def add(name, options = {}, &block)
|
17
|
-
name = canonize(name)
|
8
|
+
# Return a fact object by name. If you use this, you still have to call
|
9
|
+
# 'value' on it to retrieve the actual value.
|
10
|
+
def [](name)
|
11
|
+
value(name)
|
12
|
+
end
|
18
13
|
|
19
|
-
|
20
|
-
|
14
|
+
# Add a resolution mechanism for a named fact. This does not distinguish
|
15
|
+
# between adding a new fact and adding a new way to resolve a fact.
|
16
|
+
def add(name, options = {}, &block)
|
17
|
+
name = canonize(name)
|
21
18
|
|
22
|
-
|
23
|
-
|
19
|
+
unless fact = @facts[name]
|
20
|
+
fact = Facter::Util::Fact.new(name)
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
method = opt.to_s + "="
|
28
|
-
if fact.respond_to?(method)
|
29
|
-
fact.send(method, value)
|
30
|
-
options.delete(opt)
|
31
|
-
end
|
32
|
-
end
|
22
|
+
@facts[name] = fact
|
23
|
+
end
|
33
24
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
25
|
+
# Set any fact-appropriate options.
|
26
|
+
options.each do |opt, value|
|
27
|
+
method = opt.to_s + "="
|
28
|
+
if fact.respond_to?(method)
|
29
|
+
fact.send(method, value)
|
30
|
+
options.delete(opt)
|
31
|
+
end
|
32
|
+
end
|
45
33
|
|
46
|
-
|
47
|
-
|
34
|
+
if block
|
35
|
+
resolve = fact.add(&block)
|
36
|
+
# Set any resolve-appropriate options
|
37
|
+
options.each do |opt, value|
|
38
|
+
method = opt.to_s + "="
|
39
|
+
if resolve.respond_to?(method)
|
40
|
+
resolve.send(method, value)
|
41
|
+
options.delete(opt)
|
48
42
|
end
|
43
|
+
end
|
44
|
+
end
|
49
45
|
|
50
|
-
|
46
|
+
unless options.empty?
|
47
|
+
raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",")
|
51
48
|
end
|
52
49
|
|
53
|
-
|
50
|
+
return fact
|
51
|
+
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
53
|
+
include Enumerable
|
54
|
+
|
55
|
+
# Iterate across all of the facts.
|
56
|
+
def each
|
57
|
+
@facts.each do |name, fact|
|
58
|
+
value = fact.value
|
59
|
+
unless value.nil?
|
60
|
+
yield name.to_s, value
|
61
|
+
end
|
63
62
|
end
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
# Return a fact by name.
|
66
|
+
def fact(name)
|
67
|
+
name = canonize(name)
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
# Try to load the fact if necessary
|
70
|
+
loader.load(name) unless @facts[name]
|
71
71
|
|
72
|
-
|
73
|
-
|
72
|
+
# Try HARDER
|
73
|
+
loader.load_all unless @facts[name]
|
74
74
|
|
75
|
-
|
76
|
-
|
75
|
+
@facts[name]
|
76
|
+
end
|
77
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
78
|
+
# Flush all cached values.
|
79
|
+
def flush
|
80
|
+
@facts.each { |name, fact| fact.flush }
|
81
|
+
end
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
def initialize
|
84
|
+
@facts = Hash.new
|
85
|
+
end
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
# Return a list of all of the facts.
|
88
|
+
def list
|
89
|
+
return @facts.keys
|
90
|
+
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
92
|
+
# Load all known facts.
|
93
|
+
def load_all
|
94
|
+
loader.load_all
|
95
|
+
end
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
@loader
|
97
|
+
# The thing that loads facts if we don't have them.
|
98
|
+
def loader
|
99
|
+
unless defined?(@loader)
|
100
|
+
@loader = Facter::Util::Loader.new
|
103
101
|
end
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
102
|
+
@loader
|
103
|
+
end
|
104
|
+
|
105
|
+
# Return a hash of all of our facts.
|
106
|
+
def to_hash
|
107
|
+
@facts.inject({}) do |h, ary|
|
108
|
+
value = ary[1].value
|
109
|
+
if ! value.nil?
|
110
|
+
# For backwards compatibility, convert the fact name to a string.
|
111
|
+
h[ary[0].to_s] = value
|
112
|
+
end
|
113
|
+
h
|
115
114
|
end
|
115
|
+
end
|
116
116
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
end
|
117
|
+
def value(name)
|
118
|
+
if fact = fact(name)
|
119
|
+
fact.value
|
121
120
|
end
|
121
|
+
end
|
122
122
|
|
123
|
-
|
123
|
+
private
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
125
|
+
# Provide a consistent means of getting the exact same fact name
|
126
|
+
# every time.
|
127
|
+
def canonize(name)
|
128
|
+
name.to_s.downcase.to_sym
|
129
|
+
end
|
130
130
|
end
|