-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve EC2 detection for HVM instances when a hint isn't present #711
Conversation
Right now if there's no user data we're getting a no method exception: [2016-02-01T20:27:33+00:00] DEBUG: Plugin EC2 threw #<NoMethodError: undefined method `encoding' for nil:NilClass> [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/plugins/ec2.rb:79:in `block (2 levels) in <main>' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/dsl/plugin/versionvii.rb:90:in `instance_eval' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/dsl/plugin/versionvii.rb:90:in `run_plugin' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/dsl/plugin.rb:98:in `run' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/dsl/plugin.rb:169:in `safe_run' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/runner.rb:84:in `run_v7_plugin' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/runner.rb:43:in `run_plugin' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/system.rb:98:in `block in run_plugins' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/system.rb:97:in `each' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/system.rb:97:in `run_plugins' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/system.rb:75:in `all_plugins' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/application.rb:90:in `run_application' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/lib/ohai/application.rb:78:in `run' [2016-02-01T20:27:33+00:00] DEBUG: /opt/chef/embedded/lib/ruby/gems/2.1.0/gems/ohai-8.9.0/bin/ohai:42:in `<top (required)>'
This gives us amazon detect on VPC AWS Linux hosts.
Do HVM and paravirtualized EC2 instances work identically in this regard? |
Let me spin up a paravirt box to make sure. |
As a tweak, can you add the line that you're finding in DMI as a comment? Otherwise 👍 assuming you test both HVM + paravirt inside and outside a VPC. |
So it looks like this won't work on the paravirts since they contain no BIOS so no DMI data. I'm open to improving detection there, but it seems to be less important as new generation instance types only work on HVM AMIs. Also for non-VPC hosts our existing MAC address detection will continue to function. |
@chef/client-core ready for review |
FINALLY. 👍 |
👍 |
I'll merge this whenever appveyer finishes. I'm working on another PR to detect the paravirts, but it involves parsing dmesg, which is pretty dirty. |
I'm kinda 👎 on parsing dmesg since its a ring buffer... that information will wind up getting lost and the detection will fail, and if the user doesn't have manual hints setup then suddenly ohai will stop reporting the correct ec2 information, which will lead to bug reports... we could do something to read dmesg to setup a hint file on the box during bootstrapping... |
If we're bootstrapping they'll get the ec2 hint anyways. Let me see if there's amazon fingerprints anywhere else. Dmesg has a nice string that identifies the Xen hypervisor has being an Amazon version. That might be in other places. |
detecting ec2 from dmesg and then creating the hint file sounds like a super clever solution for those who aren't using hints exists entirely because there's rarely obvious fingerprints about what cloud platform you're on. when there is, you buy those developers 🍻. |
See above: "I'm working on another PR to detect the paravirts, but it involves parsing dmesg, which is pretty dirty." |
/usr/bin/ec2metadata seems to actually be the best thing on both hvm and paravirts. So here's the thought for the next PR Hint -> DMI -> ec2metadata_bin -> MAC Hint when someone bootstraps via knife-ec2 |
Improve EC2 detection when hint isn't present
This allows us to detect Linux hosts based on the DMI data as it includes amazon specific strings. The present method of looking for an arp address fails when hosts are in a VPC, which they all are by default now.