source: trunk/scripts/invirt-admin/invirt-admin @ 2040

Last change on this file since 2040 was 2040, checked in by price, 15 years ago

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.

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/bin/bash
2
3set -e
4
5usage () {
6    echo "usage:"
7    echo "invirt-admin create-sysvm {options}"
8    echo "  required options: --name, --fs-size, --swap-size, --memory,"
9    echo "    --hostname, --ip, --mac, --arch, --dist, --mirror"
10    echo
11    echo "  fs-size, swap-size, memory in MB"
12    echo "  fs-size + swap-size will be total disk-image size"
13    exit 2
14}
15
16if [ create-sysvm != "$1" ]; then
17    usage
18fi
19shift
20
21vg=xenvg
22while [ $# -gt 0 ]; do
23    case "$1" in
24        --vg)        vg=$2;        shift 2;;
25        --name)      name=$2;      shift 2;;
26        --fs-size)   fs_size=$2;   shift 2;;
27        --swap-size) swap_size=$2; shift 2;;
28        --memory)    memory=$2;    shift 2;;
29        --hostname)  hostname=$2shift 2;;
30        --ip)        ip=$2;        shift 2;;
31        --mac)       mac=$2;       shift 2;;
32        --arch)      arch=$2;      shift 2;;
33        --dist)      dist=$2;      shift 2;;
34        --mirror)    mirror=$2;    shift 2;;
35    esac
36done
37if [ -z "$name" ]; then
38    usage
39fi
40disk_size=$(( $fs_size + $swap_size ))
41
42
43lvcreate "$vg" --name "s_${name}_hda" --size "$disk_size"m
44
45# XXX breaks if $name has dashes
46TARGET=/dev/mapper/$vg-s_${name}_hda FSSIZE=$fs_size \
47ARCH=$arch DIST=$dist MIRROR=$mirror \
48HOSTNAME=$hostname IP=$ip \
49 invirt-create-image
50
51cat >/etc/xen/sysvms/s_$name <<EOF
52import os
53
54release     = os.uname()[2]
55kernel      = '/boot/vmlinuz-%s' % release
56ramdisk     = '/boot/initrd.img-%s' % release
57memory      = '$memory'
58
59disk        = ['phy:$vg/s_${name}_hda,hda,w']
60
61name        = 's_$name'
62
63vif         = [ 'ip=$ip,mac=$mac' ]
64
65on_poweroff = 'destroy'
66on_reboot   = 'restart'
67on_crash    = 'restart'
68
69root = "/dev/hda1 ro"
70extra = '2 console=xvc0'
71EOF
72
73echo
74echo "Configuration written to /etc/xen/sysvms/s_$name."
75echo "To boot:"
76echo "  xm create sysvms/s_$name"
Note: See TracBrowser for help on using the repository browser.