Module: MovableInk::AWS::Metadata
- Included in:
- MovableInk::AWS
- Defined in:
- lib/movable_ink/aws/metadata.rb
Instance Method Summary collapse
- #availability_zone ⇒ Object
- #http(timeout_seconds: 1) ⇒ Object
- #instance_id ⇒ Object
- #instance_type ⇒ Object
- #private_ipv4 ⇒ Object
- #retrieve_metadata(key, tries: 3) ⇒ Object
Instance Method Details
#availability_zone ⇒ Object
29 30 31 |
# File 'lib/movable_ink/aws/metadata.rb', line 29 def availability_zone @availability_zone ||= ('placement/availability-zone') end |
#http(timeout_seconds: 1) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/movable_ink/aws/metadata.rb', line 6 def http(timeout_seconds: 1) @http = begin http = Net::HTTP.new("169.254.169.254", 80) http.open_timeout = timeout_seconds http.read_timeout = timeout_seconds http end end |
#instance_id ⇒ Object
33 34 35 |
# File 'lib/movable_ink/aws/metadata.rb', line 33 def instance_id @instance_id ||= ('instance-id') end |
#instance_type ⇒ Object
37 38 39 |
# File 'lib/movable_ink/aws/metadata.rb', line 37 def instance_type @instance_type ||= ('instance-type') end |
#private_ipv4 ⇒ Object
41 42 43 |
# File 'lib/movable_ink/aws/metadata.rb', line 41 def private_ipv4 @ipv4 ||= ('local-ipv4') end |
#retrieve_metadata(key, tries: 3) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/movable_ink/aws/metadata.rb', line 15 def (key, tries: 3) tries.times do |num| num += 1 request = Net::HTTP::Get.new("/latest/meta-data/#{key}") request['X-aws-ec2-metadata-token'] = imds_token response = http(timeout_seconds: num * 3).request(request) return response.body rescue Net::OpenTimeout, Net::ReadTimeout, Errno::EHOSTDOWN sleep(num * 2) end raise MovableInk::AWS::Errors::MetadataTimeout end |