3
# The VM name will need to be passed as an argument to this script. Check to make sure we received a command line parameter
5
echo " Error: This script expects one and only one parameter. That parameter should be the name of the VM to create. Example:"
16
echo " Shutting down the VM $VMNAME ..."
17
virsh -q destroy $VMNAME > /dev/null 2>&1
19
# Make sure there aren't any snapshots that would prevent us from undefining
21
SNAPSHOTS=`virsh -q snapshot-list $VMNAME | awk '{print $1}'`
22
if [ -n $SNAPSHOTS ]; then
23
echo " Removing any existing snapshots for VM $VNMAME ..."
24
for SS in $SNAPSHOTS; do
25
virsh snapshot-delete $VMNAME $SS > /dev/null 2>&1
28
echo " No snapshots to remove. Proceeding ..."
32
echo " Undefining the VM $VMNAME ..."
33
OP=`virsh undefine $VMNAME`
35
echo " Hmmmm, something appears to have gone wrong when attempting to undefine the VM. The output of the command is:
40
if [ -d /home/VMs/$VMNAME ]; then
41
echo " Removing the disk image files for VM $VMNAME. This will require sudo privileges."
42
sudo /bin/rm -rf /home/VMs/$VMNAME > /dev/null
48
echo " The removal proccess for the VM $VMNAME is complete."