Class: Specinfra::Ec2Metadata
- Inherits:
-
Object
- Object
- Specinfra::Ec2Metadata
- Defined in:
- lib/specinfra/ec2_metadata.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each ⇒ Object
- #each_key ⇒ Object
- #each_value ⇒ Object
- #empty? ⇒ Boolean
- #get ⇒ Object
-
#initialize(host_inventory) ⇒ Ec2Metadata
constructor
A new instance of Ec2Metadata.
- #inspect ⇒ Object
- #keys ⇒ Object
Constructor Details
#initialize(host_inventory) ⇒ Ec2Metadata
Returns a new instance of 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/' @metadata = {} end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/specinfra/ec2_metadata.rb', line 16 def [](key) if @metadata[key].nil? begin require "specinfra/ec2_metadata/#{key}" inventory_class = Specinfra::Ec2Metadata.const_get(key.to_s.to_camel_case) @metadata[key] = inventory_class.new(@host_inventory).get rescue LoadError @metadata[key] = nil end end @metadata[key] end |
#each ⇒ Object
34 35 36 37 38 |
# File 'lib/specinfra/ec2_metadata.rb', line 34 def each keys.each do |k| yield k, @metadata[k] end end |
#each_key ⇒ Object
40 41 42 43 44 |
# File 'lib/specinfra/ec2_metadata.rb', line 40 def each_key keys.each do |k| yield k end end |
#each_value ⇒ Object
46 47 48 49 50 |
# File 'lib/specinfra/ec2_metadata.rb', line 46 def each_value keys.each do |k| yield @metadata[k] end end |
#empty? ⇒ Boolean
30 31 32 |
# File 'lib/specinfra/ec2_metadata.rb', line 30 def empty? @metadata.empty? end |
#get ⇒ Object
11 12 13 14 |
# File 'lib/specinfra/ec2_metadata.rb', line 11 def get @metadata = self end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/specinfra/ec2_metadata.rb', line 56 def inspect @metadata end |
#keys ⇒ Object
52 53 54 |
# File 'lib/specinfra/ec2_metadata.rb', line 52 def keys @metadata.keys end |