diff options
author | Tim Smith <tsmith@chef.io> | 2017-09-06 16:14:36 -0700 |
---|---|---|
committer | Tim Smith <tsmith@chef.io> | 2017-09-06 16:14:36 -0700 |
commit | c8ca74e5d8767dbdcd3afb01336df166dac449e1 (patch) | |
tree | d442f0f3d83f6bbea64ea640bd12d7bae2f7a832 | |
parent | 9fd0f5827ce3f9034c346748987c48937f972936 (diff) | |
download | ohai-c8ca74e5d8767dbdcd3afb01336df166dac449e1.tar.gz |
Detect EC2 using UUIDs on Windows as well as Linux
This is actually how Amazon recommends doing it. It works no matter how the VM was built.
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r-- | lib/ohai/plugins/ec2.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index 9853d3b2..1a7d5553 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -52,10 +52,18 @@ Ohai.plugin(:EC2) do end # looks for a xen UUID that starts with ec2 - # this gets us detection of Linux HVM and Paravirt hosts + # uses the sys tree on Linux and a WMI query on windows + # this gets us detection of HVM and Paravirt hosts # @return [Boolean] do we have a Xen UUID or not? def has_ec2_xen_uuid? - if ::File.exist?("/sys/hypervisor/uuid") + if RUBY_PLATFORM =~ /mswin|mingw32|windows/ + require "wmi-lite/wmi" + wmi = WmiLite::Wmi.new + if wmi.query("select uuid from Win32_ComputerSystemProduct")[0]["identifyingnumber"] =~ /^ec2/ + Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true") + return true + end + elsif ::File.exist?("/sys/hypervisor/uuid") if ::File.read("/sys/hypervisor/uuid") =~ /^ec2/ Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true") return true |