Module: Ec2Metadata

Extended by:
HttpClient
Defined in:
lib/ec2_metadata.rb,
lib/ec2_metadata/base.rb,
lib/ec2_metadata/root.rb,
lib/ec2_metadata/dummy.rb,
lib/ec2_metadata/command.rb,
lib/ec2_metadata/revision.rb,
lib/ec2_metadata/http_client.rb

Defined Under Namespace

Modules: Command, Dummy, HttpClient Classes: Base, NotFoundError, Revision, Root

Constant Summary collapse

DEFAULT_HOST =
"169.254.169.254".freeze
DEFAULT_REVISION =
'latest'

Constants included from HttpClient

HttpClient::DEFAULT_OPEN_TIMEOUT, HttpClient::DEFAULT_READ_TIMEOUT

Instance Attribute Summary

Attributes included from HttpClient

#open_timeout_sec, #read_timeout_sec

Class Method Summary collapse

Methods included from HttpClient

extended, get

Class Method Details

.[](key) ⇒ Object



27
28
29
# File 'lib/ec2_metadata.rb', line 27

def [](key)
  instance[key]
end

.clear_instanceObject



23
24
25
# File 'lib/ec2_metadata.rb', line 23

def clear_instance
  @instance = nil
end

.formalize_key(key) ⇒ Object



44
45
46
# File 'lib/ec2_metadata.rb', line 44

def formalize_key(key)
  key.to_s.gsub(/_/, '-')
end

.from_hash(hash, revision = DEFAULT_REVISION) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/ec2_metadata.rb', line 35

def from_hash(hash, revision = DEFAULT_REVISION)
  # hash = {revision => hash}
  # instance.from_hash(hash)
  rev_obj = instance.new_child(revision)
  instance.instance_variable_set(:@children, {revision => rev_obj})
  instance.instance_variable_set(:@child_keys, [revision])
  rev_obj.from_hash(hash)
end

.instanceObject



19
20
21
# File 'lib/ec2_metadata.rb', line 19

def instance
  @instance ||= Root.new
end

.logging(msg) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ec2_metadata.rb', line 48

def logging(msg)
  @indent ||= 0
  disp = (" " * @indent) << msg
  # puts(disp) 
  @indent += 2
  begin
    result = yield
  ensure
    @indent -= 2
  end
  # puts "#{disp} => #{result.inspect}"
  result
end

.to_hash(revision = DEFAULT_REVISION) ⇒ Object



31
32
33
# File 'lib/ec2_metadata.rb', line 31

def to_hash(revision = DEFAULT_REVISION)
  self[revision].to_hash
end