Class: Specinfra::Ec2Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/specinfra/ec2_metadata.rb

Instance Method Summary collapse

Constructor Details

#initialize(host_inventory) ⇒ Ec2Metadata



4
5
6
7
8
9
# File 'lib/specinfra/ec2_metadata.rb', line 4

def initialize(host_inventory)
  @host_inventory = host_inventory

  @base_uri = 'http://169.254.169.254/latest/meta-data/'
   = {}
end

Instance Method Details

#[](key) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/specinfra/ec2_metadata.rb', line 16

def [](key)
  if key.is_a?(Symbol)
    key = key.to_s
  end
  if [key].nil?
    begin
      require "specinfra/ec2_metadata/#{key}"
      inventory_class = Specinfra::.const_get(key.to_s.to_camel_case)
      [key] = inventory_class.new(@host_inventory).get
    rescue LoadError
      [key] = nil
    end
  end

  [key]
end

#eachObject



37
38
39
40
41
# File 'lib/specinfra/ec2_metadata.rb', line 37

def each
  keys.each do |k|
    yield k, [k]
  end
end

#each_keyObject



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

def each_key
  keys.each do |k|
    yield k
  end
end

#each_valueObject



49
50
51
52
53
# File 'lib/specinfra/ec2_metadata.rb', line 49

def each_value
  keys.each do |k|
    yield [k]
  end
end

#empty?Boolean



33
34
35
# File 'lib/specinfra/ec2_metadata.rb', line 33

def empty?
  .empty?
end

#getObject



11
12
13
14
# File 'lib/specinfra/ec2_metadata.rb', line 11

def get
   = 
  self
end

#inspectObject



59
60
61
# File 'lib/specinfra/ec2_metadata.rb', line 59

def inspect
  
end

#keysObject



55
56
57
# File 'lib/specinfra/ec2_metadata.rb', line 55

def keys
  .keys
end