Class: Tagenv::Ec2::Metadata
- Inherits:
-
Object
- Object
- Tagenv::Ec2::Metadata
- Defined in:
- lib/tagenv/ec2/metadata.rb
Constant Summary collapse
- TIME_OUT =
3
Class Method Summary collapse
Class Method Details
.ec2? ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/tagenv/ec2/metadata.rb', line 11 def self.ec2? begin ::Timeout.timeout(TIME_OUT) { open('http://169.254.169.254/latest/meta-data/instance-id').read return true } rescue => e return false end end |
.get_document ⇒ Object
35 36 37 |
# File 'lib/tagenv/ec2/metadata.rb', line 35 def self.get_document JSON.parse(('/latest/dynamic/instance-identity/document/')) end |
.get_instance_id ⇒ Object
39 40 41 |
# File 'lib/tagenv/ec2/metadata.rb', line 39 def self.get_instance_id ('/latest/meta-data/instance-id') end |
.get_metadata(path) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tagenv/ec2/metadata.rb', line 22 def self.(path) begin result = {} ::Timeout.timeout(TIME_OUT) { body = open('http://169.254.169.254' + path).read return body } return result rescue ::Timeout::Error => e raise "not EC2 instance" end end |