Class: VGH::EC2::MetaData

Inherits:
Object
  • Object
show all
Defined in:
lib/vgh/ec2/metadata.rb

Overview

This class gathers metadata information about the current instance, used by the applications in this gem.

Usage

data = Metadata.new
id   = data.instance_id
root = data.root_device

Instance Method Summary collapse

Instance Method Details

#instance_idString?

Query the API server for the instance ID

Returns:

  • (String, nil)

    The current instance’s ID



33
34
35
36
37
38
39
# File 'lib/vgh/ec2/metadata.rb', line 33

def instance_id
  begin
    @instance_id = open('http://instance-data/latest/meta-data/instance-id').read
  rescue
    message.fatal 'Could not get Instance ID!'
  end
end

#root_deviceString?

Query the API server for the root device

Returns:

  • (String, nil)

    The root device of the current instance



43
44
45
46
47
48
49
# File 'lib/vgh/ec2/metadata.rb', line 43

def root_device
  begin
    @root_device = open('http://instance-data/latest/meta-data/block-device-mapping/root').read
  rescue
    message.fatal 'Could not get the root device!'
  end
end