These scripts make virtualization with Virsh a little more fun to work with.

Download archive.

vm_clone

This script is for cloning a virtual machine. You simply create and configure a virtual machine which will be used as the base for many other VM's. The backing file should use the qcow2 image format. When the machine is fully configured the backing file should be marked read only. The following shows its use:

robert-crazy-laptop:~ $ ls -l /var/lib/libvirt/images/UbuntuServerBase.img 
-r-------- 1 libvirt-qemu kvm 1234894848 2010-10-03 15:34 /var/lib/libvirt/images/UbuntuServerBase.img
robert-crazy-laptop:~ $ sudo kvm-img info /var/lib/libvirt/images/UbuntuServerBase.img 
image: /var/lib/libvirt/images/UbuntuServerBase.img
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 1.1G
cluster_size: 65536
robert-crazy-laptop:~ $ sudo vm_clone UbuntuServerBase MyNewServer
robert-crazy-laptop:~ $ sudo kvm-img info /var/lib/libvirt/images/MyNewServer.img 
image: /var/lib/libvirt/images/MyNewServer.img
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 136K
cluster_size: 65536
backing file: /var/lib/libvirt/images/UbuntuServerBase.img (actual path: /var/lib/libvirt/images/UbuntuServerBase.img)
robert-crazy-laptop:~ $

vm_dot

This script creates a dot graph showing the relationship between VMs.

robert-crazy-laptop:~ $ sudo vm_dot | dot -Tpng | display

The result will look like this:

vm_addr

This script shows the MAC or IP addresses of all a VMs interfaces. The IP addresses can only be found if the VM has been started at some point. Use it like this:

robert-crazy-laptop:~ $ vm_addr -m MyNewServer
52:54:00:c1:ad:11
robert-crazy-laptop:~ $ vm_addr -i MyNewServer
robert-crazy-laptop:~ $ virsh start MyNewServer
Domain MyNewServer started

robert-crazy-laptop:~ $ vm_addr -i MyNewServer
192.168.122.2
robert-crazy-laptop:~ $

vm_remove

This is used for removing a virtual machine. It deletes both the definition and the backing file. Usage:

robert-crazy-laptop:~ $ sudo vm_remove MyNewServer 
robert-crazy-laptop:~ $