Class: Ec2Meta::Fetcher
- Inherits:
-
Object
- Object
- Ec2Meta::Fetcher
- Defined in:
- lib/ec2_meta/fetcher.rb
Constant Summary collapse
- API_HOST =
'169.254.169.254'.freeze
- API_VERSION =
'2014-02-25'.freeze
Instance Method Summary collapse
- #fetch(path) ⇒ Object
-
#initialize(options = {}) ⇒ Fetcher
constructor
A new instance of Fetcher.
Constructor Details
Instance Method Details
#fetch(path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ec2_meta/fetcher.rb', line 16 def fetch(path) @cache.fetch(path) do res = http_client.get(request_path(path)) break res.body if res.code != '404' fail MetaNotFound, "'#{path}' not found." if fail_on_not_found? nil end rescue Timeout::Error => e logger.error 'Can\'t fetch EC2 metadata from EC2 METADATA API.' logger.error 'ec2_meta gem is only available on AWS EC2 instance.' raise e rescue MetaNotFound => e raise e rescue => e logger.error "Can't fetch EC2 metadata from EC2 METADATA API.(#{e.})" logger.error e.backtrace.join("\n") raise e end |