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
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; }
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
40 gen_fake_managed_node
() {
43 local last_mac
=$
(( 54 + $num ))
45 local os_variant
=fedora10
46 if [ "$no_virtio" = 1 ]; then
50 echo "Creating fake node$num using $nodeimg..."
51 local dest_nodeimg
="$imgdir/node${num}-$(basename $src_nodeimg)"
52 echo "$src_nodeimg -> $dest_nodeimg"
53 rsync
-av $src_nodeimg $dest_nodeimg
55 virsh destroy node
$num > /dev
/null
2>&1
56 virsh undefine node
$num > /dev
/null
2>&1
59 for ((i
=0;i
<$num_disks;i
+=1)); do
60 qemu-img create
-f $NODE_DISK_FMT \
61 $imgdir/node
${num}-${i}.
$NODE_DISK_FMT $NODE_DISK_SIZE
62 disks
="$disks --disk path=$imgdir/node${num}-${i}.$NODE_DISK_FMT"
65 # FIXME: virt-install should be changed to have a --nostart parameter
66 # that just defines the VM w/o starting it.
67 virt-install
--name=node
$num --ram=$ram --vcpus=$vcpus $disks \
68 --cdrom=$dest_nodeimg --livecd \
69 --network=bridge
:$BRIDGENAME --mac=00:16:3e
:12:34:$last_mac \
70 --vnc --accelerate --hvm --noautoconsole \
71 --os-type=linux
--os-variant=$os_variant \
73 virsh destroy node
$num > /dev
/null
2>&1
74 echo "node$num created"
78 case $# in 1) warn
"$1"; try_h
; exit 1;; esac
80 Usage: $ME [-d image_dir] [-n node.iso] [-c num_disks] [-s start-stop]
81 [-v vcpus] [-r ram] [-x]
82 -n: node.iso to boot (default: $NODEIMG_DEFAULT)
83 -d: directory to place virtual disk (default: $IMGDIR_DEFAULT)
84 -c: number of disks per fake node (default: $NUM_DISKS_DEFAULT)
85 -s: node range (default: $RANGE_DEFAULT)
86 -v: vcpus per node (default: $VCPUS_DEFAULT)
87 -r: ram in MB per node (default: $RAM_DEFAULT)
88 -x: toggle virtio devices off
89 -h: display this help and exit
95 num_disks
=$NUM_DISKS_DEFAULT
99 while getopts :d
:n
:s
:c
:v
:r
:xh c
; do
103 c
) num_disks
=$OPTARG;;
109 '?') err
=1; warn
"invalid option: \`-$OPTARG'";;
110 :) err
=1; warn
"missing argument to \`-$OPTARG' option";;
111 *) err
=1; warn
"internal error: \`-$OPTARG' not handled";;
114 test $err = 1 && { try_h
; exit 1; }
115 test $help = 1 && { usage
; exit 0; }
117 # first, check to see we are root
118 if [ $
( id
-u ) -ne 0 ]; then
119 die
"Must run as root"
124 test -f $nodeimg || die
"could not find $nodeimg"
126 # define the fake managed nodes we will use.
127 range_start
=$
(echo $range | cut
-d '-' -f 1)
128 range_stop
=$
(echo $range | cut
-d '-' -f 2)
130 for i
in `seq $range_start $range_stop` ; do
131 gen_fake_managed_node
$i $nodeimg