Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created December 31, 2010 20:13
Show Gist options
  • Save seungjin/761304 to your computer and use it in GitHub Desktop.
Save seungjin/761304 to your computer and use it in GitHub Desktop.
get instance from eucalyptus/Amazon instance
$this_version = '2010.12.28.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
}
$instance_info_json = $instance_info_hash.to_json
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment