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
@@ -19,90 +19,87 @@
19
19
  #
20
20
 
21
21
  require 'thread'
22
-
23
- if ["Linux", "GNU/kFreeBSD"].include? Facter.value(:kernel)
24
- processor_num = -1
25
- processor_list = []
26
- Thread::exclusive do
27
- File.readlines("/proc/cpuinfo").each do |l|
28
- if l =~ /processor\s+:\s+(\d+)/
29
- processor_num = $1.to_i
30
- elsif l =~ /model name\s+:\s+(.*)\s*$/
31
- processor_list[processor_num] = $1 unless processor_num == -1
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
- Facter.add("ProcessorCount") do
41
- confine :kernel => [ :linux, :"gnu/kfreebsd" ]
42
- setcode do
43
- processor_list.length.to_s
44
- end
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
- processor_list.each_with_index do |desc, i|
48
- Facter.add("Processor#{i}") do
49
- confine :kernel => [ :linux, :"gnu/kfreebsd" ]
50
- setcode do
51
- desc
52
- end
53
- end
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
- if Facter.value(:kernel) == "AIX"
58
- processor_num = -1
59
- processor_list = {}
60
- Thread::exclusive do
61
- procs = Facter::Util::Resolution.exec('lsdev -Cc processor')
62
- procs.each do |proc|
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
- Facter.add("ProcessorCount") do
76
- confine :kernel => :aix
77
- setcode do
78
- processor_list.length.to_s
79
- end
80
- end
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
- processor_list.each do |proc, desc|
83
- Facter.add(proc) do
84
- confine :kernel => :aix
85
- setcode do
86
- desc
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
- if Facter.value(:kernel) == "OpenBSD"
93
- Facter.add("Processor") do
94
- confine :kernel => :openbsd
95
- setcode do
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
- Facter.add("ProcessorCount") do
101
- confine :kernel => :openbsd
102
- setcode do
103
- Facter::Util::Resolution.exec("sysctl hw.ncpu | cut -d'=' -f2")
104
- end
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
@@ -11,12 +11,12 @@
11
11
  #
12
12
 
13
13
  Facter.add(:ps) do
14
- setcode do 'ps -ef' end
14
+ setcode do 'ps -ef' end
15
15
  end
16
16
 
17
17
  Facter.add(:ps) do
18
- confine :operatingsystem => %w{FreeBSD NetBSD OpenBSD Darwin}
19
- setcode do 'ps auxwww' end
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
@@ -9,12 +9,12 @@
9
9
  #
10
10
 
11
11
  Facter.add(:puppetversion) do
12
- setcode do
13
- begin
14
- require 'puppet'
15
- Puppet::PUPPETVERSION.to_s
16
- rescue LoadError
17
- nil
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
@@ -9,10 +9,10 @@
9
9
  #
10
10
 
11
11
  Facter.add :rubysitedir do
12
- setcode do
13
- version = RUBY_VERSION.to_s.sub(/\.\d+$/, '')
14
- $:.find do |dir|
15
- dir =~ /#{File.join("site_ruby", version)}$/
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
@@ -8,5 +8,5 @@
8
8
  #
9
9
 
10
10
  Facter.add(:rubyversion) do
11
- setcode { RUBY_VERSION.to_s }
11
+ setcode { RUBY_VERSION.to_s }
12
12
  end
@@ -12,20 +12,20 @@
12
12
  ##
13
13
 
14
14
  ["/etc/ssh","/usr/local/etc/ssh","/etc","/usr/local/etc"].each do |dir|
15
- {"SSHDSAKey" => "ssh_host_dsa_key.pub", "SSHRSAKey" => "ssh_host_rsa_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
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
@@ -8,7 +8,7 @@
8
8
  #
9
9
 
10
10
  Facter.add("timezone") do
11
- setcode do
12
- Time.new.zone
13
- end
11
+ setcode do
12
+ Time.new.zone
13
+ end
14
14
  end
@@ -1,4 +1,4 @@
1
1
  Facter.add(:uniqueid) do
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}
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
- # 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
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
- unless fact = @facts[name]
20
- fact = Facter::Util::Fact.new(name)
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
- @facts[name] = fact
23
- end
19
+ unless fact = @facts[name]
20
+ fact = Facter::Util::Fact.new(name)
24
21
 
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
22
+ @facts[name] = fact
23
+ end
33
24
 
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)
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
- unless options.empty?
47
- raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",")
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
- return fact
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
- include Enumerable
50
+ return fact
51
+ end
54
52
 
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
62
- end
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
- # Return a fact by name.
66
- def fact(name)
67
- name = canonize(name)
65
+ # Return a fact by name.
66
+ def fact(name)
67
+ name = canonize(name)
68
68
 
69
- # Try to load the fact if necessary
70
- loader.load(name) unless @facts[name]
69
+ # Try to load the fact if necessary
70
+ loader.load(name) unless @facts[name]
71
71
 
72
- # Try HARDER
73
- loader.load_all unless @facts[name]
72
+ # Try HARDER
73
+ loader.load_all unless @facts[name]
74
74
 
75
- @facts[name]
76
- end
75
+ @facts[name]
76
+ end
77
77
 
78
- # Flush all cached values.
79
- def flush
80
- @facts.each { |name, fact| fact.flush }
81
- end
78
+ # Flush all cached values.
79
+ def flush
80
+ @facts.each { |name, fact| fact.flush }
81
+ end
82
82
 
83
- def initialize
84
- @facts = Hash.new
85
- end
83
+ def initialize
84
+ @facts = Hash.new
85
+ end
86
86
 
87
- # Return a list of all of the facts.
88
- def list
89
- return @facts.keys
90
- end
87
+ # Return a list of all of the facts.
88
+ def list
89
+ return @facts.keys
90
+ end
91
91
 
92
- # Load all known facts.
93
- def load_all
94
- loader.load_all
95
- end
92
+ # Load all known facts.
93
+ def load_all
94
+ loader.load_all
95
+ end
96
96
 
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
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
- # 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
114
- end
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
- def value(name)
118
- if fact = fact(name)
119
- fact.value
120
- end
117
+ def value(name)
118
+ if fact = fact(name)
119
+ fact.value
121
120
  end
121
+ end
122
122
 
123
- private
123
+ private
124
124
 
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
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