6 BUILD="${HOME}/git-build"
15 [ -d $LOGS ] || { echo "Creating logs dir $LOGS" ; mkdir -p $LOGS; }
17 DOMAIN=pl.sophia.inria.fr
24 echo "usage : $COMMAND [-c] [-f distro] [-i image] [ -m memory ] [ -n hostname ] container"
25 echo " -c : confirm, will show the command and prompt for confirmation "
26 echo " -f : set distro, default is $DEFAULT_DISTRO"
27 echo " -i : if specified, image is rsynced into /vservers"
28 echo " warning: we cannot use an image already in /vservers..."
29 echo " -m : memory size in Mb - default is 512"
30 echo " -n : specify hostname if different from container"
31 echo " container : used for /vservers/foo as well as the lxc/libvirt name"
33 echo " create-vm.sh sandbox"
34 echo " Builds a brand new $DEFAULT_DISTRO 64bits VM named sandbox with hostname sandbox.pl.sophia.inria.fr"
35 echo " create-vm.sh -i /vservers/migrating/testmaster -n testmaster testmaster.f14"
36 echo " Create a container named testmaster.f14 from the specified image with hostname testmaster.pl.sophia.inria.fr"
37 [ -n "$message" ] && echo $message
41 # using HOSTNAME won't work as this is already set in environment
42 while getopts "cf:i:m:n:h" flag; do
48 n) VM_HOSTNAME=$OPTARG ;;
54 [[ -z "$@" ]] && usage "no hostname provided"
55 container="$1" ; shift
56 [[ -n "$@" ]] && usage "extra arguments" "$@" "(container=$container)"
59 [ -d "$BUILD" ] || usage "Could not find directory $BUILD"
60 [ -d /vservers/$container ] && usage "container $container already exists in /vservers"
62 # comopute all vars from args
63 [ -z "$DISTRO" ] && DISTRO="$DEFAULT_DISTRO"
64 [ -z "$VM_HOSTNAME" ] && VM_HOSTNAME="$container"
65 fqdn=$VM_HOSTNAME.$DOMAIN
67 # prepare initvm command
68 initvm="$BUILD/lbuild-initvm.sh"
69 [ -z "$IMAGE" ] && initvm="$initvm -f $DISTRO" || initvm="$initvm -i $IMAGE"
70 initvm="$initvm -n $fqdn"
71 [ -n "$MEMORY" ] && initvm="$initvm -m $MEMORY"
72 initvm="$initvm $container"
74 if [ -n "$CONFIRM" ] ; then
75 echo -n "Run $initvm OK ? "
76 read answer ; case $answer in [nN]*) exit 1 ;; esac
79 echo "Running $initvm"
80 echo "Storing output in $LOGS/$container.log"
81 $initvm >& $LOGS/$container.log