facter 1.7.6 → 2.0.1.rc1

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 (155) hide show
  1. checksums.yaml +7 -0
  2. data/COMMITTERS.md +194 -0
  3. data/CONTRIBUTING.md +63 -235
  4. data/Gemfile +12 -8
  5. data/README.md +1 -2
  6. data/Rakefile +1 -1
  7. data/bin/facter +0 -4
  8. data/ext/build_defaults.yaml +2 -2
  9. data/ext/project_data.yaml +18 -0
  10. data/install.rb +1 -16
  11. data/lib/facter.rb +171 -171
  12. data/lib/facter/application.rb +65 -54
  13. data/lib/facter/core/aggregate.rb +220 -0
  14. data/lib/facter/core/directed_graph.rb +46 -0
  15. data/lib/facter/core/execution.rb +100 -0
  16. data/lib/facter/core/execution/base.rb +73 -0
  17. data/lib/facter/core/execution/posix.rb +50 -0
  18. data/lib/facter/core/execution/windows.rb +57 -0
  19. data/lib/facter/core/logging.rb +169 -0
  20. data/lib/facter/core/resolvable.rb +94 -0
  21. data/lib/facter/core/suitable.rb +117 -0
  22. data/lib/facter/domain.rb +15 -9
  23. data/lib/facter/filesystems.rb +1 -1
  24. data/lib/facter/hardwaremodel.rb +1 -1
  25. data/lib/facter/hostname.rb +3 -3
  26. data/lib/facter/interfaces.rb +6 -1
  27. data/lib/facter/ipaddress.rb +2 -2
  28. data/lib/facter/kernel.rb +1 -1
  29. data/lib/facter/kernelrelease.rb +1 -1
  30. data/lib/facter/ldom.rb +1 -1
  31. data/lib/facter/lsbdistcodename.rb +1 -1
  32. data/lib/facter/lsbdistdescription.rb +1 -1
  33. data/lib/facter/lsbdistid.rb +1 -1
  34. data/lib/facter/lsbdistrelease.rb +1 -1
  35. data/lib/facter/lsbrelease.rb +1 -1
  36. data/lib/facter/macaddress.rb +1 -14
  37. data/lib/facter/macosx.rb +2 -2
  38. data/lib/facter/memory.rb +8 -19
  39. data/lib/facter/operatingsystem.rb +1 -1
  40. data/lib/facter/operatingsystemrelease.rb +34 -1
  41. data/lib/facter/physicalprocessorcount.rb +6 -6
  42. data/lib/facter/processor.rb +11 -10
  43. data/lib/facter/selinux.rb +4 -15
  44. data/lib/facter/ssh.rb +5 -2
  45. data/lib/facter/util/architecture.rb +2 -2
  46. data/lib/facter/util/collection.rb +42 -38
  47. data/lib/facter/util/config.rb +19 -9
  48. data/lib/facter/util/confine.rb +34 -4
  49. data/lib/facter/util/ec2.rb +1 -1
  50. data/lib/facter/util/fact.rb +108 -36
  51. data/lib/facter/util/file_read.rb +7 -6
  52. data/lib/facter/util/formatter.rb +38 -0
  53. data/lib/facter/util/ip.rb +3 -3
  54. data/lib/facter/util/loader.rb +62 -42
  55. data/lib/facter/util/macosx.rb +7 -8
  56. data/lib/facter/util/manufacturer.rb +3 -3
  57. data/lib/facter/util/memory.rb +13 -13
  58. data/lib/facter/util/monkey_patches.rb +0 -31
  59. data/lib/facter/util/netmask.rb +3 -3
  60. data/lib/facter/util/normalization.rb +94 -0
  61. data/lib/facter/util/nothing_loader.rb +3 -6
  62. data/lib/facter/util/parser.rb +3 -5
  63. data/lib/facter/util/plist/generator.rb +1 -1
  64. data/lib/facter/util/processor.rb +15 -15
  65. data/lib/facter/util/resolution.rb +112 -289
  66. data/lib/facter/util/solaris_zones.rb +4 -4
  67. data/lib/facter/util/uptime.rb +8 -3
  68. data/lib/facter/util/values.rb +67 -1
  69. data/lib/facter/util/virtual.rb +10 -10
  70. data/lib/facter/util/xendomains.rb +1 -1
  71. data/lib/facter/version.rb +42 -39
  72. data/lib/facter/virtual.rb +6 -7
  73. data/lib/facter/zfs_version.rb +3 -3
  74. data/lib/facter/zpool_version.rb +3 -3
  75. data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
  76. data/spec/unit/application_spec.rb +46 -1
  77. data/spec/unit/core/aggregate_spec.rb +125 -0
  78. data/spec/unit/core/directed_graph_spec.rb +79 -0
  79. data/spec/unit/core/execution/base_spec.rb +119 -0
  80. data/spec/unit/core/execution/posix_spec.rb +86 -0
  81. data/spec/unit/core/execution/windows_spec.rb +106 -0
  82. data/spec/unit/core/execution_spec.rb +37 -0
  83. data/spec/unit/core/logging_spec.rb +104 -0
  84. data/spec/unit/core/resolvable_spec.rb +81 -0
  85. data/spec/unit/core/suitable_spec.rb +96 -0
  86. data/spec/unit/domain_spec.rb +5 -5
  87. data/spec/unit/facter_spec.rb +61 -222
  88. data/spec/unit/filesystems_spec.rb +2 -2
  89. data/spec/unit/hardwareisa_spec.rb +5 -5
  90. data/spec/unit/hardwaremodel_spec.rb +1 -1
  91. data/spec/unit/hostname_spec.rb +4 -4
  92. data/spec/unit/id_spec.rb +3 -3
  93. data/spec/unit/interfaces_spec.rb +10 -0
  94. data/spec/unit/ipaddress6_spec.rb +4 -4
  95. data/spec/unit/ipaddress_spec.rb +1 -1
  96. data/spec/unit/kernel_spec.rb +2 -2
  97. data/spec/unit/kernelmajversion_spec.rb +1 -1
  98. data/spec/unit/kernelrelease_spec.rb +4 -4
  99. data/spec/unit/kernelversion_spec.rb +2 -2
  100. data/spec/unit/ldom_spec.rb +2 -2
  101. data/spec/unit/lsbdistcodename_spec.rb +2 -2
  102. data/spec/unit/lsbdistdescription_spec.rb +2 -2
  103. data/spec/unit/lsbdistid_spec.rb +2 -2
  104. data/spec/unit/lsbdistrelease_spec.rb +2 -2
  105. data/spec/unit/lsbrelease_spec.rb +2 -2
  106. data/spec/unit/manufacturer_spec.rb +1 -1
  107. data/spec/unit/memory_spec.rb +24 -31
  108. data/spec/unit/netmask_spec.rb +9 -0
  109. data/spec/unit/operatingsystem_spec.rb +1 -1
  110. data/spec/unit/operatingsystemrelease_spec.rb +62 -4
  111. data/spec/unit/physicalprocessorcount_spec.rb +10 -10
  112. data/spec/unit/processor_spec.rb +11 -11
  113. data/spec/unit/selinux_spec.rb +2 -8
  114. data/spec/unit/ssh_spec.rb +3 -2
  115. data/spec/unit/uniqueid_spec.rb +3 -3
  116. data/spec/unit/util/collection_spec.rb +37 -35
  117. data/spec/unit/util/config_spec.rb +20 -0
  118. data/spec/unit/util/confine_spec.rb +21 -0
  119. data/spec/unit/util/directory_loader_spec.rb +1 -0
  120. data/spec/unit/util/ec2_spec.rb +6 -6
  121. data/spec/unit/util/fact_spec.rb +92 -90
  122. data/spec/unit/util/ip_spec.rb +2 -2
  123. data/spec/unit/util/loader_spec.rb +127 -186
  124. data/spec/unit/util/macaddress_spec.rb +2 -2
  125. data/spec/unit/util/macosx_spec.rb +8 -8
  126. data/spec/unit/util/manufacturer_spec.rb +3 -3
  127. data/spec/unit/util/normalization_spec.rb +113 -0
  128. data/spec/unit/util/parser_spec.rb +25 -3
  129. data/spec/unit/util/processor_spec.rb +2 -2
  130. data/spec/unit/util/resolution_spec.rb +60 -631
  131. data/spec/unit/util/solaris_zones_spec.rb +5 -5
  132. data/spec/unit/util/uptime_spec.rb +1 -1
  133. data/spec/unit/util/values_spec.rb +131 -0
  134. data/spec/unit/util/virtual_spec.rb +16 -16
  135. data/spec/unit/util/xendomains_spec.rb +2 -2
  136. data/spec/unit/virtual_spec.rb +39 -39
  137. data/spec/unit/zfs_version_spec.rb +11 -11
  138. data/spec/unit/zonename_spec.rb +2 -2
  139. data/spec/unit/zones_spec.rb +1 -1
  140. data/spec/unit/zpool_version_spec.rb +11 -11
  141. metadata +466 -447
  142. data/lib/facter/util/cfpropertylist.rb +0 -6
  143. data/lib/facter/util/cfpropertylist/LICENSE +0 -19
  144. data/lib/facter/util/cfpropertylist/README +0 -44
  145. data/lib/facter/util/cfpropertylist/Rakefile +0 -44
  146. data/lib/facter/util/cfpropertylist/THANKS +0 -7
  147. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
  148. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
  149. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
  150. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
  151. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
  152. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
  153. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
  154. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
  155. data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -24,9 +24,9 @@
24
24
  # at this point in time.
25
25
  # In particular, Installed Software might be an interesting addition.
26
26
 
27
- require 'facter/util/macosx'
28
-
29
27
  if Facter.value(:kernel) == "Darwin"
28
+ require 'facter/util/macosx'
29
+
30
30
  Facter::Util::Macosx.hardware_overview.each do |fact, value|
31
31
  Facter.add("sp_#{fact}") do
32
32
  confine :kernel => :darwin
@@ -86,7 +86,7 @@ if Facter.value(:kernel) == "Darwin"
86
86
  Facter.add("SwapEncrypted") do
87
87
  confine :kernel => :Darwin
88
88
  setcode do
89
- swap = Facter::Util::Resolution.exec('sysctl vm.swapusage')
89
+ swap = Facter::Core::Execution.exec('sysctl vm.swapusage')
90
90
  encrypted = false
91
91
  if swap =~ /\(encrypted\)/ then encrypted = true; end
92
92
  encrypted
@@ -99,7 +99,7 @@ if Facter.value(:kernel) == "SunOS"
99
99
  Facter.add("memorysize_mb") do
100
100
  confine :kernel => :sunos
101
101
  # Total memory size available from prtconf
102
- pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf 2>/dev/null')
102
+ pconf = Facter::Core::Execution.exec('/usr/sbin/prtconf 2>/dev/null')
103
103
  phymem = ""
