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_identity_document ⇒ Object
- #instance_type ⇒ Object
- #private_ipv4 ⇒ Object
- #retrieve_data(url, tries: 3) ⇒ Object
- #retrieve_dynamicdata(key, tries: 3) ⇒ Object
- #retrieve_metadata(key, tries: 3) ⇒ Object
Instance Method Details
#availability_zone ⇒ Object
44 45 46 |
# File 'lib/movable_ink/aws/metadata.rb', line 44 def availability_zone @availability_zone ||= ('placement/availability-zone') end |
#http(timeout_seconds: 1) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/movable_ink/aws/metadata.rb', line 7 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
48 49 50 |
# File 'lib/movable_ink/aws/metadata.rb', line 48 def instance_id @instance_id ||= ('instance-id') end |
#instance_identity_document ⇒ Object
38 39 40 41 42 |
# File 'lib/movable_ink/aws/metadata.rb', line 38 def instance_identity_document @instance_identity_document ||= JSON.parse(retrieve_dynamicdata('instance-identity/document')) rescue JSON::ParserError return end |
#instance_type ⇒ Object
52 53 54 |
# File 'lib/movable_ink/aws/metadata.rb', line 52 def instance_type @instance_type ||= ('instance-type') end |
#private_ipv4 ⇒ Object
56 57 58 |
# File 'lib/movable_ink/aws/metadata.rb', line 56 def private_ipv4 @ipv4 ||= ('local-ipv4') end |
#retrieve_data(url, tries: 3) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/movable_ink/aws/metadata.rb', line 16 def retrieve_data(url, tries: 3) tries.times do |num| num += 1 request = Net::HTTP::Get.new(url) 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, Errno::ECONNREFUSED sleep(num * 2) end raise MovableInk::AWS::Errors::MetadataTimeout end |
#retrieve_dynamicdata(key, tries: 3) ⇒ Object
34 35 36 |
# File 'lib/movable_ink/aws/metadata.rb', line 34 def retrieve_dynamicdata(key, tries: 3) retrieve_data("/latest/dynamic/#{key}", tries: tries) end |
#retrieve_metadata(key, tries: 3) ⇒ Object
30 31 32 |
# File 'lib/movable_ink/aws/metadata.rb', line 30 def (key, tries: 3) retrieve_data("/latest/meta-data/#{key}", tries: tries) end |