Module: Vrt::Ec2::Tags
- Defined in:
- lib/vrt/ec2/tags.rb,
lib/vrt/ec2/tags/version.rb
Overview
This module will fetch the EC2 tags for this instance via custom lambda.
Constant Summary collapse
- VERSION =
'0.2.0'
Class Method Summary collapse
- .instance_id ⇒ Object
- .meta_data_uri ⇒ Object
- .read_instance_id ⇒ Object
- .read_tags ⇒ Object
- .request_tags ⇒ Object
- .tag_uri ⇒ Object
- .tags ⇒ Object
Class Method Details
.instance_id ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/vrt/ec2/tags.rb', line 53 def self.instance_id id = read_instance_id raise('Something bad happened since there was no error but this is not a string.') unless id.is_a? String id rescue StandardError warn 'This is not an AWS EC2 instance or unable to contact the AWS instance-data web server.' end |
.meta_data_uri ⇒ Object
19 20 21 |
# File 'lib/vrt/ec2/tags.rb', line 19 def self. @meta_data_uri || @meta_data_uri = URI.parse('http://169.254.169.254') end |
.read_instance_id ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/vrt/ec2/tags.rb', line 62 def self.read_instance_id http = Net::HTTP.new(.host, .port) http.open_timeout = 2 http.read_timeout = 4 request = Net::HTTP::Get.new('/latest/dynamic/instance-identity/rsa2048') http.request(request).body end |
.read_tags ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vrt/ec2/tags.rb', line 27 def self. response = case response when Net::HTTPSuccess response.body when Net::HTTPUnauthorized raise("#{response.}: username and password set and correct?") when Net::HTTPServerError raise("#{response.}: try again later?") else raise(response.) end end |
.request_tags ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vrt/ec2/tags.rb', line 41 def self. http = Net::HTTP.new(tag_uri.host, tag_uri.port) http.use_ssl = true http.open_timeout = 2 http.read_timeout = 4 http.verify_mode = OpenSSL::SSL::VERIFY_PEER request = Net::HTTP::Post.new(tag_uri) request.add_field 'Content-Type', 'text/plain; charset=utf-8' request.body = instance_id http.request(request) end |
.tag_uri ⇒ Object
23 24 25 |
# File 'lib/vrt/ec2/tags.rb', line 23 def self.tag_uri @tag_uri || @tag_uri = URI.parse('https://cert-lambda.core.a51.be/tags') end |
.tags ⇒ Object
12 13 14 15 16 17 |
# File 'lib/vrt/ec2/tags.rb', line 12 def self. yamlstring = puts yamlstring if yamlstring rescue StandardError => e warn "Something failed.... Abort! : #{e.class} - #{e.}" end |