Skip to content
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

Merged
merged 3 commits into from
Feb 2, 2016

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Feb 1, 2016

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.

tas50 added 2 commits February 1, 2016 12:56
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.
@tas50 tas50 changed the title Ec2 detection Improve EC2 detection when hint isn't present Feb 1, 2016
@tas50 tas50 mentioned this pull request Feb 1, 2016
@mfischer-zd
Copy link

Do HVM and paravirtualized EC2 instances work identically in this regard?

@tas50
Copy link
Contributor Author

tas50 commented Feb 1, 2016

Let me spin up a paravirt box to make sure.

@thommay
Copy link
Contributor

thommay commented Feb 2, 2016

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.

@tas50
Copy link
Contributor Author

tas50 commented Feb 2, 2016

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.

@tas50
Copy link
Contributor Author

tas50 commented Feb 2, 2016

@chef/client-core ready for review

@danielsdeleo
Copy link
Contributor

FINALLY. 👍

@lamont-granquist
Copy link
Contributor

👍

@tas50
Copy link
Contributor Author

tas50 commented Feb 2, 2016

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.

@lamont-granquist
Copy link
Contributor

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...

@tas50
Copy link
Contributor Author

tas50 commented Feb 2, 2016

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.

@btm
Copy link
Contributor

btm commented Feb 2, 2016

detecting ec2 from dmesg and then creating the hint file sounds like a super clever solution for those who aren't using knife ec2 server create. Of course, I wonder if there's a case where you'd want to opt out of that.

hints exists entirely because there's rarely obvious fingerprints about what cloud platform you're on. when there is, you buy those developers 🍻.

@lamont-granquist
Copy link
Contributor

See above: "I'm working on another PR to detect the paravirts, but it involves parsing dmesg, which is pretty dirty."

@tas50
Copy link
Contributor Author

tas50 commented Feb 2, 2016

/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
DMI if they're on a HVM box
ec2metadata if they're on an official amazon AMI on either HVM or Paravirt
MAC if they're in a classic networking setup

tas50 added a commit that referenced this pull request Feb 2, 2016
Improve EC2 detection when hint isn't present
@tas50 tas50 merged commit 493143c into chef:master Feb 2, 2016
@btm
Copy link
Contributor

btm commented Feb 3, 2016

#723

@tas50 tas50 changed the title Improve EC2 detection when hint isn't present Improve EC2 detection for HVM instances when a hint isn't present Feb 3, 2016
@thommay thommay added Type: Enhancement Adds new functionality. and removed Enhancement labels Jan 24, 2017
@chef chef locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Enhancement Adds new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants