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

Last change on this file since 2237 was 2237, checked in by broder, 15 years ago

Don't loop infinitely if options are misspelled (or invalid).

  • Property svn:executable set to *
File size: 1.8 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 MiB"
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        *)
36            echo "Unknown option: $1"
37            echo
38            usage
39            ;;
40    esac
41done
42if [ -z "$name" ]; then
43    usage
44fi
45disk_size=$(( $fs_size + $swap_size ))
46
47
48lvcreate "$vg" --name "s_${name}_hda" --size "$disk_size"m
49
50# XXX breaks if $name has dashes
51TARGET=/dev/mapper/$vg-s_${name}_hda FSSIZE=$fs_size \
52ARCH=$arch DIST=$dist MIRROR=$mirror \
53HOSTNAME=$hostname IP=$ip \
54 invirt-create-image
55
56cat >/etc/xen/sysvms/s_$name <<EOF
57import os
58
59release     = os.uname()[2]
60kernel      = '/boot/vmlinuz-%s' % release
61ramdisk     = '/boot/initrd.img-%s' % release
62memory      = '$memory'
63
64disk        = ['phy:$vg/s_${name}_hda,hda,w']
65
66name        = 's_$name'
67
68vif         = [ 'ip=$ip,mac=$mac' ]
69
70on_poweroff = 'destroy'
71on_reboot   = 'restart'
72on_crash    = 'restart'
73
74root = "/dev/hda1 ro"
75extra = '2 console=xvc0'
76EOF
77
78echo
79echo "Configuration written to /etc/xen/sysvms/s_$name."
80echo "To boot:"
81echo "  xm create sysvms/s_$name"
Note: See TracBrowser for help on using the repository browser.