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/util/loader.rb
CHANGED
@@ -3,110 +3,110 @@ require 'facter'
|
|
3
3
|
# Load facts on demand.
|
4
4
|
class Facter::Util::Loader
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
def initialize
|
7
|
+
@loaded = []
|
8
|
+
end
|
9
|
+
|
10
|
+
# Load all resolutions for a single fact.
|
11
|
+
def load(fact)
|
12
|
+
# Now load from the search path
|
13
|
+
shortname = fact.to_s.downcase
|
14
|
+
load_env(shortname)
|
15
|
+
|
16
|
+
filename = shortname + ".rb"
|
17
|
+
search_path.each do |dir|
|
18
|
+
# Load individual files
|
19
|
+
file = File.join(dir, filename)
|
20
|
+
|
21
|
+
load_file(file) if FileTest.exist?(file)
|
22
|
+
|
23
|
+
# And load any directories matching the name
|
24
|
+
factdir = File.join(dir, shortname)
|
25
|
+
load_dir(factdir) if FileTest.directory?(factdir)
|
8
26
|
end
|
27
|
+
end
|
9
28
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
shortname = fact.to_s.downcase
|
14
|
-
load_env(shortname)
|
29
|
+
# Load all facts from all directories.
|
30
|
+
def load_all
|
31
|
+
return if defined?(@loaded_all)
|
15
32
|
|
16
|
-
|
17
|
-
search_path.each do |dir|
|
18
|
-
# Load individual files
|
19
|
-
file = File.join(dir, filename)
|
33
|
+
load_env
|
20
34
|
|
21
|
-
|
35
|
+
search_path.each do |dir|
|
36
|
+
next unless FileTest.directory?(dir)
|
22
37
|
|
23
|
-
|
24
|
-
|
25
|
-
|
38
|
+
Dir.entries(dir).sort.each do |file|
|
39
|
+
path = File.join(dir, file)
|
40
|
+
if File.directory?(path)
|
41
|
+
load_dir(path)
|
42
|
+
elsif file =~ /\.rb$/
|
43
|
+
load_file(File.join(dir, file))
|
26
44
|
end
|
45
|
+
end
|
27
46
|
end
|
28
47
|
|
29
|
-
|
30
|
-
|
31
|
-
return if defined?(@loaded_all)
|
48
|
+
@loaded_all = true
|
49
|
+
end
|
32
50
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
path = File.join(dir, file)
|
40
|
-
if File.directory?(path)
|
41
|
-
load_dir(path)
|
42
|
-
elsif file =~ /\.rb$/
|
43
|
-
load_file(File.join(dir, file))
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
@loaded_all = true
|
51
|
+
# The list of directories we're going to search through for facts.
|
52
|
+
def search_path
|
53
|
+
result = []
|
54
|
+
result += $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
55
|
+
if ENV.include?("FACTERLIB")
|
56
|
+
result += ENV["FACTERLIB"].split(":")
|
49
57
|
end
|
50
58
|
|
51
|
-
#
|
52
|
-
|
53
|
-
result = []
|
54
|
-
result += $LOAD_PATH.collect { |d| File.join(d, "facter") }
|
55
|
-
if ENV.include?("FACTERLIB")
|
56
|
-
result += ENV["FACTERLIB"].split(":")
|
57
|
-
end
|
58
|
-
|
59
|
-
# This allows others to register additional paths we should search.
|
60
|
-
result += Facter.search_path
|
59
|
+
# This allows others to register additional paths we should search.
|
60
|
+
result += Facter.search_path
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
result
|
63
|
+
end
|
64
64
|
|
65
|
-
|
65
|
+
private
|
66
66
|
|
67
|
-
|
68
|
-
|
67
|
+
def load_dir(dir)
|
68
|
+
return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
end
|
70
|
+
Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.sort.each do |file|
|
71
|
+
load_file(File.join(dir, file))
|
73
72
|
end
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
73
|
+
end
|
74
|
+
|
75
|
+
def load_file(file)
|
76
|
+
return if @loaded.include? file
|
77
|
+
# We have to specify Kernel.load, because we have a load method.
|
78
|
+
begin
|
79
|
+
# Store the file path so we don't try to reload it
|
80
|
+
@loaded << file
|
81
|
+
Kernel.load(file)
|
82
|
+
rescue ScriptError => detail
|
83
|
+
# Don't store the path if the file can't be loaded
|
84
|
+
# in case it's loadable later on.
|
85
|
+
@loaded.delete(file)
|
86
|
+
warn "Error loading fact #{file} #{detail}"
|
88
87
|
end
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
88
|
+
end
|
89
|
+
|
90
|
+
# Load facts from the environment. If no name is provided,
|
91
|
+
# all will be loaded.
|
92
|
+
def load_env(fact = nil)
|
93
|
+
# Load from the environment, if possible
|
94
|
+
ENV.each do |name, value|
|
95
|
+
# Skip anything that doesn't match our regex.
|
96
|
+
next unless name =~ /^facter_?(\w+)$/i
|
97
|
+
env_name = $1
|
98
|
+
|
99
|
+
# If a fact name was specified, skip anything that doesn't
|
100
|
+
# match it.
|
101
|
+
next if fact and env_name != fact
|
102
|
+
|
103
|
+
Facter.add($1) do
|
104
|
+
has_weight 1_000_000
|
105
|
+
setcode { value }
|
106
|
+
end
|
107
|
+
|
108
|
+
# Short-cut, if we are only looking for one value.
|
109
|
+
break if fact
|
111
110
|
end
|
111
|
+
end
|
112
112
|
end
|
data/lib/facter/util/macosx.rb
CHANGED
@@ -6,56 +6,56 @@
|
|
6
6
|
##
|
7
7
|
|
8
8
|
module Facter::Util::Macosx
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
require 'thread'
|
10
|
+
require 'facter/util/plist'
|
11
|
+
require 'facter/util/resolution'
|
12
|
+
|
13
|
+
# JJM I'd really like to dynamically generate these methods
|
14
|
+
# by looking at the _name key of the _items dict for each _dataType
|
15
|
+
|
16
|
+
def self.profiler_xml(data_field)
|
17
|
+
Facter::Util::Resolution.exec("/usr/sbin/system_profiler -xml #{data_field}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.intern_xml(xml)
|
21
|
+
return nil unless xml
|
22
|
+
Plist::parse_xml(xml)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Return an xml result, modified as we need it.
|
26
|
+
def self.profiler_data(data_field)
|
27
|
+
begin
|
28
|
+
return nil unless parsed_xml = intern_xml(profiler_xml(data_field))
|
29
|
+
return nil unless data = parsed_xml[0]['_items'][0]
|
30
|
+
data.delete '_name'
|
31
|
+
data
|
32
|
+
rescue
|
33
|
+
return nil
|
18
34
|
end
|
35
|
+
end
|
19
36
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
37
|
+
def self.hardware_overview
|
38
|
+
profiler_data("SPHardwareDataType")
|
39
|
+
end
|
24
40
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
return nil unless parsed_xml = intern_xml(profiler_xml(data_field))
|
29
|
-
return nil unless data = parsed_xml[0]['_items'][0]
|
30
|
-
data.delete '_name'
|
31
|
-
data
|
32
|
-
rescue
|
33
|
-
return nil
|
34
|
-
end
|
35
|
-
end
|
41
|
+
def self.os_overview
|
42
|
+
profiler_data("SPSoftwareDataType")
|
43
|
+
end
|
36
44
|
|
37
|
-
|
38
|
-
|
45
|
+
def self.sw_vers
|
46
|
+
ver = Hash.new
|
47
|
+
[ "productName", "productVersion", "buildVersion" ].each do |option|
|
48
|
+
ver["macosx_#{option}"] = Facter::Util::Resolution.exec("/usr/bin/sw_vers -#{option}").strip
|
39
49
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
ver["macosx_#{option}"] = Facter::Util::Resolution.exec("/usr/bin/sw_vers -#{option}").strip
|
49
|
-
end
|
50
|
-
productversion = ver["macosx_productVersion"]
|
51
|
-
if not productversion.nil?
|
52
|
-
versions = productversion.scan(/(\d+)\.(\d+)\.*(\d*)/)[0]
|
53
|
-
ver["macosx_productversion_major"] = "#{versions[0]}.#{versions[1]}"
|
54
|
-
if versions[2].empty? # 10.x should be treated as 10.x.0
|
55
|
-
versions[2] = "0"
|
56
|
-
end
|
57
|
-
ver["macosx_productversion_minor"] = versions[2]
|
58
|
-
end
|
59
|
-
ver
|
50
|
+
productversion = ver["macosx_productVersion"]
|
51
|
+
if not productversion.nil?
|
52
|
+
versions = productversion.scan(/(\d+)\.(\d+)\.*(\d*)/)[0]
|
53
|
+
ver["macosx_productversion_major"] = "#{versions[0]}.#{versions[1]}"
|
54
|
+
if versions[2].empty? # 10.x should be treated as 10.x.0
|
55
|
+
versions[2] = "0"
|
56
|
+
end
|
57
|
+
ver["macosx_productversion_minor"] = versions[2]
|
60
58
|
end
|
59
|
+
ver
|
60
|
+
end
|
61
61
|
end
|
@@ -3,103 +3,103 @@
|
|
3
3
|
|
4
4
|
module Facter::Manufacturer
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.get_dmi_table()
|
7
|
+
case Facter.value(:kernel)
|
8
|
+
when 'Linux', 'GNU/kFreeBSD'
|
9
|
+
return nil unless FileTest.exists?("/usr/sbin/dmidecode")
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
output=%x{/usr/sbin/dmidecode 2>/dev/null}
|
12
|
+
when 'FreeBSD'
|
13
|
+
return nil unless FileTest.exists?("/usr/local/sbin/dmidecode")
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
output=%x{/usr/local/sbin/dmidecode 2>/dev/null}
|
16
|
+
when 'NetBSD'
|
17
|
+
return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
|
20
|
+
when 'SunOS'
|
21
|
+
return nil unless FileTest.exists?("/usr/sbin/smbios")
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
return output
|
23
|
+
output=%x{/usr/sbin/smbios 2>/dev/null}
|
24
|
+
else
|
25
|
+
output=nil
|
28
26
|
end
|
27
|
+
return output
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
30
|
+
def self.dmi_find_system_info(name)
|
31
|
+
splitstr= Facter.value(:kernel) == 'SunOS' ? "ID SIZE TYPE" : /^Handle/
|
32
|
+
output = self.get_dmi_table()
|
33
|
+
return if output.nil?
|
34
|
+
name.each_pair do |key,v|
|
35
|
+
v.each do |v2|
|
36
|
+
v2.each_pair do |value,facterkey|
|
37
|
+
output.split(splitstr).each do |line|
|
38
|
+
if line =~ /#{key}/ and line =~ /\n\s+#{value} (.+)\n/
|
39
|
+
result = $1.strip
|
40
|
+
Facter.add(facterkey) do
|
41
|
+
confine :kernel => [ :linux, :freebsd, :netbsd, :sunos, :"gnu/kfreebsd" ]
|
42
|
+
setcode do
|
43
|
+
result
|
48
44
|
end
|
45
|
+
end
|
49
46
|
end
|
47
|
+
end
|
50
48
|
end
|
49
|
+
end
|
51
50
|
end
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
53
|
+
def self.sysctl_find_system_info(name)
|
54
|
+
name.each do |sysctlkey,facterkey|
|
55
|
+
Facter.add(facterkey) do
|
56
|
+
confine :kernel => [:openbsd, :darwin]
|
57
|
+
setcode do
|
58
|
+
Facter::Util::Resolution.exec("sysctl -n #{sysctlkey} 2>/dev/null")
|
61
59
|
end
|
60
|
+
end
|
62
61
|
end
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
def self.prtdiag_sparc_find_system_info()
|
65
|
+
# Parses prtdiag for a SPARC architecture string, won't work with Solaris x86
|
66
|
+
output = Facter::Util::Resolution.exec('/usr/sbin/prtdiag')
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
Facter.add('productname') do
|
77
|
-
setcode do
|
78
|
-
$3
|
79
|
-
end
|
80
|
-
end
|
68
|
+
# System Configuration: Sun Microsystems sun4u Sun SPARC Enterprise M3000 Server
|
69
|
+
sysconfig = output.split("\n")[0]
|
70
|
+
if sysconfig =~ /^System Configuration:\s+(.+?)\s+(sun\d+\S+)\s+(.+)/ then
|
71
|
+
Facter.add('manufacturer') do
|
72
|
+
setcode do
|
73
|
+
$1
|
81
74
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
end
|
75
|
+
end
|
76
|
+
Facter.add('productname') do
|
77
|
+
setcode do
|
78
|
+
$3
|
87
79
|
end
|
80
|
+
end
|
88
81
|
end
|
89
82
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
83
|
+
Facter.add('serialnumber') do
|
84
|
+
setcode do
|
85
|
+
Facter::Util::Resolution.exec("/usr/sbin/sneep")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.win32_find_system_info(name)
|
91
|
+
require 'facter/util/wmi'
|
92
|
+
value = ""
|
93
|
+
wmi = Facter::Util::WMI.connect()
|
94
|
+
name.each do |facterkey, win32key|
|
95
|
+
query = wmi.ExecQuery("select * from Win32_#{win32key.last}")
|
96
|
+
Facter.add(facterkey) do
|
97
|
+
confine :kernel => :windows
|
98
|
+
setcode do
|
99
|
+
query.each { |x| value = x.__send__( (win32key.first).to_sym) }
|
100
|
+
value
|
103
101
|
end
|
102
|
+
end
|
104
103
|
end
|
104
|
+
end
|
105
105
|
end
|