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
@@ -3,110 +3,110 @@ require 'facter'
3
3
  # Load facts on demand.
4
4
  class Facter::Util::Loader
5
5
 
6
- def initialize
7
- @loaded = []
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
- # 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)
29
+ # Load all facts from all directories.
30
+ def load_all
31
+ return if defined?(@loaded_all)
15
32
 
16
- filename = shortname + ".rb"
17
- search_path.each do |dir|
18
- # Load individual files
19
- file = File.join(dir, filename)
33
+ load_env
20
34
 
21
- load_file(file) if FileTest.exist?(file)
35
+ search_path.each do |dir|
36
+ next unless FileTest.directory?(dir)
22
37
 
23
- # And load any directories matching the name
24
- factdir = File.join(dir, shortname)
25
- load_dir(factdir) if FileTest.directory?(factdir)
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
- # Load all facts from all directories.
30
- def load_all
31
- return if defined?(@loaded_all)
48
+ @loaded_all = true
49
+ end
32
50
 
33
- load_env
34
-
35
- search_path.each do |dir|
36
- next unless FileTest.directory?(dir)
37
-
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))
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
- # 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(":")
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
- result
63
- end
62
+ result
63
+ end
64
64
 
65
- private
65
+ private
66
66
 
67
- def load_dir(dir)
68
- return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/
67
+ def load_dir(dir)
68
+ return if dir =~ /\/\.+$/ or dir =~ /\/util$/ or dir =~ /\/lib$/
69
69
 
70
- Dir.entries(dir).find_all { |f| f =~ /\.rb$/ }.sort.each do |file|
71
- load_file(File.join(dir, file))
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
- 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}"
87
- end
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
- # 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
110
- end
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
@@ -6,56 +6,56 @@
6
6
  ##
7
7
 
8
8
  module Facter::Util::Macosx
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}")
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
- def self.intern_xml(xml)
21
- return nil unless xml
22
- Plist::parse_xml(xml)
23
- end
37
+ def self.hardware_overview
38
+ profiler_data("SPHardwareDataType")
39
+ end
24
40
 
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
34
- end
35
- end
41
+ def self.os_overview
42
+ profiler_data("SPSoftwareDataType")
43
+ end
36
44
 
37
- def self.hardware_overview
38
- profiler_data("SPHardwareDataType")
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
- def self.os_overview
42
- profiler_data("SPSoftwareDataType")
43
- end
44
-
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
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
- def self.get_dmi_table()
7
- case Facter.value(:kernel)
8
- when 'Linux', 'GNU/kFreeBSD'
9
- return nil unless FileTest.exists?("/usr/sbin/dmidecode")
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
- output=%x{/usr/sbin/dmidecode 2>/dev/null}
12
- when 'FreeBSD'
13
- return nil unless FileTest.exists?("/usr/local/sbin/dmidecode")
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
- output=%x{/usr/local/sbin/dmidecode 2>/dev/null}
16
- when 'NetBSD'
17
- return nil unless FileTest.exists?("/usr/pkg/sbin/dmidecode")
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
- output=%x{/usr/pkg/sbin/dmidecode 2>/dev/null}
20
- when 'SunOS'
21
- return nil unless FileTest.exists?("/usr/sbin/smbios")
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
- output=%x{/usr/sbin/smbios 2>/dev/null}
24
- else
25
- output=nil
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
- 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
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
- 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")
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
- 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')
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
- # 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
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
- Facter.add('serialnumber') do
84
- setcode do
85
- Facter::Util::Resolution.exec("/usr/sbin/sneep")
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
- 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
101
- end
102
- end
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