Add wrapper for lxc-fedora template 97/41597/5
authorDariusz Michaluk <d.michaluk@samsung>
Tue, 16 Jun 2015 12:39:42 +0000 (14:39 +0200)
committerJan Olszak <j.olszak@samsung.com>
Thu, 18 Jun 2015 17:21:30 +0000 (10:21 -0700)
[Feature]       Add wrapper for lxc-fedora template
[Cause]         N/A
[Solution]      N/A
[Verification]  Build, create/start/shutdown/destroy zone.

Change-Id: Iaa071f19dedfb7406d576858d8c7be2600b1e077

packaging/vasum.spec
server/configs/templates/fedora.sh [new file with mode: 0755]

index 38c7cf6..83c5f0f 100644 (file)
@@ -28,6 +28,7 @@ Requires:       lxc
 Requires:       iproute2
 Requires(post): libcap-tools
 %else
+Requires:       lxc-templates
 Requires:       iproute
 Requires(post): libcap
 %endif
diff --git a/server/configs/templates/fedora.sh b/server/configs/templates/fedora.sh
new file mode 100755 (executable)
index 0000000..dc4db3b
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+
+#  template script for creating Fedora LXC container
+#  This script is a wrapper for the lxc-fedora template
+#
+#  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#  Contact: Dariusz Michaluk  <d.michaluk@samsung.com>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+usage()
+{
+    cat <<EOF
+usage:
+    $1 -n|--name=<zone_name>
+        [-p|--path=<path>] [--rootfs=<rootfs>] [--vt=<vt>]
+        [--ipv4=<ipv4>] [--ipv4-gateway=<ipv4_gateway>] [-h|--help]
+Mandatory args:
+  -n,--name         zone name
+  -p,--path         path to zone config files
+  --rootfs          path to zone rootfs
+Optional args:
+  --vt              zone virtual terminal
+  --ipv4            zone IP address
+  --ipv4-gateway    zone gateway
+  -h,--help         print help
+EOF
+    return 0
+}
+
+options=$(getopt -o hp:n: -l help,rootfs:,path:,vt:,name:,ipv4:,ipv4-gateway: -- "$@")
+if [ $? -ne 0 ]; then
+    usage $(basename $0)
+    exit 1
+fi
+eval set -- "$options"
+
+while true
+do
+    case "$1" in
+        -h|--help)      usage $0 && exit 0;;
+        --rootfs)       rootfs=$2; shift 2;;
+        -p|--path)      path=$2; shift 2;;
+        --vt)           vt=$2; shift 2;;
+        -n|--name)      name=$2; shift 2;;
+        --ipv4)         ipv4=$2; shift 2;;
+        --ipv4-gateway) ipv4_gateway=$2; shift 2;;
+        --)             shift 1; break ;;
+        *)              break ;;
+    esac
+done
+
+if [ "$(id -u)" != "0" ]; then
+    echo "This script should be run as 'root'"
+    exit 1
+fi
+
+if [ -z $name ]; then
+    echo "Zone name must be given"
+    exit 1
+fi
+
+if [ -z "$path" ]; then
+    echo "'path' parameter is required"
+    exit 1
+fi
+
+if [ -z "$rootfs" ]; then
+    echo "'rootfs' parameter is required"
+    exit 1
+fi
+
+/usr/share/lxc/templates/lxc-fedora --name="$name" --path="$path" --rootfs="$rootfs"