Created
September 18, 2013 16:47
-
-
Save danielpetisme/6611990 to your computer and use it in GitHub Desktop.
Veewee + OpenStack Rakefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
task :default => [:all] | |
task :all, [:provider] => [:build, :halt, :shrink] | |
def isVeeweeFolder() | |
return if not Dir.exists? './definitions/' | |
end | |
def getBoxName() | |
return File.basename(Dir.glob("./definitions/*").at(0)) | |
end | |
def veewee(command, provider, boxname, options) | |
sh "rvmsudo veewee #{provider} #{command} #{boxname} #{options}" | |
end | |
def imageExists() | |
return system "glance image-show --human-readable #{getBoxName()} | grep 'No image' | wc -l" | |
end | |
desc "Build the Box" | |
task :build, [:provider] do |t, args| | |
unless isVeeweeFolder() | |
options = "--force" | |
veewee("build", args.provider, getBoxName(), options) | |
end | |
end | |
desc "Halt the Box" | |
task :halt, [:provider] do |t, args| | |
unless isVeeweeFolder() | |
veewee("halt", args.provider, getBoxName(), nil) | |
end | |
end | |
desc "Shrink the Box" | |
task :shrink do | |
sh "sudo qemu-img convert -O qcow2 /var/lib/libvirt/images/#{getBoxName()}.qcow2 /var/lib/libvirt/images/#{getBoxName()}-shrinked.qcow2" | |
sh "sudo virt-sparsify --format qcow2 /var/lib/libvirt/images/#{getBoxName()}-shrinked.qcow2 /var/lib/libvirt/images/#{getBoxName()}-sparsified.qcow2" | |
sh "sudo qemu-img convert -c -p -f qcow2 -O qcow2 /var/lib/libvirt/images/#{getBoxName()}-sparsified.qcow2 /var/lib/libvirt/images/#{getBoxName()}-gold.qcow2" | |
end | |
desc "Release image" | |
task :release, [:provider] do |t, args| | |
boxname = getBoxName() | |
boxname_splitted = boxname.split("-") | |
os = boxname_splitted[0] | |
version = boxname_splitted[1] | |
arch = boxname_splitted[2] | |
sh "mkdir -p /var/cloud/#{args.provider}/#{os}/#{version}/#{arch}/" | |
sh "cp -f /var/lib/libvirt/images/#{getBoxName()}-gold.qcow2 /var/cloud/#{args.provider}/#{os}/#{version}/#{arch}/#{getBoxName()}.qcow2" | |
end | |
desc "Deploy image" | |
task :deploy do | |
#The credentials are provided by Jenkins | |
if imageExists() | |
puts "Box #{getBoxName()} already exists. It will be removed..." | |
sh "glance image-delete #{getBoxName()}" | |
end | |
sh "glance image-create --name='#{getBoxName()}' --is-public=true --container-format=ovf --disk-format=qcow2 < /var/lib/libvirt/images/#{getBoxName()}-gold.qcow2" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment