Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created January 4, 2011 19:02
Show Gist options
  • Save seungjin/765213 to your computer and use it in GitHub Desktop.
Save seungjin/765213 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/http'
$this_version = '2011.01.04.001'
$resource_url = 'http://169.254.169.254/latest/meta-data/'
$instance_info_hash = Hash.new
def vmInfo()
def a(address)
url = URI.parse(address)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) }
res.body.split().map { |i| lambda{ if i[-1,1] != "/" then $instance_info_hash[(address+i)[40..-1]] = "" else lambda{a(address+i)}.call end}.call}
end
def set()
a($resource_url)
$instance_info_hash.each_pair{ |key,value|
url = URI.parse($resource_url+key)
req = Net::HTTP::Get.new(url.path)
res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
if res.class == Net::HTTPInternalServerError then $instance_info_hash[key] = nil
else $instance_info_hash[key] = res.body end
}
end
end
def main()
vmInfo.set();
$instance_info_hash.each_pair{ |key,value| puts "#{key} : #{value}" }
puts ""
puts "Atmo Info"
puts "Version #{$this_version}"
puts "Author: Seung-jin Kim <[email protected]>"
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment