diff options
author | Tim Smith <tsmith84@gmail.com> | 2016-02-01 13:15:22 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2016-02-01 13:15:22 -0800 |
commit | 3b6d44dcc66cffc7ec04724976c5eac2f99f9958 (patch) | |
tree | e74df11a5d2ff74054acef63f3a43762a9c6cc58 | |
parent | e6fc8fca73273b269a2cfe27eb247fb5440d98ec (diff) | |
download | ohai-3b6d44dcc66cffc7ec04724976c5eac2f99f9958.tar.gz |
If dmi data is present use the presence of amazon strings to detect EC2
This gives us amazon detect on VPC AWS Linux hosts.
-rw-r--r-- | lib/ohai/plugins/ec2.rb | 18 | ||||
-rw-r--r-- | spec/unit/plugins/ec2_spec.rb | 16 |
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index cecc883f..42eb5136 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -26,7 +26,9 @@ Ohai.plugin(:EC2) do provides "ec2" depends "network/interfaces" + depends "dmi" + # look for arp address that non-VPC hosts will have def has_ec2_mac? network[:interfaces].values.each do |iface| unless iface[:arp].nil? @@ -40,10 +42,24 @@ Ohai.plugin(:EC2) do false end + # look for amazon string in dmi bios data + def has_ec2_dmi? + begin + if dmi[:bios][:all_records][0][:Version] =~ /amazon/ + Ohai::Log.debug("has_ec2_dmi? == true") + true + end + rescue NoMethodError + Ohai::Log.debug("has_ec2_dmi? == false") + false + end + end + + def looks_like_ec2? # Try non-blocking connect so we don't "block" if # the Xen environment is *not* EC2 - hint?('ec2') || has_ec2_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80) + hint?('ec2') || ( has_ec2_dmi? || has_ec2_mac?) && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80) end collect_data do diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb index 86b53d2c..0b02df1c 100644 --- a/spec/unit/plugins/ec2_spec.rb +++ b/spec/unit/plugins/ec2_spec.rb @@ -270,6 +270,22 @@ end end end + describe "with ec2 dmi data" do + it_should_behave_like "ec2" + + before(:each) do + @plugin[:dmi] = { :bios => { :all_records => [ { :Version => "4.2.amazon" } ] } } + end + end + + describe "without ec2 dmi data" do + it_should_behave_like "!ec2" + + before(:each) do + @plugin[:dmi] = nil + end + end + describe "with ec2 cloud file" do it_should_behave_like "ec2" |