diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-03-30 19:37:43 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-03-31 11:40:59 -0700 |
commit | 5904607f0dde61751dab4d8c8d03811e369b3f17 (patch) | |
tree | c18840b257d8ef985ed30dc3a40e80cabadb8006 | |
parent | 3301715e5b7924bcdba7cf30c2f382f10b801066 (diff) | |
download | ohai-5904607f0dde61751dab4d8c8d03811e369b3f17.tar.gz |
Detect Windows EC2 nodes
-rw-r--r-- | lib/ohai/plugins/ec2.rb | 22 | ||||
-rw-r--r-- | spec/unit/plugins/ec2_spec.rb | 8 |
2 files changed, 28 insertions, 2 deletions
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index a9c7eff7..513058c1 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -2,6 +2,7 @@ # Author:: Tim Dysinger (<tim@dysinger.net>) # Author:: Benjamin Black (<bb@chef.io>) # Author:: Christopher Brown (<cb@chef.io>) +# Author:: Tim Smith (<tsmith@chef.io>) # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # @@ -20,7 +21,8 @@ # How we detect EC2 from easiest to hardest & least reliable # 1. Ohai ec2 hint exists. This always works # 2. DMI data mentions amazon. This catches HVM instances in a VPC -# 3. Has a xen MAC + can connect to metadata. This catches paravirt instances not in a VPC +# 3. Kernel data mentioned Amazon. This catches Windows instances +# 4. Has a xen MAC + can connect to metadata. This catches paravirt instances not in a VPC require "ohai/mixin/ec2_metadata" require "base64" @@ -32,6 +34,7 @@ Ohai.plugin(:EC2) do depends "network/interfaces" depends "dmi" + depends "kernel" # look for xen arp address # this gets us detection of paravirt instances that are NOT within a VPC @@ -69,11 +72,26 @@ EOM end end + # looks for the Amazon.com Organization in Windows Kernel data + # this gets us detection of Windows systems + def has_amazon_org? + begin + # detect an Organization of 'Amazon.com' + if kernel[:os_info][:organization] =~ /Amazon/ + Ohai::Log.debug("ec2 plugin: has_amazon_org? == true") + true + end + rescue NoMethodError + Ohai::Log.debug("ec2 plugin: has_amazon_org? == false") + false + end + end + def looks_like_ec2? return true if hint?("ec2") # Even if it looks like EC2 try to connect first - if has_ec2_dmi? || has_xen_mac? + if has_ec2_dmi? || has_amazon_org? || has_xen_mac? return true if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) end end diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb index 1098b5fa..b5d4e87b 100644 --- a/spec/unit/plugins/ec2_spec.rb +++ b/spec/unit/plugins/ec2_spec.rb @@ -276,6 +276,14 @@ describe Ohai::System, "plugin ec2" do end end + describe "with amazon kernel data" do + it_should_behave_like "ec2" + + before(:each) do + @plugin[:kernel] = { :os_info => { :organization => "Amazon.com" } } + end + end + describe "with ec2 hint file" do it_should_behave_like "ec2" |