104
104
  pconf.each_line do |line|
105
105
  if line =~ /^Memory size:\s+(\d+) Megabytes/
@@ -143,8 +143,8 @@ end
143
143
  Facter.add("swapsize_mb") do
144
144
  confine :kernel => :dragonfly
145
145
  setcode do
146
- page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f
147
- swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
146
+ page_size = Facter::Core::Execution.exec("/sbin/sysctl -n hw.pagesize").to_f
147
+ swaptotal = Facter::Core::Execution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
148
148
  "%.2f" % [(swaptotal.to_f / 1024.0) / 1024.0]
149
149
  end
150
150
  end
@@ -152,22 +152,11 @@ end
152
152
  Facter.add("swapfree_mb") do
153
153
  confine :kernel => :dragonfly
154
154
  setcode do
155
- page_size = Facter::Util::Resolution.exec("/sbin/sysctl -n hw.pagesize").to_f
156
- swaptotal = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
157
- swap_anon_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_anon_use").to_f * page_size
158
- swap_cache_use = Facter::Util::Resolution.exec("/sbin/sysctl -n vm.swap_cache_use").to_f * page_size
155
+ page_size = Facter::Core::Execution.exec("/sbin/sysctl -n hw.pagesize").to_f
156
+ swaptotal = Facter::Core::Execution.exec("/sbin/sysctl -n vm.swap_size").to_f * page_size
157
+ swap_anon_use = Facter::Core::Execution.exec("/sbin/sysctl -n vm.swap_anon_use").to_f * page_size
158
+ swap_cache_use = Facter::Core::Execution.exec("/sbin/sysctl -n vm.swap_cache_use").to_f * page_size
159
159
  swapfree = swaptotal - swap_anon_use - swap_cache_use
160
160
  "%.2f" % [(swapfree.to_f / 1024.0) / 1024.0]
161
161
  end
162
162
  end
