facter 2.1.0 → 2.2.0

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 (139) hide show
  1. data/COMMITTERS.md +25 -34
  2. data/CONTRIBUTING.md +27 -5
  3. data/README.md +32 -0
  4. data/ext/build_defaults.yaml +1 -1
  5. data/ext/debian/control +3 -2
  6. data/ext/osx/file_mapping.yaml +5 -0
  7. data/ext/redhat/facter.spec.erb +4 -1
  8. data/lib/facter/Cfkey.rb +2 -2
  9. data/lib/facter/architecture.rb +2 -2
  10. data/lib/facter/augeasversion.rb +2 -2
  11. data/lib/facter/blockdevices.rb +12 -12
  12. data/lib/facter/dhcp_servers.rb +4 -4
  13. data/lib/facter/domain.rb +4 -4
  14. data/lib/facter/ec2.rb +17 -0
  15. data/lib/facter/ec2/rest.rb +2 -2
  16. data/lib/facter/facterversion.rb +2 -2
  17. data/lib/facter/filesystems.rb +10 -3
  18. data/lib/facter/fqdn.rb +1 -1
  19. data/lib/facter/gid.rb +16 -0
  20. data/lib/facter/hardwareisa.rb +3 -3
  21. data/lib/facter/hardwaremodel.rb +3 -3
  22. data/lib/facter/hostname.rb +1 -1
  23. data/lib/facter/id.rb +4 -4
  24. data/lib/facter/interfaces.rb +3 -0
  25. data/lib/facter/ipaddress6.rb +9 -9
  26. data/lib/facter/kernel.rb +2 -2
  27. data/lib/facter/kernelmajversion.rb +2 -2
  28. data/lib/facter/kernelrelease.rb +4 -4
  29. data/lib/facter/kernelversion.rb +3 -3
  30. data/lib/facter/ldom.rb +11 -0
  31. data/lib/facter/lsbdistcodename.rb +8 -4
  32. data/lib/facter/lsbdistdescription.rb +6 -10
  33. data/lib/facter/lsbdistid.rb +8 -4
  34. data/lib/facter/lsbdistrelease.rb +8 -4
  35. data/lib/facter/lsbmajdistrelease.rb +7 -12
  36. data/lib/facter/lsbminordistrelease.rb +22 -0
  37. data/lib/facter/lsbrelease.rb +8 -4
  38. data/lib/facter/macaddress.rb +1 -0
  39. data/lib/facter/macosx.rb +1 -1
  40. data/lib/facter/manufacturer.rb +3 -3
  41. data/lib/facter/memory.rb +8 -8
  42. data/lib/facter/netmask.rb +2 -1
  43. data/lib/facter/network.rb +3 -3
  44. data/lib/facter/operatingsystem.rb +9 -126
  45. data/lib/facter/operatingsystem/base.rb +61 -0
  46. data/lib/facter/operatingsystem/cumuluslinux.rb +27 -0
  47. data/lib/facter/operatingsystem/implementation.rb +30 -0
  48. data/lib/facter/operatingsystem/linux.rb +467 -0
  49. data/lib/facter/operatingsystem/sunos.rb +54 -0
  50. data/lib/facter/operatingsystem/vmkernel.rb +11 -0
  51. data/lib/facter/operatingsystem/windows.rb +37 -0
  52. data/lib/facter/operatingsystemmajrelease.rb +14 -33
  53. data/lib/facter/operatingsystemrelease.rb +14 -235
  54. data/lib/facter/os.rb +69 -0
  55. data/lib/facter/osfamily.rb +4 -23
  56. data/lib/facter/partitions.rb +4 -3
  57. data/lib/facter/path.rb +2 -2
  58. data/lib/facter/physicalprocessorcount.rb +10 -74
  59. data/lib/facter/processor.rb +13 -129
  60. data/lib/facter/processors.rb +60 -0
  61. data/lib/facter/processors/os.rb +234 -0
  62. data/lib/facter/ps.rb +5 -4
  63. data/lib/facter/puppetversion.rb +1 -1
  64. data/lib/facter/rackspace.rb +34 -0
  65. data/lib/facter/rubysitedir.rb +3 -0
  66. data/lib/facter/rubyversion.rb +2 -2
  67. data/lib/facter/selinux.rb +57 -2
  68. data/lib/facter/ssh.rb +1 -0
  69. data/lib/facter/system_uptime.rb +42 -0
  70. data/lib/facter/timezone.rb +1 -1
  71. data/lib/facter/uptime.rb +5 -23
  72. data/lib/facter/uptime_days.rb +4 -6
  73. data/lib/facter/uptime_hours.rb +4 -6
  74. data/lib/facter/uptime_seconds.rb +5 -9
  75. data/lib/facter/util/formatter.rb +1 -1
  76. data/lib/facter/util/manufacturer.rb +1 -1
  77. data/lib/facter/util/partitions.rb +3 -1
  78. data/lib/facter/util/partitions/linux.rb +1 -1
  79. data/lib/facter/util/partitions/openbsd.rb +35 -0
  80. data/lib/facter/util/uptime.rb +4 -3
  81. data/lib/facter/util/virtual.rb +3 -1
  82. data/lib/facter/util/xendomains.rb +12 -3
  83. data/lib/facter/version.rb +1 -1
  84. data/lib/facter/virtual.rb +24 -23
  85. data/lib/facter/vlans.rb +1 -1
  86. data/lib/facter/xendomains.rb +1 -1
  87. data/lib/facter/zfs_version.rb +6 -2
  88. data/lib/facter/zones.rb +6 -5
  89. data/lib/facter/zpool_version.rb +1 -1
  90. data/spec/fixtures/cpuinfo/amd64dual-grep +2 -0
  91. data/spec/fixtures/cpuinfo/amd64twentyfour-grep +24 -0
  92. data/spec/fixtures/cpuinfo/two_multicore-grep +4 -0
  93. data/spec/fixtures/cpuinfo/two_singlecore-grep +2 -0
  94. data/spec/fixtures/unit/processors/os/darwin-system-profiler +287 -0
  95. data/spec/fixtures/unit/zfs_version/zfs_new +61 -0
  96. data/spec/fixtures/unit/zfs_version/zfs_old +43 -0
  97. data/spec/fixtures/unit/zfs_version/zfsonlinux_0.6.1 +13 -0
  98. data/spec/fixtures/unit/zpool_version/zfsonlinux_0.6.1 +48 -0
  99. data/spec/unit/ec2/rest_spec.rb +6 -6
  100. data/spec/unit/gid_spec.rb +22 -0
  101. data/spec/unit/hardwaremodel_spec.rb +2 -0
  102. data/spec/unit/lsbdistcodename_spec.rb +22 -17
  103. data/spec/unit/lsbdistdescription_spec.rb +22 -17
  104. data/spec/unit/lsbdistid_spec.rb +23 -18
  105. data/spec/unit/lsbdistrelease_spec.rb +22 -17
  106. data/spec/unit/lsbmajdistrelease_spec.rb +23 -6
  107. data/spec/unit/lsbminordistrelease_spec.rb +31 -0
  108. data/spec/unit/lsbrelease_spec.rb +22 -17
  109. data/spec/unit/macaddress_spec.rb +3 -0
  110. data/spec/unit/operatingsystem/base_spec.rb +76 -0
  111. data/spec/unit/operatingsystem/cumuluslinux_spec.rb +40 -0
  112. data/spec/unit/operatingsystem/implementation_spec.rb +49 -0
  113. data/spec/unit/operatingsystem/linux_spec.rb +538 -0
  114. data/spec/unit/operatingsystem/sunos_spec.rb +144 -0
  115. data/spec/unit/operatingsystem/vmkernel_spec.rb +13 -0
  116. data/spec/unit/operatingsystem/windows_spec.rb +68 -0
  117. data/spec/unit/operatingsystem_spec.rb +10 -153
  118. data/spec/unit/operatingsystemmajrelease_spec.rb +14 -31
  119. data/spec/unit/operatingsystemrelease_spec.rb +13 -229
  120. data/spec/unit/os_spec.rb +131 -0
  121. data/spec/unit/osfamily_spec.rb +9 -54
  122. data/spec/unit/partitions_spec.rb +41 -3
  123. data/spec/unit/physicalprocessorcount_spec.rb +6 -78
  124. data/spec/unit/processor_spec.rb +18 -381
  125. data/spec/unit/processors/os_spec.rb +446 -0
  126. data/spec/unit/processors_spec.rb +203 -0
  127. data/spec/unit/rackspace_spec.rb +40 -0
  128. data/spec/unit/system_uptime_spec.rb +80 -0
  129. data/spec/unit/util/formatter_spec.rb +5 -0
  130. data/spec/unit/util/macaddress_spec.rb +2 -0
  131. data/spec/unit/util/processor_spec.rb +120 -0
  132. data/spec/unit/util/uptime_spec.rb +3 -4
  133. data/spec/unit/util/virtual_spec.rb +8 -0
  134. data/spec/unit/util/xendomains_spec.rb +54 -9
  135. data/spec/unit/virtual_spec.rb +8 -1
  136. data/spec/unit/zfs_version_spec.rb +20 -8
  137. data/spec/unit/zpool_version_spec.rb +5 -0
  138. metadata +652 -589
  139. checksums.yaml +0 -7
@@ -3,35 +3,16 @@
3
3
  # Purpose: Returns the operating system
4
4
  #
5
5
  # Resolution:
6
- # Maps operating systems to operating system families, such as linux
6
+ # Uses the family key of the os structured fact, which itself
7
+ # maps operating systems to operating system families, such as Linux
7
8
  # distribution derivatives. Adds mappings from specific operating systems
8
9
  # to kernels in the case that it is relevant.
9
10
  #
10
11
  # Caveats:
11
12
  # This fact is completely reliant on the operatingsystem fact, and no
12
- # heuristics are used
13
+ # heuristics are used.
13
14
  #
14
15
 
15
16
  Facter.add(:osfamily) do
16
-
17
- setcode do
18
- case Facter.value(:operatingsystem)
19
- when "RedHat", "Fedora", "CentOS", "Scientific", "SLC", "Ascendos", "CloudLinux", "PSBM", "OracleLinux", "OVS", "OEL", "Amazon", "XenServer"
20
- "RedHat"
21
- when "LinuxMint", "Ubuntu", "Debian", "CumulusLinux"
22
- "Debian"
23
- when "SLES", "SLED", "OpenSuSE", "SuSE"
24
- "Suse"
25
- when "Solaris", "Nexenta", "OmniOS", "OpenIndiana", "SmartOS"
26
- "Solaris"
27
- when "Gentoo"
28
- "Gentoo"
29
- when "Archlinux"
30
- "Archlinux"
31
- when "Mageia", "Mandriva", "Mandrake"
32
- "Mandrake"
33
- else
34
- Facter.value("kernel")
35
- end
36
- end
17
+ setcode { Facter.value("os")["family"] }
37
18
  end
@@ -1,14 +1,15 @@
1
1
  # Fact: partitions
2
2
  #
3
3
  # Purpose:
4
- # Return the details of the disk partitions
4
+ # Return the details of the disk partitions.
5
5
  #
6
6
  # Resolution:
7
- # Parse the contents of /sys/block/<device>/size to receive the size (multiplying by 512 to correct for blocks-to-bytes)
7
+ # Parse the contents of `/sys/block/<device>/size` to receive the size (multiplying by 512 to correct for blocks-to-bytes).
8
8
  #
9
9
  # Caveats:
10
- # Only supports Linux 2.6+ at this time, due to the reliance on sysfs
10
+ # For Linux, only 2.6+ is supported at this time due to the reliance on sysfs.
11
11
  #
12
+
12
13
  # Author: Chris Portman <chris@portman.net.au>
13
14
 
14
15
  require 'facter'
@@ -1,8 +1,8 @@
1
1
  # Fact: path
2
2
  #
3
- # Purpose: Returns the $PATH variable.
3
+ # Purpose: Returns the `$PATH` variable.
4
4
  #
5
- # Resolution: Gets $PATH from the environment.
5
+ # Resolution: Gets `$PATH` from the environment.
6
6
  #
7
7
  # Caveats:
8
8
  #
@@ -3,89 +3,25 @@
3
3
  # Purpose: Return the number of physical processors.
4
4
  #
5
5
  # Resolution:
6
- #
7
- # Attempts to use sysfs to get the physical IDs of the processors. Falls
8
- # back to /proc/cpuinfo and "physical id" if sysfs is not available.
6
+ # Uses the physicalprocessorcount key of the processors structured
7
+ # fact, which itself attempts to use sysfs to get the physical IDs of
8
+ # the processors and falls back to `/proc/cpuinfo` and `physical id` if
9
+ # sysfs is not available.
9
10
  #
10
11
  # Caveats:
11
12
  #
12
- require 'facter/util/posix'
13
-
14
- Facter.add('physicalprocessorcount') do
15
- confine :kernel => :linux
16
-
17
- setcode do
18
- sysfs_cpu_directory = '/sys/devices/system/cpu' # This should always be there ...
19
-
20
- if File.exists?(sysfs_cpu_directory)
21
- #
22
- # We assume that the sysfs file system has the correct number of entries
23
- # under the "/sys/device/system/cpu" directory and if so then we process
24
- # content of the file "physical_package_id" located inside the "topology"
25
- # directory in each of the per-CPU sub-directories.
26
- #
27
- # As per Linux Kernel documentation and the file "cputopology.txt" located
28
- # inside the "/usr/src/linux/Documentation" directory we can find following
29
- # short explanation:
30
- #
31
- # (...)
32
- #
33
- # 1) /sys/devices/system/cpu/cpuX/topology/physical_package_id:
34
- #
35
- # physical package id of cpuX. Typically corresponds to a physical
36
- # socket number, but the actual value is architecture and platform
37
- # dependent.
38
- #
39
- # (...)
40
- #
41
- lookup_pattern = "#{sysfs_cpu_directory}" +
42
- "/cpu*/topology/physical_package_id"
43
-
44
- Dir.glob(lookup_pattern).collect { |f| Facter::Core::Execution.exec("cat #{f}")}.uniq.size.to_s
45
-
46
- else
47
- #
48
- # Try to count number of CPUs using the proc file system next ...
49
- #
50
- # We assume that /proc/cpuinfo has what we need and is so then we need
51
- # to make sure that we only count unique entries ...
52
- #
53
- str = Facter::Core::Execution.exec("grep 'physical.\\+:' /proc/cpuinfo")
54
-
55
- if str then str.scan(/\d+/).uniq.size.to_s; end
56
- end
57
- end
58
- end
59
13
 
60
14
  Facter.add('physicalprocessorcount') do
61
- confine :kernel => :windows
62
- setcode do
63
- require 'facter/util/wmi'
64
- Facter::Util::WMI.execquery("select Name from Win32_Processor").Count.to_s
15
+ confine do
16
+ !Facter.value(:processors).nil?
65
17
  end
66
- end
67
-
68
- Facter.add('physicalprocessorcount') do
69
- confine :kernel => :sunos
70
18
 
71
- # (#16526) The -p flag was not added until Solaris 8. Our intent is to
72
- # split the kernel release fact value on the dot, take the second element,
73
- # and disable the -p flag for values < 8 when.
74
19
  setcode do
75
- kernelrelease = Facter.value(:kernelrelease)
76
- (major_version, minor_version) = kernelrelease.split(".").map { |str| str.to_i }
77
- if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
78
- Facter::Core::Execution.exec("/usr/sbin/psrinfo -p")
20
+ processors = Facter.value(:processors)
21
+ if (physicalprocessorcount = processors["physicalcount"])
22
+ physicalprocessorcount.to_s
79
23
  else
80
- output = Facter::Core::Execution.exec("/usr/sbin/psrinfo")
81
- output.split("\n").length.to_s
24
+ nil
82
25
  end
83
26
  end
84
27
  end
85
-
86
- Facter.add('physicalprocessorcount') do
87
- confine :kernel => :openbsd
88
- setcode do
89
- Facter::Util::POSIX.sysctl("hw.ncpufound")
90
- end
91
- end
@@ -4,11 +4,9 @@
4
4
  # Additional Facts about the machine's CPUs.
5
5
  #
6
6
  # Resolution:
7
- # On Linux and kFreeBSD, parse '/proc/cpuinfo' for each processor.
8
- # On AIX, parse the output of 'lsdev' for its processor section.
9
- # On Solaris, parse the output of 'kstat' for each processor.
10
- # On OpenBSD, use the sysctl variables 'hw.model' and 'hw.ncpu'
11
- # for the CPU model and the CPU count respectively.
7
+ # Utilizes values from the processors structured fact, which itself
8
+ # uses various methods to collect CPU information, with implementation
9
+ # dependent upon the OS of the system in question.
12
10
  #
13
11
  # Caveats:
14
12
  #
@@ -19,115 +17,29 @@
19
17
  # Author: Matthew Palmer <matt@solutionsfirst.com.au>
20
18
  #
21
19
 
22
- require 'thread'
23
- require 'facter/util/processor'
24
- require 'facter/util/posix'
25
20
 
26
21
  # We have to enumerate these outside a Facter.add block to get the processorN
27
22
  # descriptions iteratively (but we need them inside the Facter.add block above
28
23
  # for tests on processorcount to work)
29
- processor_list = case Facter::Util::Processor.kernel_fact_value
30
- when "AIX"
31
- Facter::Util::Processor.aix_processor_list
32
- when "HP-UX"
33
- Facter::Util::Processor.hpux_processor_list
34
- when "SunOS"
35
- Facter::Util::Processor.enum_kstat
36
- else
37
- Facter::Util::Processor.enum_cpuinfo
38
- end
39
-
40
- processor_list.each_with_index do |desc, i|
41
- Facter.add("Processor#{i}") do
42
- confine :kernel => [ :aix, :"hp-ux", :sunos, :linux, :"gnu/kfreebsd" ]
43
- setcode do
44
- desc
45
- end
46
- end
47
- end
48
-
49
- Facter.add("ProcessorCount") do
50
- confine :kernel => [ :linux, :"gnu/kfreebsd" ]
51
- setcode do
52
- processor_list = Facter::Util::Processor.enum_cpuinfo
53
-
54
- ## If this returned nothing, then don't resolve the fact
55
- if processor_list.length != 0
56
- processor_list.length.to_s
57
- end
58
- end
59
- end
60
-
61
- Facter.add("ProcessorCount") do
62
- confine :kernel => [ :linux, :"gnu/kfreebsd" ]
63
- setcode do
64
- ## The method above is preferable since it provides the description of the CPU as well
65
- ## but if that returned 0, then we enumerate sysfs
66
- sysfs_cpu_directory = '/sys/devices/system/cpu'
67
- if File.exists?(sysfs_cpu_directory)
68
- lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu[0-9]*"
69
- cpuCount = Dir.glob(lookup_pattern).length
70
- cpuCount.to_s
24
+ processors = Facter.value(:processors)
25
+ if processors && (processor_list = processors["models"])
26
+ processor_list.each_with_index do |processor, i|
27
+ Facter.add("processor#{i}") do
28
+ setcode { processor }
71
29
  end
72
30
  end
73
31
  end
74
32
 
75
33
  Facter.add("ProcessorCount") do
76
- confine :kernel => :aix
77
- setcode do
78
- processor_list = Facter::Util::Processor.aix_processor_list
79
-
80
- processor_list.length.to_s
34
+ confine do
35
+ !Facter.value(:processors).nil?
81
36
  end
82
- end
83
37
 
84
- Facter.add("ProcessorCount") do
85
- confine :kernel => :"hp-ux"
86
38
  setcode do
87
- processor_list = Facter::Util::Processor.hpux_processor_list
88
- processor_list.length.to_s
89
- end
90
- end
91
-
92
- Facter.add("ProcessorCount") do
93
- confine :kernel => :Darwin
94
- setcode do
95
- Facter::Util::POSIX.sysctl("hw.ncpu")
96
- end
97
- end
98
-
99
- if Facter.value(:kernel) == "windows"
100
- processor_list = []
101
-
102
- require 'facter/util/wmi'
103
-
104
- # get each physical processor
105
- Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
106
- # not supported before 2008
107
- if proc.respond_to?(:NumberOfLogicalProcessors)
108
- processor_num = proc.NumberOfLogicalProcessors
39
+ if (processorcount = processors["count"])
40
+ processorcount.to_s
109
41
  else
110
- processor_num = 1
111
- end
112
-
113
- processor_num.times do |i|
114
- processor_list << proc.Name.squeeze(" ")
115
- end
116
- end
117
-
118
- processor_list.each_with_index do |name, i|
119
- Facter.add("Processor#{i}") do
120
- confine :kernel => :windows
121
- setcode do
122
- name
123
- end
124
- end
125
- end
126
-
127
- Facter.add("ProcessorCount") do
128
- confine :kernel => :windows
129
- setcode do
130
- processor_list.length.to_s
42
+ nil
131
43
  end
132
44
  end
133
45
  end
@@ -138,31 +50,3 @@ Facter.add("Processor") do
138
50
  Facter::Util::POSIX.sysctl("hw.model")
139
51
  end
140
52
  end
141
-
142
- Facter.add("ProcessorCount") do
143
- confine :kernel => [:dragonfly,:freebsd,:openbsd]
144
- setcode do
145
- Facter::Util::POSIX.sysctl("hw.ncpu")
146
- end
147
- end
148
-
149
- Facter.add("ProcessorCount") do
150
- confine :kernel => :sunos
151
- setcode do
152
- kernelrelease = Facter.value(:kernelrelease)
153
- (major_version, minor_version) = kernelrelease.split(".").map { |str| str.to_i }
154
- result = nil
155
-
156
- if (major_version < 5) or (major_version == 5 and minor_version < 8) then
157
- if kstat = Facter::Core::Execution.exec("/usr/bin/kstat cpu_info")
158
- result = kstat.scan(/\bcore_id\b\s+\d+/).uniq.length
159
- end
160
- else
161
- if output = Facter::Core::Execution.exec("/usr/sbin/psrinfo") then
162
- result = output.split("\n").length
163
- end
164
- end
165
-
166
- result.to_s
167
- end
168
- end
@@ -0,0 +1,60 @@
1
+ # Fact: processors
2
+ #
3
+ # Purpose:
4
+ # Additional facts about the machine's CPU's, including
5
+ # processor lists, models, counts, and speeds.
6
+ #
7
+ # Resolution:
8
+ # Each kernel utilizes its own implementation object to collect
9
+ # processor data. Linux and kFreeBSD parse `/proc/cpuinfo` for each
10
+ # processor. AIX parses the output of `lsdev` for its processor section.
11
+ # For Solaris, we parse the output of `kstat` for each processor. OpenBSD uses
12
+ # the sysctl variables 'hw.model' and 'hw.ncpu' for the CPU model and
13
+ # the CPU count respectively. Darwin utilizes the system profiler to collect
14
+ # the physical CPU count and speed.
15
+ #
16
+
17
+ require 'facter/processors/os'
18
+
19
+ Facter.add(:processors, :type => :aggregate) do
20
+ confine do
21
+ !os.nil?
22
+ end
23
+
24
+ def os
25
+ @os ||= Facter::Processors.implementation
26
+ end
27
+
28
+ chunk(:models) do
29
+ processor_hash = {}
30
+ processor_list = os.get_processor_list
31
+ if processor_list.length > 0
32
+ processor_hash["models"] = processor_list
33
+ processor_hash
34
+ end
35
+ end
36
+
37
+ chunk(:count) do
38
+ processor_hash = {}
39
+ if (processor_count = os.get_processor_count)
40
+ processor_hash["count"] = processor_count
41
+ processor_hash
42
+ end
43
+ end
44
+
45
+ chunk(:physicalcount) do
46
+ processor_hash = {}
47
+ if (physical_processor_count = os.get_physical_processor_count)
48
+ processor_hash["physicalcount"] = physical_processor_count
49
+ processor_hash
50
+ end
51
+ end
52
+
53
+ chunk(:speed) do
54
+ processor_hash = {}
55
+ if (processor_speed = os.get_processor_speed)
56
+ processor_hash["speed"] = processor_speed
57
+ processor_hash
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,234 @@
1
+ # Processor OS classes
2
+ #
3
+ # Implements processor data collection with the help
4
+ # of the Util::Processor module.
5
+
6
+ require 'facter/util/processor'
7
+ require 'facter/util/posix'
8
+
9
+ module Facter
10
+ module Processors
11
+
12
+ def self.implementation(kernel = Facter.value(:kernel))
13
+ case kernel
14
+ when "Linux"
15
+ Facter::Processors::Linux.new
16
+ when "GNU/kFreeBSD"
17
+ Facter::Processors::GNU.new
18
+ when "Darwin"
19
+ Facter::Processors::Darwin.new
20
+ when "AIX"
21
+ Facter::Processors::AIX.new
22
+ when "HP-UX"
23
+ Facter::Processors::HP_UX.new
24
+ when "DragonFly", "FreeBSD"
25
+ Facter::Processors::BSD.new
26
+ when "OpenBSD"
27
+ Facter::Processors::OpenBSD.new
28
+ when "SunOS"
29
+ Facter::Processors::SunOS.new
30
+ when "windows"
31
+ Facter::Processors::Windows.new
32
+ end
33
+ end
34
+
35
+ class Base
36
+ def get_processor_list
37
+ Facter::Util::Processor.enum_cpuinfo
38
+ end
39
+
40
+ def get_processor_count
41
+ get_processor_list.length
42
+ end
43
+
44
+ def get_physical_processor_count
45
+ nil
46
+ end
47
+
48
+ def get_processor_speed
49
+ nil
50
+ end
51
+ end
52
+
53
+ class GNU < Base
54
+ def get_processor_count
55
+ processor_list = get_processor_list
56
+ if processor_list.length != 0
57
+ processor_list.length
58
+ else
59
+ count_cpu_from_sysfs
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def count_cpu_from_sysfs
66
+ sysfs_cpu_directory = "/sys/devices/system/cpu"
67
+ if File.exists?(sysfs_cpu_directory)
68
+ lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu[0-9]*"
69
+ Dir.glob(lookup_pattern).length
70
+ end
71
+ end
72
+ end
73
+
74
+ class Linux < GNU
75
+ def get_physical_processor_count
76
+ if count = count_physical_cpu_from_sysfs
77
+ count
78
+ else
79
+ count_physical_cpu_from_cpuinfo
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ def count_physical_cpu_from_sysfs
86
+ sysfs_cpu_directory = "/sys/devices/system/cpu"
87
+ if File.exists?(sysfs_cpu_directory)
88
+ lookup_pattern = "#{sysfs_cpu_directory}" + "/cpu*/topology/physical_package_id"
89
+ Dir.glob(lookup_pattern).collect { |f| Facter::Core::Execution.exec("cat #{f}")}.uniq.size
90
+ else
91
+ nil
92
+ end
93
+ end
94
+
95
+ def count_physical_cpu_from_cpuinfo
96
+ str = Facter::Core::Execution.exec("grep 'physical.\+:' /proc/cpuinfo")
97
+ if str
98
+ str.scan(/\d+/).uniq.size
99
+ else
100
+ nil
101
+ end
102
+ end
103
+ end
104
+
105
+ class Windows < Base
106
+ def initialize
107
+ require 'facter/util/wmi'
108
+ end
109
+
110
+ def get_processor_list
111
+ processor_list = []
112
+ # get each physical processor
113
+ Facter::Util::WMI.execquery("select * from Win32_Processor").each do |proc|
114
+ # not supported before 2008
115
+ if proc.respond_to?(:NumberOfLogicalProcessors)
116
+ processor_num = proc.NumberOfLogicalProcessors
117
+ else
118
+ processor_num = 1
119
+ end
120
+
121
+ processor_num.times do |i|
122
+ processor_list << proc.Name.squeeze(" ")
123
+ end
124
+ end
125
+ processor_list
126
+ end
127
+
128
+ def get_physical_processor_count
129
+ Facter::Util::WMI.execquery("select Name from Win32_Processor").Count
130
+ end
131
+ end
132
+
133
+ class AIX < Base
134
+ def get_processor_list
135
+ Facter::Util::Processor.aix_processor_list
136
+ end
137
+ end
138
+
139
+ class HP_UX < Base
140
+ def get_processor_list
141
+ Facter::Util::Processor.hpux_processor_list
142
+ end
143
+ end
144
+
145
+ class Darwin < Base
146
+ def initialize
147
+ require "cfpropertylist"
148
+ @system_hardware_data = query_system_profiler
149
+ end
150
+
151
+ def get_processor_count
152
+ Facter::Util::POSIX.sysctl("hw.ncpu").to_i
153
+ end
154
+
155
+ def get_processor_speed
156
+ @system_hardware_data["current_processor_speed"]
157
+ end
158
+
159
+ private
160
+
161
+ def query_system_profiler
162
+ output = Facter::Core::Execution.exec("/usr/sbin/system_profiler -xml SPHardwareDataType")
163
+ plist = CFPropertyList::List.new
164
+ plist.load_str(output)
165
+ parsed_xml = CFPropertyList.native_types(plist.value)
166
+ parsed_xml[0]['_items'][0]
167
+ end
168
+ end
169
+
170
+ class BSD < Base
171
+ def get_processor_count
172
+ Facter::Util::POSIX.sysctl("hw.ncpu").to_i
173
+ end
174
+ end
175
+
176
+ class OpenBSD < BSD
177
+ def get_physical_processor_count
178
+ Facter::Util::POSIX.sysctl("hw.ncpufound").to_i
179
+ end
180
+ end
181
+
182
+ class SunOS < Base
183
+ def initialize
184
+ kernelrelease = Facter.value(:kernelrelease)
185
+ @major_version = kernelrelease.split(".")[0].to_i
186
+ @minor_version = kernelrelease.split(".")[1].to_i
187
+ end
188
+
189
+ def get_processor_list
190
+ Facter::Util::Processor.enum_kstat
191
+ end
192
+
193
+ def get_processor_count
194
+ if @major_version < 5 or (@major_version == 5 and @minor_version < 8)
195
+ if count = count_cpu_with_kstat
196
+ count
197
+ else
198
+ count_cpu_with_psrinfo
199
+ end
200
+ else
201
+ count_cpu_with_psrinfo
202
+ end
203
+ end
204
+
205
+ def get_physical_processor_count
206
+ if @major_version > 5 or (@major_version == 5 and @minor_version >= 8)
207
+ if output = Facter::Core::Execution.exec("/usr/sbin/psrinfo -p")
208
+ output.to_i
209
+ end
210
+ else
211
+ count_cpu_with_psrinfo
212
+ end
213
+ end
214
+
215
+ private
216
+
217
+ def count_cpu_with_kstat
218
+ if output = Facter::Core::Execution.exec("/usr/bin/kstat cpu_info")
219
+ output.scan(/\bcore_id\b\s+\d+/).uniq.length
220
+ else
221
+ nil
222
+ end
223
+ end
224
+
225
+ def count_cpu_with_psrinfo
226
+ if output = Facter::Core::Execution.exec("/usr/sbin/psrinfo")
227
+ output.split("\n").length
228
+ else
229
+ nil
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end