6 $1 -h|--host=<hostname> -e|--engine=<vmengine> -c|--config=<config> -t|--template=<template>
7 config use the syntax used in test/config/default file
8 hostname=vmengine:template:address/mask:gateway
15 options=`getopt -o h:e:c:t: -l host:,engine:,config:,template: -- "$@"`
17 usage_vm `basename $0`
20 eval set -- "$options"
25 -e|--engine) VMENGINE=$2; shift 2;;
26 -h|--host) HOST=$2; shift 2;;
27 -c|--config) CONFIG=$2; shift 2;;
28 -t|--template) VMTEMPLATE=$2; shift 2;;
34 # Loading default config
35 if [ -f $configdir/default ]
39 echo "Something went wrong, could not find default config: $configdir/default"
43 # Loading specific config
44 if [ -f $configdir/`hostname` ]
46 echo "Using specific config: $configdir/`hostname`"
47 . $configdir/`hostname`
49 echo "Using default config"
52 # Host can be defined by env var
55 echo "host not defined"
60 BASEHOST=`echo $HOST|cut -d. -f1`
64 eval "$BASEHOST=$CONFIG"
67 # Now let's look if host/engine is defined in config
68 IFS=: ; VARS=`eval echo \\\$$BASEHOST` ; unset IFS ;
76 echo "$BASEHOST=`eval echo \\\$$BASEHOST`"
79 export HOST BASEHOST $BASEHOST SSHPUBKEY
83 # Try to guess the vmengine
84 if [ -x /usr/sbin/vzctl ]
88 if [ -x /usr/bin/lxc-start ]
94 echo "VM engine not defined"
100 if [ -z "$VMTEMPLATE" ]
102 echo "Template not defined"
107 export VMTEMPLATE VMENGINE CIDR IPGW
112 tests/scripts/destroy_vm $@ || true
115 start_vm_if_not_keeped()
119 # VM can already exist
120 tests/scripts/start_vm $@
122 # Destroy the VM if found
123 tests/scripts/stop_vm $@ || true
124 if ! tests/scripts/start_vm $@
126 echo "Could not start VM";
132 stop_vm_if_not_keeped()
136 echo "Keeping vm $@ alive"
138 tests/scripts/stop_vm $@