163
-
164
- # http://projects.puppetlabs.com/issues/11436
165
- #
166
- # Unifying naming for the amount of physical memory in a given host.
167
- # This fact is DEPRECATED and will be removed in Facter 2.0 per
168
- # http://projects.puppetlabs.com/issues/11466
169
- Facter.add("MemoryTotal") do
170
- setcode do
171
- Facter.value("memorysize")
172
- end
173
- end
@@ -16,7 +16,7 @@ Facter.add(:operatingsystem) do
16
16
  setcode do
17
17
  # Use uname -v because /etc/release can change in zones under SmartOS.
18
18
  # It's apparently not trustworthy enough to rely on for this fact.
19
- output = Facter::Util::Resolution.exec('uname -v')
19
+ output = Facter::Core::Execution.exec('uname -v')
20
20
  if output =~ /^joyent_/
21
21
  "SmartOS"
22
22
  elsif output =~ /^oi_/
@@ -141,7 +141,7 @@ end
141
141
  Facter.add(:operatingsystemrelease) do
142
142
  confine :operatingsystem => %w{VMwareESX}
143
143
  setcode do
144
- release = Facter::Util::Resolution.exec('vmware -v')
144
+ release = Facter::Core::Execution.exec('vmware -v')
145
145
  if match = /VMware ESX .*?(\d.*)/.match(release)
146
146
  match[1]
147
147
  end
@@ -188,6 +188,39 @@ Facter.add(:operatingsystemrelease) do
188
188
  end
189
189
  end
190
190
 
191
+ Facter.add(:operatingsystemrelease) do
192
+ confine :operatingsystem => :windows
193
+ setcode do
194
+ require 'facter/util/wmi'
195
+ result = nil
196
+ Facter::Util::WMI.execquery("SELECT version, producttype FROM Win32_OperatingSystem").each do |os|
197
+ result =
198
+ case os.version
199
+ when /^6\.2/
200
+ os.producttype == 1 ? "8" : "2012"
201
+ when /^6\.1/
202
+ os.producttype == 1 ? "7" : "2008 R2"
203
+ when /^6\.0/
204
+ os.producttype == 1 ? "Vista" : "2008"
205
+ when /^5\.2/
206
+ if os.producttype == 1
207
+ "XP"
208
+ else
209
+ begin
210
+ os.othertypedescription == "R2" ? "2003 R2" : "2003"
211
+ rescue NoMethodError
212
+ "2003"
213
+ end
214
+ end
215
+ else
216
+ Facter[:kernelrelease].value
217
+ end
218
+ break
219
+ end
220
+ result
221
+ end
222
+ end
223
+
191
224
  Facter.add(:operatingsystemrelease) do
192
225
  setcode do Facter[:kernelrelease].value end
193
226
  end
@@ -39,7 +39,7 @@ Facter.add('physicalprocessorcount') do
39
39
  lookup_pattern = "#{sysfs_cpu_directory}" +
40
40
  "/cpu*/topology/physical_package_id"
41
41
 
42
- Dir.glob(lookup_pattern).collect { |f| Facter::Util::Resolution.exec("cat #{f}")}.uniq.size
42
+ Dir.glob(lookup_pattern).collect { |f| Facter::Core::Execution.exec("cat #{f}")}.uniq.size.to_s
43
43
 
44
44
  else
45
45
  #
@@ -48,9 +48,9 @@ Facter.add('physicalprocessorcount') do
48
48
  # We assume that /proc/cpuinfo has what we need and is so then we need
49
49
  # to make sure that we only count unique entries ...
50
50
  #
51
- str = Facter::Util::Resolution.exec("grep 'physical.\\+:' /proc/cpuinfo")
51
+ str = Facter::Core::Execution.exec("grep 'physical.\\+:' /proc/cpuinfo")
52
52
 
53
- if str then str.scan(/\d+/).uniq.size; end
53
+ if str then str.scan(/\d+/).uniq.size.to_s; end
54
54
  end
55
55
  end
56
56
  end
@@ -59,7 +59,7 @@ Facter.add('physicalprocessorcount') do
59
59
  confine :kernel => :windows
60
60
  setcode do
61
61
  require 'facter/util/wmi'
62
- Facter::Util::WMI.execquery("select Name from Win32_Processor").Count
62
+ Facter::Util::WMI.execquery("select Name from Win32_Processor").Count.to_s
63
63
  end
64
64
  end
65
65
 
@@ -75,9 +75,9 @@ Facter.add('physicalprocessorcount') do
75
75
  cmd = "/usr/sbin/psrinfo"
76
76
  result = nil
77
77
  if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
