Makes $dist-updates-newkey only available on Fedora 9.
[ovirt-node-image.git] / create-ovirt-iso-nodes
blob085fd65302fdea95d98838f0f59ffc99b44e5c4c
1 #!/bin/bash
3 # Create fake oVirt Nodes for testing CDROM boot
4 # Copyright 2008 Red Hat, Inc.
5 # Written by Perry Myers <pmyers@redhat.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 PATH=$PATH:/sbin:/usr/sbin
22 ME=$(basename "$0")
23 warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
24 try_h() { printf "Try \`$ME -h' for more information.\n" >&2; }
25 die() { warn "$@"; try_h; exit 1; }
27 BRIDGENAME=ovirtbr0
28 IMGDIR_DEFAULT=/var/lib/libvirt/images
29 imgdir=$IMGDIR_DEFAULT
30 NODEIMG_DEFAULT=/usr/share/ovirt-node-image/ovirt-node-image.iso
31 nodeimg=$NODEIMG_DEFAULT
33 NODE_DISK_FMT=qcow2
34 NODE_DISK_SIZE=128M
36 gen_fake_managed_node() {
37 local num=$1
38 local nodeimg=$2
39 local last_mac=$(( 54 + $num ))
41 echo "Creating fake node$num using $nodeimg..."
42 virsh destroy node$num > /dev/null 2>&1
43 virsh undefine node$num > /dev/null 2>&1
44 rm -f $imgdir/node${i}-sda.$NODE_DISK_FMT
45 qemu-img create -f $NODE_DISK_FMT $imgdir/node${i}-sda.$NODE_DISK_FMT \
46 $NODE_DISK_SIZE
47 # FIXME: virt-install should be changed to have a --nostart parameter
48 # that just defines the VM w/o starting it.
49 virt-install --name=node$num --ram=512 --vcpus=1 \
50 --disk path=$imgdir/node${i}-sda.$NODE_DISK_FMT \
51 --cdrom=$nodeimg --livecd \
52 --network=bridge:$BRIDGENAME --mac=00:16:3e:12:34:$last_mac \
53 --vnc --accelerate --hvm --noautoconsole \
54 --os-type=linux --os-variant=fedora9 \
55 --force --noreboot
56 virsh destroy node$num > /dev/null 2>&1
57 echo "node$num created"
60 usage() {
61 case $# in 1) warn "$1"; try_h; exit 1;; esac
62 cat <<EOF
63 Usage: $ME [-d image_dir] [-n node.iso]
64 -n: node.iso to boot (default: $NODEIMG_DEFAULT)
65 -d: directory to place virtual disk (default: $IMGDIR_DEFAULT)
66 -h: display this help and exit
67 EOF
70 err=0 help=0
71 while getopts :d:n:h c; do
72 case $c in
73 n) nodeimg=$OPTARG;;
74 d) imgdir=$OPTARG;;
75 h) help=1;;
76 '?') err=1; warn "invalid option: \`-$OPTARG'";;
77 :) err=1; warn "missing argument to \`-$OPTARG' option";;
78 *) err=1; warn "internal error: \`-$OPTARG' not handled";;
79 esac
80 done
81 test $err = 1 && { try_h; exit 1; }
82 test $help = 1 && { usage; exit 0; }
84 # first, check to see we are root
85 if [ $( id -u ) -ne 0 ]; then
86 die "Must run as root"
89 mkdir -p $imgdir
91 test -f $nodeimg || die "could not find $nodeimg"
92 cp $nodeimg $imgdir
94 # define the fake managed nodes we will use.
95 for i in `seq 6 9` ; do
96 gen_fake_managed_node $i $imgdir/$(basename $nodeimg)
97 done