Skip to content

Instantly share code, notes, and snippets.

@fairchild

fairchild/foo.rb

Forked from jameskyle/foo.rb
Created Nov 10, 2012
Embed
What would you like to do?
#!/usr/bin/ruby
require 'net/http'
META_BASE = "/2008-02-01/meta-data"
def server
@server ||= Net::HTTP.new("169.254.169.254")
end
def get_data(request_uri)
request = Net::HTTP::Get.new(request_uri)
response = $http.request(request)
return response.body
end
get_data(META_BASE).split.each do |item|
data = get_data("#{$meta_base}/#{item}")
puts "#{item} => #{data}"
puts "----------------"
end
require 'net/http'
require 'open-uri'
@metadata=Hash.new
base="http://169.254.169.254/2008-02-01/meta-data/"
puts URI(base).open.read
puts '------------\n'
%w(reservation-id
security-groups
public-ipv4
ami-manifest-path
instance-type
instance-id
local-ipv4
local-hostname
ami-launch-index
public-hostname
hostname
ami-id
instance-action
).each do |key|
@metadata[key]=URI("#{base}#{key}").open.read
end
@metadata['zone']=URI("#{base}placement/availability-zone}").open.read
@metadata['ssh-key']=URI(base+'public-keys/').open.read.split('=').pop
# iterate over block devices
#block-device-mapping/
@metadata['block-devices']={}
URI(base+'/block-device-mapping/').open.read.each do |block|
@metadata['block-devices'][block]=URI("#{base}/block-device-mapping/#{block}").open.read
end
print @metadata.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.