Class: Specinfra::Ec2Metadata
- Inherits:
-
Object
- Object
- Specinfra::Ec2Metadata
- Defined in:
- lib/specinfra/ec2_metadata.rb
Instance Method Summary collapse
- #get(path = '') ⇒ Object
- #get_endpoint(path) ⇒ Object
-
#initialize ⇒ Ec2Metadata
constructor
A new instance of Ec2Metadata.
Constructor Details
#initialize ⇒ Ec2Metadata
Returns a new instance of Ec2Metadata.
4 5 6 |
# File 'lib/specinfra/ec2_metadata.rb', line 4 def initialize @base_uri = 'http://169.254.169.254/latest/meta-data/' end |
Instance Method Details
#get(path = '') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/specinfra/ec2_metadata.rb', line 8 def get(path='') = {} keys = Specinfra::Runner.run_command("curl #{@base_uri}#{path}").stdout.split("\n") keys.each do |key| if key =~ %r{/$} [key[0..-2]] = get(path + key) else if key =~ %r{=} key = key.split('=')[0] + '/' [key[0..-2]] = get(path + key) else ret = get_endpoint(path) [key] = get_endpoint(path + key) if ret end end end end |