From cbdd7bd82ce2c690531d0bd556f9b738413d16f3 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 21 Mar 2014 18:55:59 +0100 Subject: [PATCH] add option -m for setting memory add option -n for setting hostname if different from container-name review options to be in line with the ones in lbuild-initvm (-i -> -c for confirm, -I -> -i) --- scripts/create-vm.sh | 64 +++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/scripts/create-vm.sh b/scripts/create-vm.sh index b879490..43adf55 100755 --- a/scripts/create-vm.sh +++ b/scripts/create-vm.sh @@ -17,50 +17,66 @@ LOGS=$HOME/machines DOMAIN=pl.sophia.inria.fr DEFAULT_DISTRO=f20 -# do not care about 32 bits anymore -#DEFAULT_PERSO=linux64 -INTERACTIVE= -DISTRO=$DEFAULT_DISTRO +CONFIRM= function usage () { message="$@" - echo "usage : $COMMAND [-i] [-f distro] [-I Image] hostname" - echo " default distro is $DEFAULT_DISTRO" + echo "usage : $COMMAND [-c] [-f distro] [-i image] [ -m memory ] [ -n hostname ] container" + echo " -c : confirm, will show the command and prompt for confirmation " + echo " -f : set distro, default is $DEFAULT_DISTRO" + echo " -i : if specified, image is rsynced into /vservers" + echo " warning: we cannot use an image already in /vservers..." + echo " -m : memory size in Mb - default is 512" + echo " -n : specify hostname if different from container" + echo " container : used for /vservers/foo as well as the lxc/libvirt name" + echo "examples" + echo " create-vm.sh sandbox" + echo " Builds a brand new $DEFAULT_DISTRO 64bits VM named sandbox with hostname sandbox.pl.sophia.inria.fr" + echo " create-vm.sh -i /vservers/migrating/testmaster -n testmaster testmaster.f14" + echo " Create a container named testmaster.f14 from the specified image with hostname testmaster.pl.sophia.inria.fr" [ -n "$message" ] && echo $message exit 1 } -while getopts "f:I:ih" flag; do +while getopts "cf:i:m:n:h" flag; do case $flag in - f) DISTRO=$OPTARG;; - i) INTERACTIVE=true ;; - I) IMAGE=$OPTARG;; + c) CONFIRM=true ;; + f) DISTRO=$OPTARG ;; + i) IMAGE=$OPTARG ;; + m) MEMORY=$OPTARG ;; + n) HOSTNAME=$OPTARG ;; ?|h) usage "" ;; esac done +# parse args shift $((OPTIND-1)) [[ -z "$@" ]] && usage "no hostname provided" container="$1" ; shift -[[ -n "$@" ]] && usage "extra arguments" "$@" "(hostname=$container)" - +[[ -n "$@" ]] && usage "extra arguments" "$@" "(container=$container)" +# sanity checks [ -d "$BUILD" ] || usage "Could not find directory $BUILD" - [ -d /vservers/$container ] && usage "container $container already exists in /vservers" -fqdn=$container.$DOMAIN - -if [ -n "$IMAGE" ]; then - command="$BUILD/lbuild-initvm.sh -f $DISTRO -n $fqdn -i $IMAGE $container" -else - command="$BUILD/lbuild-initvm.sh -f $DISTRO -n $fqdn $container" -fi - -if [ -n "$INTERACTIVE" ] ; then - echo -n "Run $command OK ? " +# comopute all vars from args +[ -z "$DISTRO" ] && DISTRO="$DEFAULT_DISTRO" +[ -z "$HOSTNAME" ] && HOSTNAME="$container" +fqdn=$HOSTNAME.$DOMAIN + +# prepare initvm command +initvm="$BUILD/lbuild-initvm.sh" +initvm="$initvm -f $DISTRO" +initvm="$initvm -n $fqdn" +[ -n "$IMAGE" ] && initvm="$initvm -i $IMAGE" +[ -n "$MEMORY" ] $$ initvm="$initvm -m $MEMORY" +initvm="$initvm $container" + +if [ -n "$CONFIRM" ] ; then + echo -n "Run $initvm OK ? " read answer ; case $answer in [nN]*) exit 1 ;; esac fi +echo "Running $initvm" echo "Storing output in $LOGS/$container.log" -$command >& $LOGS/$container.log +$initvm >& $LOGS/$container.log -- 2.43.0