78
- result = Facter::Util::Resolution.exec("#{cmd} -p")
78
+ result = Facter::Core::Execution.exec("#{cmd} -p")
79
79
  else
80
- output = Facter::Util::Resolution.exec(cmd)
80
+ output = Facter::Core::Execution.exec(cmd)
81
81
  result = output.split("\n").length.to_s
82
82
  end
83
83
  end
@@ -22,8 +22,9 @@
22
22
  require 'thread'
23
23
  require 'facter/util/processor'
24
24
 
25
- ## We have to enumerate these outside a Facter.add block to get the processorN descriptions iteratively
26
- ## (but we need them inside the Facter.add block above for tests on processorcount to work)
25
+ # We have to enumerate these outside a Facter.add block to get the processorN
26
+ # descriptions iteratively (but we need them inside the Facter.add block above
27
+ # for tests on processorcount to work)
27
28
  processor_list = case Facter::Util::Processor.kernel_fact_value
28
29
  when "AIX"
29
30
  Facter::Util::Processor.aix_processor_list
@@ -90,21 +91,21 @@ end
90
91
  Facter.add("Processor") do
91
92
  confine :kernel => :openbsd
92
93
  setcode do
93
- Facter::Util::Resolution.exec("uname -p")
94
+ Facter::Core::Execution.exec("uname -p")
94
95
  end
95
96
  end
96
97
 
97
98
  Facter.add("ProcessorCount") do
98
99
  confine :kernel => :openbsd
99
100
  setcode do
100
- Facter::Util::Resolution.exec("sysctl -n hw.ncpu")
101
+ Facter::Core::Execution.exec("sysctl -n hw.ncpu")
101
102
  end
102
103
  end
103
104
 
104
105
  Facter.add("ProcessorCount") do
105
106
  confine :kernel => :Darwin
106
107
  setcode do
107
- Facter::Util::Resolution.exec("sysctl -n hw.ncpu")
108
+ Facter::Core::Execution.exec("sysctl -n hw.ncpu")
108
109
  end
109
110
  end
110
111
 
@@ -149,14 +150,14 @@ end
149
150
  Facter.add("Processor") do
150
151
  confine :kernel => [:dragonfly,:freebsd]
151
152
  setcode do
152
- Facter::Util::Resolution.exec("sysctl -n hw.model")
153
+ Facter::Core::Execution.exec("sysctl -n hw.model")
153
154
  end
154
155
  end
155
156
 
156
157
  Facter.add("ProcessorCount") do
157
158
  confine :kernel => [:dragonfly,:freebsd]
158
159
  setcode do
159
- Facter::Util::Resolution.exec("sysctl -n hw.ncpu")
160
+ Facter::Core::Execution.exec("sysctl -n hw.ncpu")
160
161
  end
161
162
  end
162
163
 
@@ -168,15 +169,15 @@ Facter.add("ProcessorCount") do
168
169
  result = nil
169
170
 
170
171
  if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
171
- if kstat = Facter::Util::Resolution.exec("/usr/bin/kstat cpu_info")
172
+ if kstat = Facter::Core::Execution.exec("/usr/bin/kstat cpu_info")
172
173
  result = kstat.scan(/\bcore_id\b\s+\d+/).uniq.length
173
174
  end
174
175
  else
175
- if output = Facter::Util::Resolution.exec("/usr/sbin/psrinfo") then
176
+ if output = Facter::Core::Execution.exec("/usr/sbin/psrinfo") then
176
177
  result = output.split("\n").length
177
178
  end
178
179
  end
179
180
 
180
- result
181
+ result.to_s
181
182
  end
182
183
  end
@@ -22,7 +22,7 @@ def selinux_mount_point
22
22
  # a hang. Reading from other parts of /proc does not seem to cause this problem.
23
23
  # The work around is to read the file in another process.
24
24
  # -- andy Fri Aug 31 2012
25
- selinux_line = Facter::Util::Resolution.exec('cat /proc/self/mounts').lines.find { |line| line =~ /selinuxfs/ }
25
+ selinux_line = Facter::Core::Execution.exec('cat /proc/self/mounts').each_line.find { |line| line =~ /selinuxfs/ }
26
26
  if selinux_line
27
27
  path = selinux_line.split[1]
28
28
  end
@@ -72,7 +72,7 @@ Facter.add("selinux_current_mode") do
72
72
  confine :selinux => :true
