Automate the creation of vms on KVM
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Automate the creation of CoreOs and Ubuntu vms on KVM


  • ruby
  • git
  • qemu-img
  • virt-install
  • virsh
  • wget
  • bzip2
  • dd
  • gzip
  • perl
  • libxml-simple-perl
  • libsys-virt-perl

Configure the virtualization host following these steps


Get the latest version

git clone --depth 1
cd kvm-automation
git pull --rebase origin master

Create a CoreOs vm

ruby vm_task.rb CoreOsVmCreationTask \
    --path ~/vms/ \
    --name vm1 \
    --img ~/vm-templates/coreos_production_qemu_image.img \
    --key ~/vm-templates/

Create an Ubuntu vm

ruby vm_task.rb UbuntuVmCreationTask \
    --path ~/vms/ \
    --name vm2 \
    --os-variant "ubuntu16.04" \
    --img ~/vm-templates/ubuntu-16.04.2-server-amd64.iso
# At this point the command will display the vm's mac address and vnc port  
# From your host vnc to `vmhost.local:<VNC_PORT>` and finish the installation  

Restore an Ubuntu vm

ruby vm_task.rb UbuntuVmRestoreTask \
    --path ~/vms/ \
    --name vm3 \
    --os-variant "ubuntu16.04" \
    --img ~/vm-backups/vm1/20170701000000/vm1/vm1_vda.img.gz

Shrink a vm HDD

sudo ruby vm_task.rb HddShrinkTask --path ~/vms/ --name vm3

Backup a vm

sudo ruby vm_task.rb VmBackupTask --path ~/vm-backups/ --name vm1

Get the path for the latest vm backup

ruby vm_task.rb ReadVmBackupPathTask --path ~/vm-backups/ --name vm1

Destroy a vm

ruby vm_task.rb VmDeletionTask --path ~/vms/ --name vm1

Delete all vm backups

sudo ruby vm_task.rb DeleteAllVmBackupsTask --path ~/vm-backups/ --name vm1

Get the mac address of a vm

ruby vm_task.rb ReadVmMacTask --name vm1

Get the vnc infomation of a vm

ruby vm_task.rb ReadVmVncInfoTask --name vm1