diff options
author | Claire McQuin <claire@opscode.com> | 2013-07-31 17:10:15 -0700 |
---|---|---|
committer | Claire McQuin <claire@opscode.com> | 2013-08-07 10:16:39 -0700 |
commit | 2fdf7078f3497c84ee8469d294030a3b169ea5d0 (patch) | |
tree | b17bb9f89ee7c789e438e87d3a9a974b494a794d /lib/ohai/plugins/darwin/system_profiler.rb | |
parent | 07a1512d4b941c76bd62dcd27e1aa94969814e52 (diff) | |
download | ohai-2fdf7078f3497c84ee8469d294030a3b169ea5d0.tar.gz |
convert plugins to new dsl.
Diffstat (limited to 'lib/ohai/plugins/darwin/system_profiler.rb')
-rw-r--r-- | lib/ohai/plugins/darwin/system_profiler.rb | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/lib/ohai/plugins/darwin/system_profiler.rb b/lib/ohai/plugins/darwin/system_profiler.rb index 9eacd63d..0a3f40dd 100644 --- a/lib/ohai/plugins/darwin/system_profiler.rb +++ b/lib/ohai/plugins/darwin/system_profiler.rb @@ -15,56 +15,61 @@ # See the License for the specific language governing permissions and # limitations under the License. # -provides "system_profile" -begin - require 'plist' +Ohai.plugin(:DarwinSystemProfile) do + provides "system_profile" - system_profile Array.new - items Array.new - detail_level = { - 'mini' => [ - "SPParallelATAData", - "SPAudioData", - "SPBluetoothData", - "SPCardReaderData", - "SPDiagnosticsData", - "SPDiscBurningData", - "SPEthernetData", - "SPFibreChannelData", - "SPFireWireData", - "SPDisplaysData", - "SPHardwareRAIDData", - "SPMemoryData", - "SPModemData", - "SPNetworkData", - "SPPCIData", - "SPParallelSCSIData", - "SPPrintersSoftwareData", - "SPPrintersData", - "SPSASData", - "SPSerialATAData", - "SPSoftwareData", - "SPThunderboltData", - "SPUSBData", - "SPWWANData", - "SPAirPortData" - ], - 'full' => [ - "SPHardwareDataType" - ] - } + collect_data do + begin + require 'plist' - detail_level.each do |level, data_types| - popen4("system_profiler -xml -detailLevel #{level} #{data_types.join(' ')}") do |pid, stdin, stdout, stderr| - stdin.close - Plist::parse_xml(stdout.read).each do |e| - items << e + system_profile Array.new + items Array.new + detail_level = { + 'mini' => [ + "SPParallelATAData", + "SPAudioData", + "SPBluetoothData", + "SPCardReaderData", + "SPDiagnosticsData", + "SPDiscBurningData", + "SPEthernetData", + "SPFibreChannelData", + "SPFireWireData", + "SPDisplaysData", + "SPHardwareRAIDData", + "SPMemoryData", + "SPModemData", + "SPNetworkData", + "SPPCIData", + "SPParallelSCSIData", + "SPPrintersSoftwareData", + "SPPrintersData", + "SPSASData", + "SPSerialATAData", + "SPSoftwareData", + "SPThunderboltData", + "SPUSBData", + "SPWWANData", + "SPAirPortData" + ], + 'full' => [ + "SPHardwareDataType" + ] + } + + detail_level.each do |level, data_types| + popen4("system_profiler -xml -detailLevel #{level} #{data_types.join(' ')}") do |pid, stdin, stdout, stderr| + stdin.close + Plist::parse_xml(stdout.read).each do |e| + items << e + end + end end + + system_profile items.sort_by { |h| h['_dataType'] } + rescue LoadError => e + Ohai::Log.debug("Can't load gem: #{e})") end end - - system_profile items.sort_by { |h| h['_dataType'] } -rescue LoadError => e - Ohai::Log.debug("Can't load gem: #{e})") end |