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

[ohai][ec2][looks_like_ec2] Do not depend on metadata endpoint #1768

Merged
merged 7 commits into from
Oct 11, 2022
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/ohai/plugins/ec2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@

Ohai.plugin(:EC2) do
require_relative "../mixin/ec2_metadata"
require_relative "../mixin/http_helper"

include Ohai::Mixin::Ec2Metadata
include Ohai::Mixin::HttpHelper

provides "ec2"

Expand Down Expand Up @@ -107,11 +105,7 @@ def file_val_if_exists(path)
# @return [Boolean] Does the system appear to be on EC2
def looks_like_ec2?
return true if hint?("ec2")

# Even if it looks like EC2 try to connect first
if has_ec2_xen_uuid? || has_ec2_amazon_dmi? || has_ec2_xen_dmi? || has_ec2_identifying_number?
return true if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
end
return true if has_ec2_xen_uuid? || has_ec2_amazon_dmi? || has_ec2_xen_dmi? || has_ec2_identifying_number?
end

collect_data do
Expand Down