Skip to content

Instantly share code, notes, and snippets.

@rubiojr
Created September 4, 2012 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubiojr/3624915 to your computer and use it in GitHub Desktop.
Save rubiojr/3624915 to your computer and use it in GitHub Desktop.
Upload AMI/AKI/ARI to OpenStack Glance
#!/usr/bin/env ruby
name = ARGV[0]
ids = {}
unless name and !name.empty?
puts "Usage: upload_ami <image-name>"
exit 1
end
%w{aki ari}.each do |f|
puts "Uploading #{f} image (usually fast)..."
`glance add disk_format=#{f} container_format=#{f} name=#{name}-#{f} < #{f} 2>&1`.each_line do |l|
if l =~ /Added new image with ID:.*/
ids[f.to_sym] = l.split[-1].chomp.strip
puts "#{f.upcase} ID: #{ids[f.to_sym]}"
end
end
end
puts "Uploading root image (this may take some time)..."
`glance add disk_format=ami container_format=ami name=#{name}-ami kernel_id=#{ids[:aki]} ramdisk_id=#{ids[:ari]} < root.img`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment