From 1b6d8e7197f1f80a0c17ba59e51e59f59cc09ec1 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Sun, 27 Dec 2009 22:36:09 +0100 Subject: [PATCH] add template option for lxc-create The lxc-create command is now able to call a sub script to install a mini template. Right now, debian is supported. The rootfs is stored automatically in //rootfs So the rootfs is a subdirectory of the container configuration directory. When lxc-destroy is called, the rootfs is deleted with the container configuration. Signed-off-by: Daniel Lezcano --- src/lxc/lxc-create.in | 60 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/src/lxc/lxc-create.in b/src/lxc/lxc-create.in index ee0f3d1e8..7514803df 100644 --- a/src/lxc/lxc-create.in +++ b/src/lxc/lxc-create.in @@ -34,8 +34,8 @@ if [ "$(id -u)" != "0" ]; then exit 1 fi -shortoptions='n:f:' -longoptions='name:,config:' +shortoptions='n:f:t:' +longoptions='name:,config:,template:' lxc_path=@LXCPATH@ getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@") @@ -58,6 +58,11 @@ while true; do lxc_config=$1 shift ;; + -t|--template) + shift + lxc_template=$1 + shift + ;; --) shift break;; @@ -85,6 +90,8 @@ if [ -d "$lxc_path/$lxc_name" ]; then exit 1 fi +trap "lxc-destroy -n $lxc_name; echo aborted; exit 1" SIGHUP SIGINT SIGTERM + mkdir -p $lxc_path/$lxc_name if [ -z "$lxc_config" ]; then @@ -96,4 +103,51 @@ else fi cp $lxc_config $lxc_path/$lxc_name/config -fi \ No newline at end of file +fi + +if [ ! -z $lxc_template ]; then + + type lxc-$lxc_template + if [ $? -ne 0 ]; then + echo "unknown template '$lxc_template'" + lxc-destroy -n $lxc_name + exit 1 + fi + + if [ -z "$lxc_config" ]; then + echo + echo "Warning:" + echo "-------" + echo "Usually the template option is called with a configuration" + echo "file option too, mostly to configure the network." + echo "eg. lxc-create -n foo -f lxc.conf -t debian" + echo "The configuration file is often:" + echo + echo "lxc.network.type=macvlan" + echo "lxc.network.link=eth0" + echo "lxc.network.flags=up" + echo + echo "or alternatively:" + echo + echo "lxc.network.type=veth" + echo "lxc.network.link=br0" + echo "lxc.network.flags=up" + echo + echo "For more information look at lxc.conf (5)" + echo + echo "At this point, I assume you know what you do." + echo "Press to continue ..." + read dummy + fi + + lxc-$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name + if [ $? -ne 0 ]; then + echo "failed to execute template '$lxc_template'" + lxc-destroy -n $lxc_name + exit 1 + fi + + echo "'$lxc_template' template installed" +fi + +echo "'$lxc_name' created" \ No newline at end of file -- 2.47.2