73
73
  setcode do
74
74
  result = 'unknown'
75
- mode = Facter::Util::Resolution.exec(sestatus_cmd)
75
+ mode = Facter::Core::Execution.exec(sestatus_cmd)
76
76
  mode.each_line { |l| result = $1 if l =~ /^Current mode\:\s+(\w+)$/i }
77
77
  result.chomp
78
78
  end
@@ -82,7 +82,7 @@ Facter.add("selinux_config_mode") do
82
82
  confine :selinux => :true
83
83
  setcode do
84
84
  result = 'unknown'
85
- mode = Facter::Util::Resolution.exec(sestatus_cmd)
85
+ mode = Facter::Core::Execution.exec(sestatus_cmd)
86
86
  mode.each_line { |l| result = $1 if l =~ /^Mode from config file\:\s+(\w+)$/i }
87
87
  result.chomp
88
88
  end
@@ -92,19 +92,8 @@ Facter.add("selinux_config_policy") do
92
92
  confine :selinux => :true
93
93
  setcode do
94
94
  result = 'unknown'
95
- mode = Facter::Util::Resolution.exec(sestatus_cmd)
95
+ mode = Facter::Core::Execution.exec(sestatus_cmd)
96
96
  mode.each_line { |l| result = $1 if l =~ /^Policy from config file\:\s+(\w+)$/i }
97
97
  result.chomp
98
98
  end
99
99
  end
100
-
101
- # This is a legacy fact which returns the old selinux_mode fact value to prevent
102
- # breakages of existing manifests. It should be removed at the next major release.
103
- # See ticket #6677.
104
-
105
- Facter.add("selinux_mode") do
106
- confine :selinux => :true
107
- setcode do
108
- Facter.value(:selinux_config_policy)
109
- end
110
- end
@@ -11,8 +11,11 @@
11
11
  ## Facts related to SSH
12
12
  ##
13
13
 
14
- {"SSHDSAKey" => { :file => "ssh_host_dsa_key.pub", :sshfprrtype => 2 } , "SSHRSAKey" => { :file => "ssh_host_rsa_key.pub", :sshfprrtype => 1 }, "SSHECDSAKey" => { :file => "ssh_host_ecdsa_key.pub", :sshfprrtype => 3 } }.each do |name,key|
15
-
14
+ {"SSHDSAKey" => { :file => "ssh_host_dsa_key.pub", :sshfprrtype => 2 },
15
+ "SSHRSAKey" => { :file => "ssh_host_rsa_key.pub", :sshfprrtype => 1 },
16
+ "SSHECDSAKey" => { :file => "ssh_host_ecdsa_key.pub", :sshfprrtype => 3 },
17
+ "SSHED25519Key" => { :file => "ssh_host_ed25519_key.pub", :sshfprrtype => 4 } }.each do |name,key|
18
+
16
19
  Facter.add(name) do
17
20
  setcode do
18
21
  value = nil
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Facter::Util::Architecture
4
4
  ##
5
- # lsattr is intended to directly delegate to Facter::Util::Resolution.exec in
5
+ # lsattr is intended to directly delegate to Facter::Core::Execution.exec in
6
6
  # an effort to make the processorX facts easier to test. See also the
7
7
  # {lsdev} method.
8
8
  def self.lsattr(command="lsattr -El proc0 -a type")
9
- Facter::Util::Resolution.exec(command)
9
+ Facter::Core::Execution.exec(command)
10
10
  end
11
11
 
12
12
  ##
@@ -4,6 +4,8 @@ require 'facter/util/loader'
4
4
 
5
5
  # Manage which facts exist and how we access them. Largely just a wrapper
6
6
  # around a hash of facts.
7
+ #
8
+ # @api private
7
9
  class Facter::Util::Collection
8
10
 
9
11
  def initialize(internal_loader, external_loader)
@@ -12,53 +14,40 @@ class Facter::Util::Collection
12
14
  @external_loader = external_loader
13
15
  end
14
16
 
15
- # Return a fact object by name. If you use this, you still have to call
16
- # 'value' on it to retrieve the actual value.
17
+ # Return a fact object by name.
17
18
  def [](name)
18
19
  value(name)
19
20
  end
20
21
 
