blob: abdc3322009d3e5a42173bd52dd1c8f3dabf5f58 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
#!/usr/bin/env bash
BASE_DIR=$(readlink -f $(dirname $0))
[[ -z "$COMMON_DIR" ]] && COMMON_DIR="$(cd $BASE_DIR/../common && pwd)"
[[ -z "$TEST_DIR" ]] && TEST_DIR="$(cd $BASE_DIR/../../../../ && pwd)"
function usage()
{
[[ ! -z $2 ]] && ( echo "$2"; echo ""; )
echo "Shortcut script for connecting to or executing command on selected VM"
echo "Usage: $(basename $1) [OPTIONS] VM_NUMBER"
echo
echo "-h, --help print help and exit"
echo " --work-dir=WORK_DIR Where to find build file. Must exist. [default: $TEST_DIR]"
echo "-w Don't wait for vm to boot"
echo "-x set -x for script debug"
exit 0
}
boot_wait=true
while getopts 'xwh-:' optchar; do
case "$optchar" in
-)
case "$OPTARG" in
help) usage $0 ;;
work-dir=*) TEST_DIR="${OPTARG#*=}" ;;
*) usage $0 "Invalid argument '$OPTARG'" ;;
esac ;;
h) usage $0 ;;
w) boot_wait=false ;;
x) set -x ;;
*) usage $0 "Invalid argument '$OPTARG'" ;;
esac
done
. $COMMON_DIR/common.sh
shift $((OPTIND-1))
vm_num="$1"
shift
if ! vm_num_is_valid $vm_num; then
usage $0 "Invalid VM num $vm_num"
exit 1
fi
if $boot_wait; then
while ! vm_os_booted $vm_num; do
if ! vm_is_running $vm_num; then
fail "VM$vm_num is not running"
fi
notice "waiting for VM$vm_num to boot"
sleep 1
done
fi
vm_ssh $vm_num "$@"
|