summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2015-10-29 23:04:26 -0700
committerTim Smith <tsmith84@gmail.com>2015-10-29 23:47:12 -0700
commit0aa60c87a7b228c2165c7f05987fa6a858cdae56 (patch)
tree076fb6d24dfb66b4a23ec0247932bb56656081a2
parentffd9a0a0485718846381559946c8b38af7e46c70 (diff)
downloadohai-0aa60c87a7b228c2165c7f05987fa6a858cdae56.tar.gz
Detect vbox/vmware on Windows and speed up runs
Fetch WMI data within Ruby vs. shelling out to Powershell. This should be WAY faster.
-rw-r--r--lib/ohai/plugins/windows/virtualization.rb40
1 files changed, 24 insertions, 16 deletions
diff --git a/lib/ohai/plugins/windows/virtualization.rb b/lib/ohai/plugins/windows/virtualization.rb
index 6090fd3a..b10c747c 100644
--- a/lib/ohai/plugins/windows/virtualization.rb
+++ b/lib/ohai/plugins/windows/virtualization.rb
@@ -1,6 +1,8 @@
#
# Author:: Pavel Yudin (<pyudin@parallels.com>)
+# Author:: Tim Smith (<tsmith@chef.io>)
# Copyright:: Copyright (c) 2015 Pavel Yudin
+# Copyright:: Copyright (c) 2015 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,29 +18,35 @@
# limitations under the License.
#
-require 'ohai/util/file_helper'
-
-include Ohai::Util::FileHelper
+require 'wmi-lite/wmi'
Ohai.plugin(:Virtualization) do
- provides "virtualization"
-
- def powershell_exists?
- which('powershell.exe')
- end
+ provides 'virtualization'
collect_data(:windows) do
virtualization Mash.new unless virtualization
virtualization[:systems] = Mash.new unless virtualization[:systems]
- # Detect Parallels virtual machine from BIOS information
- if powershell_exists?
- so = shell_out('powershell.exe "Get-WmiObject -Class Win32_BIOS"')
- if so.stdout =~ /Parallels Software International Inc./
- virtualization[:system] = 'parallels'
- virtualization[:role] = 'guest'
- virtualization[:systems][:parallels] = 'guest'
- end
+ # Grab BIOS data from WMI to determine vendor information
+ wmi = WmiLite::Wmi.new
+ bios = wmi.instances_of('Win32_BIOS')
+
+ case bios[0]['manufacturer']
+ when 'innotek GmbH'
+ virtualization[:system] = 'vbox'
+ virtualization[:role] = 'guest'
+ virtualization[:systems][:vbox] = 'guest'
+ when 'Parallels Software International Inc.'
+ virtualization[:system] = 'parallels'
+ virtualization[:role] = 'guest'
+ virtualization[:systems][:parallels] = 'guest'
+ end
+
+ # vmware fusion detection
+ if bios[0]['serialnumber'] == /VMware/
+ virtualization[:system] = 'vmware'
+ virtualization[:role] = 'guest'
+ virtualization[:systems][:vmware] = 'guest'
end
end
end