21
- # Add a resolution mechanism for a named fact. This does not distinguish
22
- # between adding a new fact and adding a new way to resolve a fact.
23
- def add(name, options = {}, &block)
24
- name = canonicalize(name)
25
-
26
- unless fact = @facts[name]
27
- fact = Facter::Util::Fact.new(name)
28
-
29
- @facts[name] = fact
30
- end
31
-
32
- # Set any fact-appropriate options.
33
- options.each do |opt, value|
34
- method = opt.to_s + "="
35
- if fact.respond_to?(method)
36
- fact.send(method, value)
37
- options.delete(opt)
38
- end
39
- end
22
+ # Define a new fact or extend an existing fact.
23
+ #
24
+ # @param name [Symbol] The name of the fact to define
25
+ # @param options [Hash] A hash of options to set on the fact
26
+ #
27
+ # @return [Facter::Util::Fact] The fact that was defined
28
+ def define_fact(name, options = {}, &block)
29
+ fact = create_or_return_fact(name, options)
40
30
 
41
31
  if block_given?
42
- resolve = fact.add(&block)
43
- else
44
- resolve = fact.add
32
+ fact.instance_eval(&block)
45
33
  end
46
34
 
47
- # Set any resolve-appropriate options
48
- if resolve
49
- # If the resolve was actually added, set any resolve-appropriate options
50
- options.each do |opt, value|
51
- method = opt.to_s + "="
52
- if resolve.respond_to?(method)
53
- resolve.send(method, value)
54
- options.delete(opt)
55
- end
56
- end
57
- end
35
+ fact
36
+ rescue => e
37
+ Facter.log_exception(e, "Unable to add fact #{name}: #{e}")
38
+ end
58
39
 
59
- unless options.empty?
60
- raise ArgumentError, "Invalid facter option(s) %s" % options.keys.collect { |k| k.to_s }.join(",")
61
- end
40
+ # Add a resolution mechanism for a named fact. This does not distinguish
41
+ # between adding a new fact and adding a new way to resolve a fact.
42
+ #
43
+ # @param name [Symbol] The name of the fact to define
44
+ # @param options [Hash] A hash of options to set on the fact and resolution
45
+ #
46
+ # @return [Facter::Util::Fact] The fact that was defined
47
+ def add(name, options = {}, &block)
48
+ fact = create_or_return_fact(name, options)
49
+
50
+ fact.add(options, &block)
62
51
 
63
52
  return fact
64
53
  end
@@ -144,6 +133,21 @@ class Facter::Util::Collection
144
133
 
145
134
  private
146
135
 
136
+ def create_or_return_fact(name, options)
137
+ name = canonicalize(name)
138
+
139
+ fact = @facts[name]
140
+
141
+ if fact.nil?
142
+ fact = Facter::Util::Fact.new(name, options)
143
+ @facts[name] = fact
144
+ else
145
+ fact.extract_ldapname_option!(options)
146
+ end
147
+
148
+ fact
149
+ end
150
+
147
151
  def canonicalize(name)
148
152
  name.to_s.downcase.to_sym
149
153
  end
@@ -29,23 +29,33 @@ module Facter::Util::Config
29
29
  end
30
30
  end
31
31
 
32
+ def self.external_facts_dirs=(dir)
33
+ @external_facts_dirs = dir
34
+ end
35
+
32
36
  def self.external_facts_dirs
37
+ @external_facts_dirs
38
+ end
39
+
40
+ def self.setup_default_ext_facts_dirs
33
41
  if Facter::Util::Root.root?
34
42
  windows_dir = windows_data_dir
35
43
  if windows_dir.nil? then
36
- ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
44
+ @external_facts_dirs = ["/etc/facter/facts.d", "/etc/puppetlabs/facter/facts.d"]
37
45
  else
38
- [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
46
+ @external_facts_dirs = [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
39
47
  end
40
48
  else
41
- [File.expand_path(File.join("~", ".facter", "facts.d"))]
49
+ @external_facts_dirs = [File.expand_path(File.join("~", ".facter", "facts.d"))]
42
50
  end
43
51
  end
44
- end
45
52
 
46
- if Facter::Util::Config.is_windows?
47
- require 'win32/dir'
48
- require 'facter/util/windows_root'
49
- else
50
- require 'facter/util/unix_root'
53
+ if Facter::Util::Config.is_windows?
54
+ require 'win32/dir'
55
+ require 'facter/util/windows_root'
56
+ else
57
+ require 'facter/util/unix_root'
58
+ end
59
+
60
+ setup_default_ext_facts_dirs
51
61
  end