#!/bin/sh -e
#
# Copyright (C) 2009 Canonical, Ltd.
# Author: Kees Cook <kees@ubuntu.com>
# License: GPLv3
#
# Get list of VMs
#

ustconf="$HOME/.uqt-vm-tools.conf"
if [ -s "$ustconf" ]; then
    . "$ustconf"
else
    echo "Could not find '$ustconf'"
    exit 1
fi

. $UQT_VM_TOOLS/libvm.sh
abort_if_root

help() {
    echo "Usage: vm-list [-p PREFIX] [-a ARCH]"
}

arch=
prefix="sec"
while getopts "ha:p:" opt
do
    case "$opt" in
        a) arch="$OPTARG";;
        p) prefix="$OPTARG";;
        ?|h) help
           exit 1
           ;;
    esac
done
shift $(($OPTIND - 1))

if [ -z "$prefix" ]; then
    if [ -z "$1" ]; then
        help
        exit 1
    fi

    for i in "$@" ; do
        echo "$i"
    done
else
    archs=$vm_archs
    if [ ! -z "$arch" ]; then
        archs="$arch"
    fi

    for a in $archs ; do
        for m in `vm_get_machines_by_prefix "${prefix}" "$a"` ; do
            echo "$m"
        done
    done
fi

exit 0
