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
36 gen_fake_managed_node
() {
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 \
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 \
56 virsh destroy node
$num > /dev
/null
2>&1
57 echo "node$num created"
61 case $# in 1) warn
"$1"; try_h
; exit 1;; esac
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
71 while getopts :d
:n
:h c
; do
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";;
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"
91 test -f $nodeimg || die
"could not find $nodeimg"
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)