From: Greg Price <price@mit.edu>
Date: Sat, 31 Jan 2009 03:14:28 +0000 (-0500)
Subject: invirt-admin create-sysvm
X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/invirt-admin.git/commitdiff_plain/c8a0789183a6384280e164ca0e1cd9bf136e5d52

invirt-admin create-sysvm

This produces a new sysvm with lvcreate, invirt-create-image,
and writing out a Xen config file.

invirt-admin will end up in a package, but which one I'm not sure,
so for now it's on its own.  Probably it should also end up being
written in Python rather than shell.

svn path=/trunk/scripts/invirt-admin/; revision=2040
---

c8a0789183a6384280e164ca0e1cd9bf136e5d52
diff --git a/invirt-admin b/invirt-admin
new file mode 100755
index 0000000..91c73c7
--- /dev/null
+++ b/invirt-admin
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+set -e
+
+usage () {
+    echo "usage:"
+    echo "invirt-admin create-sysvm {options}"
+    echo "  required options: --name, --fs-size, --swap-size, --memory,"
+    echo "    --hostname, --ip, --mac, --arch, --dist, --mirror"
+    echo
+    echo "  fs-size, swap-size, memory in MB"
+    echo "  fs-size + swap-size will be total disk-image size"
+    exit 2
+}
+
+if [ create-sysvm != "$1" ]; then
+    usage
+fi
+shift
+
+vg=xenvg
+while [ $# -gt 0 ]; do
+    case "$1" in
+	--vg)        vg=$2;        shift 2;;
+	--name)      name=$2;      shift 2;;
+	--fs-size)   fs_size=$2;   shift 2;;
+	--swap-size) swap_size=$2; shift 2;;
+	--memory)    memory=$2;    shift 2;;
+	--hostname)  hostname=$2;  shift 2;;
+	--ip)        ip=$2;        shift 2;;
+	--mac)       mac=$2;       shift 2;;
+	--arch)      arch=$2;      shift 2;;
+	--dist)      dist=$2;      shift 2;;
+	--mirror)    mirror=$2;    shift 2;;
+    esac
+done
+if [ -z "$name" ]; then
+    usage
+fi
+disk_size=$(( $fs_size + $swap_size ))
+
+
+lvcreate "$vg" --name "s_${name}_hda" --size "$disk_size"m
+
+# XXX breaks if $name has dashes
+TARGET=/dev/mapper/$vg-s_${name}_hda FSSIZE=$fs_size \
+ARCH=$arch DIST=$dist MIRROR=$mirror \
+HOSTNAME=$hostname IP=$ip \
+ invirt-create-image 
+
+cat >/etc/xen/sysvms/s_$name <<EOF
+import os
+
+release     = os.uname()[2]
+kernel      = '/boot/vmlinuz-%s' % release
+ramdisk     = '/boot/initrd.img-%s' % release
+memory      = '$memory'
+
+disk        = ['phy:$vg/s_${name}_hda,hda,w']
+
+name        = 's_$name'
+
+vif         = [ 'ip=$ip,mac=$mac' ]
+
+on_poweroff = 'destroy'
+on_reboot   = 'restart'
+on_crash    = 'restart'
+
+root = "/dev/hda1 ro"
+extra = '2 console=xvc0'
+EOF
+
+echo
+echo "Configuration written to /etc/xen/sysvms/s_$name."
+echo "To boot:"
+echo "  xm create sysvms/s_$name"