[Ovirt-devel] [PATCH appliance] Refactor the create-ovirt-appliance script into several scripts
Perry Myers
pmyers at redhat.com
Fri Nov 14 22:06:55 UTC 2008
Separated out several independent functions from ovirt-create-appliance:
- installing the appliance image from the appliance packaging
- creating the appliance in libvirt
- creating the fake nodes
- setting up the host networking to support running the appliance
Along with these changes also made it so that the appliance and
fake nodes are created using virt-image from the appliance-creator
or from virt-install and changed so that only a single network
(ovirtbr0) is required for the appliance and fake nodes.
Signed-off-by: Perry Myers <pmyers at redhat.com>
---
Makefile.am | 7 +-
create-ovirt-appliance | 344 +++++++--------------------------------------
create-ovirt-network | 141 ++++++++++++++++++
create-ovirt-nodes | 51 +++++++
get-ovirt-appliance | 100 +++++++++++++
ovirt-appliance-functions | 180 +++++++++++++++++++++++
ovirt-appliance.ks | 4 +-
ovirt-appliance.spec.in | 9 ++
8 files changed, 537 insertions(+), 299 deletions(-)
create mode 100755 create-ovirt-network
create mode 100755 create-ovirt-nodes
create mode 100755 get-ovirt-appliance
create mode 100644 ovirt-appliance-functions
diff --git a/Makefile.am b/Makefile.am
index 4b96624..af84422 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -32,6 +32,10 @@ NVR = $(PACKAGE)-$(VERSION)-$(ARCH)
EXTRA_DIST = \
.gitignore \
create-$(PACKAGE) \
+ create-ovirt-network \
+ create-ovirt-nodes \
+ get-$(PACKAGE) \
+ $(PACKAGE)-functions \
gettree.sh \
$(PACKAGE).ks \
$(PACKAGE).spec \
@@ -102,7 +106,8 @@ $(NVR).$(PKG_FMT): repos.ks
)
mkdir -p scripts
- cp -a create-$(PACKAGE) scripts
+ cp -a create-$(PACKAGE) create-ovirt-network create-ovirt-nodes \
+ get-$(PACKAGE) $(PACKAGE)-functions scripts
ln -snf $(OVIRT_CACHE_DIR)/$(PACKAGE)-tmp tmp
sudo su -c "export PATH=$(PATH):/sbin:/usr/sbin && \
diff --git a/create-ovirt-appliance b/create-ovirt-appliance
index 9454377..1669368 100755
--- a/create-ovirt-appliance
+++ b/create-ovirt-appliance
@@ -1,44 +1,42 @@
#!/bin/bash
-
-PATH=$PATH:/sbin:/usr/sbin
-
-ME=$(basename "$0")
-warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
-try_h() { printf "Try \`$ME -h' for more information.\n" >&2; }
-die() { warn "$@"; try_h; exit 1; }
-
-RAM=768
-
-IMGDIR_DEFAULT=/var/lib/libvirt/images
-NAME_DEFAULT=ovirt-appliance
-NET_SCRIPTS=/etc/sysconfig/network-scripts
-BRIDGENAME=ovirtbr0
-NET_TYPE=network
-
-NODE_DISK_SIZE=128M
-NODE_DISK_FMT=raw
-
-imgdir=$IMGDIR_DEFAULT
-name=$NAME_DEFAULT
+#
+# Create oVirt Appliance
+# Copyright 2008 Red Hat, Inc.
+# Written by Perry Myers <pmyers at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+. $(dirname $0)/ovirt-appliance-functions
usage() {
case $# in 1) warn "$1"; try_h; exit 1;; esac
cat <<EOF
-Usage: $ME [-d image_dir] [-n name] [-e eth]
+Usage: $ME [-d image_dir] [-n name] [-c]
-d: directory to place virtual disk (default: $IMGDIR_DEFAULT)
-n: appliance name (default: $NAME_DEFAULT)
- -e: ethernet device to use as bridge (i.e. eth1)
+ -c: open console when appliance is started
-h: display this help and exit
EOF
}
err=0 help=0
-bridge=
-while getopts :d:e:n:h c; do
+console=0
+while getopts :d:n:ch c; do
case $c in
d) imgdir=$OPTARG;;
- e) bridge=$OPTARG;;
n) name=$OPTARG;;
+ c) console=1;;
h) help=1;;
'?') err=1; warn "invalid option: \`-$OPTARG'";;
:) err=1; warn "missing argument to \`-$OPTARG' option";;
@@ -48,282 +46,38 @@ done
test $err = 1 && { try_h; exit 1; }
test $help = 1 && { usage; exit 0; }
-gen_bridge() {
- local name=$1
- cat << EOF
-<network>
- <name>$name</name>
- <bridge name="$name" stp="off" forwardDelay="0" />
- <ip address="192.168.50.1" netmask="255.255.255.0"/>
-</network>
-EOF
-}
-
-gen_fake_managed_node() {
- local num=$1
- local disk=$2
- local last_mac=$(( 54 + $num ))
-
- cat <<EOF
-<domain type='kvm'>
- <name>node$num</name>
- <uuid>25ab2490-7c4c-099f-b647-${num}5ff8efa73f6</uuid>
- <memory>524288</memory>
- <currentMemory>524288</currentMemory>
- <vcpu>1</vcpu>
- <os>
- <type>hvm</type>
- <boot dev='network'/>
- </os>
- <clock offset='utc'/>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>destroy</on_crash>
- <devices>
- <emulator>$KVM_BINARY</emulator>
- <disk type='file' device='disk'>
- <source file='$disk'/>
- <target dev='hda'/>
- </disk>
- <interface type='$NET_TYPE'>
- <mac address='00:16:3e:12:34:$last_mac'/>
- <source $NET_TYPE='$BRIDGENAME'/>
- </interface>
- <serial type='pty'>
- <target port='0'/>
- </serial>
- <console type='pty'>
- <target port='0'/>
- </console>
- <input type='mouse' bus='ps2'/>
- <graphics type='vnc' port='-1' listen='127.0.0.1'/>
- </devices>
-</domain>
-EOF
-}
-
-gen_app() {
- local name=$1
- local disk=$2
- local ram=$3
-
- cat<<EOF
-<domain type='kvm'>
- <name>$name</name>
- <memory>$(( $ram * 1024 ))</memory>
- <currentMemory>$(( $ram * 1024 ))</currentMemory>
- <vcpu>1</vcpu>
- <os>
- <type>hvm</type>
- <boot dev='hd'/>
- </os>
- <clock offset='utc'/>
- <on_poweroff>destroy</on_poweroff>
- <on_reboot>restart</on_reboot>
- <on_crash>destroy</on_crash>
- <devices>
- <emulator>$KVM_BINARY</emulator>
- <disk type='file' device='disk'>
- <source file='$disk'/>
- <target dev='hda'/>
- </disk>
- <interface type='network'>
- <source network='default'/>
- <model type='virtio'/>
- </interface>
- <interface type='$NET_TYPE'>
- <source $NET_TYPE='$BRIDGENAME'/>
- <model type='virtio'/>
- </interface>
- <serial type='pty'>
- <target port='0'/>
- </serial>
- <console type='pty'>
- <target port='0'/>
- </console>
- <input type='mouse' bus='ps2'/>
- <graphics type='vnc' port='-1' listen='127.0.0.1'/>
- </devices>
-</domain>
-EOF
-}
-
-net_debug() {
- # Some output for debugging problems
- echo "Currently active bridges:"
- echo "-------------------------"
- brctl show
- echo
- echo "Currently defined libvirt networks:"
- echo "-----------------------------------"
- virsh net-list --all
- echo
-}
-
-# first, check to see we are root
-if [ $( id -u ) -ne 0 ]; then
- die "Must run as root"
-fi
+do_checks
-# now make sure the packages we need are installed
-if [ -e /etc/redhat-release ]; then
- # We rely on RPM deps for this in Red Hat/Fedora systems
- CHECK=0
- KVM_BINARY=/usr/bin/qemu-kvm
-elif [ -e /etc/debian_version ]; then
- # Works in Ubuntu 8.04. Still needs testing in Debian
- PACKAGES="libvirt0 libvirt-bin kvm qemu"
- CHECK=$(dpkg -l $PACKAGES &> /dev/null; echo $?)
- KVM_BINARY=/usr/bin/kvm
-else
- die "Not a supported system"
-fi
-
-if [ $CHECK -ne 0 ]; then
- # one of the previous packages wasn't installed; bail out
- die "Must have the $PACKAGES packages installed"
-fi
-
-service libvirtd status > /dev/null 2>&1 \
- || service libvirtd start > /dev/null 2>&1
-chkconfig libvirtd on
-
-# Cleanup to handle older version of script that used these bridge names
-{
- virsh net-destroy dummybridge
- virsh net-undefine dummybridge
- brctl delif eth1bridge eth1
- virsh net-destroy eth1bridge
- virsh net-undefine eth1bridge
- old_bridge=$(brctl show \
- | awk -v BRIDGENAME=ovirtbr '$1==BRIDGENAME {print $4}')
- if [ -n "$old_bridge" ]; then
- ifconfig $old_bridge down
- fi
- brctl delif ovirtbr $old_bridge
- virsh net-destroy ovirtbr
- virsh net-undefine ovirtbr
- sed -i "/# ovirtbr$/d" /etc/rc.d/rc.local
-} > /dev/null 2>&1
-
-net_debug
-
-# If we're bridging to a physical network, run some checks to make sure the
-# choice of physical eth device is sane
-if [ -n "$bridge" ]; then
- NET_TYPE=bridge
- # Check to see if the physical device is present
- ifconfig $bridge > /dev/null 2>&1 ; bridge_dev_present=$?
- test $bridge_dev_present != 0 \
- && die "$bridge device not present, aborting!"
-
- # Check to see if the eth device is already tied to a non oVirt bridge
- attached_bridge=$(brctl show \
- | awk -v BRIDGE=$bridge '$4~BRIDGE {print $1}')
- test -n "$attached_bridge" -a "$attached_bridge" != "$BRIDGENAME" \
- && die "$bridge already attached to other bridge $attached_bridge"
-
- # Check to make sure that the system is not already using the interface
- if test -f $NET_SCRIPTS/ifcfg-$bridge ; then
- echo "$NET_SCRIPTS/ifcfg-$bridge is present, are you sure you wish to"
- echo "overwrite this file? [y/N]? "
- read yesno
-
- if [ "$yesno" != "y" -a "$yesno" != "Y" ]; then
- exit 2
- fi
- fi
+if virsh dumpxml $name > /dev/null 2>&1 ; then
+ # If the appliance is already defined, abort since rewriting the appliance
+ # will change network settings that break the appliance.
+ echo "$name is already a defined virtual machine."
+ die
fi
mkdir -p $imgdir
-# define the fake managed nodes we will use.
-for i in `seq 3 5` ; do
- imgname="node${i}.img"
- if [ ! -f $imgdir/$imgname ]; then
- qemu-img create -f $NODE_DISK_FMT $imgdir/$imgname $NODE_DISK_SIZE
- fi
- virsh destroy node$i >& /dev/null
- virsh undefine node$i >& /dev/null
- TMPXML=$(mktemp)
- gen_fake_managed_node $i $imgdir/$imgname > $TMPXML
- virsh define $TMPXML
- rm $TMPXML
-done
-
-# Remove old bridge device if it exists
-sed -i "/# $BRIDGENAME/d" /etc/rc.d/rc.local
-old_bridge=$(brctl show \
- | awk -v BRIDGENAME=$BRIDGENAME '$1==BRIDGENAME {print $4}')
-if [ -n "$old_bridge" ]; then
- echo "Removing old bridge $old_bridge"
- ifconfig $old_bridge down
- brctl delif $BRIDGENAME $old_bridge
- rm -f $NET_SCRIPTS/ifcfg-$old_bridge
-fi
-
-{
-echo "Removing $BRIDGENAME"
-virsh net-destroy $BRIDGENAME
-virsh net-undefine $BRIDGENAME
-ifconfig $BRIDGENAME down
-brctl delbr $BRIDGENAME
-rm -fv $NET_SCRIPTS/ifcfg-$BRIDGENAME
-echo "Done Removing $BRIDGENAME"
-} 2> /dev/null
-
-if [ -n "$bridge" ]; then
- # real external bridge, use distro networking scripts
- ifconfig $bridge down 2> /dev/null
- TMPAUG=$(mktemp) || exit 1
- cat > $TMPAUG <<EOF
-rm /files$NET_SCRIPTS/ifcfg-$bridge
-set /files$NET_SCRIPTS/ifcfg-$bridge/DEVICE $bridge
-set /files$NET_SCRIPTS/ifcfg-$bridge/ONBOOT yes
-set /files$NET_SCRIPTS/ifcfg-$bridge/BRIDGE $BRIDGENAME
-rm /files$NET_SCRIPTS/ifcfg-$BRIDGENAME
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/DEVICE $BRIDGENAME
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/BOOTPROTO static
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/ONBOOT y
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/TYPE Bridge
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/PEERNTP yes
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/IPADDR 192.168.50.1
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/NETMASK 255.255.255.0
-set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/DELAY 0
-save
-EOF
- augtool < $TMPAUG
- ifup $BRIDGENAME
- ifup $bridge
-else
- # internal bridge only, use libvirt networking
- TMPXML=$(mktemp) || exit 1
- gen_bridge $BRIDGENAME > $TMPXML
- virsh net-define $TMPXML
- rm $TMPXML
- virsh net-start $BRIDGENAME
- virsh net-autostart $BRIDGENAME
-fi
-
-net_debug
+appdisk=$name/$name-sda.$DISK_FMT
+datadisk=$name/$name-sdb.$DISK_FMT
-# Cleanup to handle older version of script that used these domain names
-{
- virsh destroy developer
- virsh undefine developer
- virsh destroy bundled
- virsh undefine bundled
-} > /dev/null 2>&1
-
-imgname=$name.img
-test ! -r $imgdir/$imgname && die "Disk image not found at $imgdir/$imgname"
+test ! -r $imgdir/$appdisk && die "Disk image not found at $imgdir/$appdisk"
+test ! -r $imgdir/$datadisk && die "Disk image not found at $imgdir/$datadisk"
virsh destroy $name > /dev/null 2>&1
virsh undefine $name > /dev/null 2>&1
+virt-image -b $BRIDGENAME $imgdir/$name/$name.xml
+# FIXME: virt-image doesn't do virtio so we have to kill the appliance, edit
+# the libvirt xml and restart
+virsh destroy $name > /dev/null 2>&1
TMPXML=$(mktemp) || exit 1
-# FIXME virt-image to define the appliance instance
-gen_app $name $imgdir/$imgname $RAM > $TMPXML
-virsh define $TMPXML
-rm $TMPXML
-echo "Application defined using disk located at $imgdir/$imgname."
-echo "Run virsh start $name to start the appliance"
+BR_XML="<source bridge='$BRIDGENAME'/>"
+VNIC_XML="<model type='virtio'/>"
+# FIXME: virtio disks won't boot presently, need to look into this
+# -e "s/bus='ide'/bus='virtio'/" \
+# -e "s/dev='hd\(.\)'/dev='vd\1'/" \
+virsh dumpxml $name | sed -e "s^\($BR_XML\)^\1\n$VNIC_XML^" \
+ > $TMPXML && \
+ virsh define $TMPXML && \
+ rm -f $TMPXML
+
+test $console = 1 && virsh start $name && virsh console $name
diff --git a/create-ovirt-network b/create-ovirt-network
new file mode 100755
index 0000000..00b56ba
--- /dev/null
+++ b/create-ovirt-network
@@ -0,0 +1,141 @@
+#!/bin/bash
+
+. $(dirname $0)/ovirt-appliance-functions
+
+usage() {
+ case $# in 1) warn "$1"; try_h; exit 1;; esac
+ cat <<EOF
+Usage: $ME [-e eth]
+ -e: ethernet device to use as bridge (i.e. eth1)
+ -h: display this help and exit
+EOF
+}
+
+err=0 help=0
+bridge=
+while getopts :e:h c; do
+ case $c in
+ e) bridge=$OPTARG;;
+ h) help=1;;
+ '?') err=1; warn "invalid option: \`-$OPTARG'";;
+ :) err=1; warn "missing argument to \`-$OPTARG' option";;
+ *) err=1; warn "internal error: \`-$OPTARG' not handled";;
+ esac
+done
+test $err = 1 && { try_h; exit 1; }
+test $help = 1 && { usage; exit 0; }
+
+do_checks
+
+cleanup_old_nets
+
+net_debug
+
+# If we're bridging to a physical network, run some checks to make sure the
+# choice of physical eth device is sane
+if [ -n "$bridge" ]; then
+ # Check to see if the physical device is present
+ ifconfig $bridge > /dev/null 2>&1 ; bridge_dev_present=$?
+ test $bridge_dev_present != 0 \
+ && die "$bridge device not present, aborting!"
+
+ # Check to see if the eth device is already tied to a non oVirt bridge
+ attached_bridge=$(brctl show \
+ | awk -v BRIDGE=$bridge '$4~BRIDGE {print $1}')
+ test -n "$attached_bridge" -a "$attached_bridge" != "$BRIDGENAME" \
+ && die "$bridge already attached to other bridge $attached_bridge"
+
+ # Check to make sure that the system is not already using the interface
+ if test -f $NET_SCRIPTS/ifcfg-$bridge ; then
+ echo "$NET_SCRIPTS/ifcfg-$bridge is present, are you sure you wish to"
+ echo "overwrite this file? [y/N]? "
+ read yesno
+
+ if [ "$yesno" != "y" -a "$yesno" != "Y" ]; then
+ exit 2
+ fi
+ fi
+fi
+
+# Remove old bridge device if it exists
+sed -i "/# $BRIDGENAME/d" /etc/rc.d/rc.local
+old_bridge=$(brctl show \
+ | awk -v BRIDGENAME=$BRIDGENAME '$1==BRIDGENAME {print $4}')
+if [ -n "$old_bridge" ]; then
+ echo "Removing old bridge $old_bridge"
+ ifconfig $old_bridge down
+ brctl delif $BRIDGENAME $old_bridge
+ rm -f $NET_SCRIPTS/ifcfg-$old_bridge
+fi
+
+{
+echo "Removing $BRIDGENAME"
+virsh net-destroy $BRIDGENAME
+virsh net-undefine $BRIDGENAME
+ifconfig $BRIDGENAME down
+brctl delbr $BRIDGENAME
+rm -fv $NET_SCRIPTS/ifcfg-$BRIDGENAME
+rm -fv /etc/sysconfig/iptables-$BRIDGENAME-filter
+rm -fv /etc/sysconfig/iptables-$BRIDGENAME-nat
+sed -i "/iptables-$BRIDGENAME/d" /etc/sysconfig/system-config-firewall
+lokkit --update
+echo "Done Removing $BRIDGENAME"
+} 2> /dev/null
+
+if [ -n "$bridge" ]; then
+ # real external bridge, use distro networking scripts
+ ifconfig $bridge down 2> /dev/null
+ TMPAUG=$(mktemp) || exit 1
+ cat > $TMPAUG <<EOF
+rm /files$NET_SCRIPTS/ifcfg-$bridge
+set /files$NET_SCRIPTS/ifcfg-$bridge/DEVICE $bridge
+set /files$NET_SCRIPTS/ifcfg-$bridge/ONBOOT yes
+set /files$NET_SCRIPTS/ifcfg-$bridge/BRIDGE $BRIDGENAME
+rm /files$NET_SCRIPTS/ifcfg-$BRIDGENAME
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/DEVICE $BRIDGENAME
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/BOOTPROTO static
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/ONBOOT y
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/TYPE Bridge
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/PEERNTP yes
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/IPADDR ${NETWORK%.*}.1
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/NETMASK $NETMASK
+set /files$NET_SCRIPTS/ifcfg-$BRIDGENAME/DELAY 0
+save
+EOF
+ augtool < $TMPAUG
+ ifup $BRIDGENAME
+ ifup $bridge
+
+ cat > /etc/sysconfig/iptables-$BRIDGENAME-filter <<EOF
+-A FORWARD -m physdev --physdev-is-bridged -j ACCEPT
+-A FORWARD -d $NETWORK/$NETMASK -o $BRIDGENAME -m state --state RELATED,ESTABLISHED -j ACCEPT
+-A FORWARD -s $NETWORK/$NETMASK -i $BRIDGENAME -j ACCEPT
+-A FORWARD -i $BRIDGENAME -o $BRIDGENAME -j ACCEPT
+EOF
+
+ cat > /etc/sysconfig/iptables-$BRIDGENAME-nat <<EOF
+-A POSTROUTING -s $NETWORK/$NETMASK -d ! $NETWORK/$NETMASK -j MASQUERADE
+EOF
+
+ lokkit --custom-rules=ipv4:filter:/etc/sysconfig/iptables-$BRIDGENAME-filter
+ lokkit --custom-rules=ipv4:nat:/etc/sysconfig/iptables-$BRIDGENAME-nat
+else
+ # internal bridge only, use libvirt networking
+ TMPXML=$(mktemp) || exit 1
+ gen_bridge > $TMPXML
+ virsh net-define $TMPXML
+ rm $TMPXML
+ virsh net-start $BRIDGENAME
+ virsh net-autostart $BRIDGENAME
+fi
+
+# Set up dnsmasq on $BRIDGENAME just for DNS forwarding
+cat <<EOF > /etc/dnsmasq.d/$BRIDGENAME.conf
+bind-interfaces
+interface=$BRIDGENAME
+except-interface=lo
+EOF
+chkconfig dnsmasq on
+service dnsmasq restart
+
+net_debug
diff --git a/create-ovirt-nodes b/create-ovirt-nodes
new file mode 100755
index 0000000..0ac5fd0
--- /dev/null
+++ b/create-ovirt-nodes
@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# Create fake oVirt Nodes that PXE boot to the Appliance Server
+# Copyright 2008 Red Hat, Inc.
+# Written by Perry Myers <pmyers at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+. $(dirname $0)/ovirt-appliance-functions
+
+usage() {
+ case $# in 1) warn "$1"; try_h; exit 1;; esac
+ cat <<EOF
+Usage: $ME [-d image_dir]
+ -d: directory to place virtual disk (default: $IMGDIR_DEFAULT)
+ -h: display this help and exit
+EOF
+}
+
+err=0 help=0
+while getopts :dh c; do
+ case $c in
+ d) imgdir=$OPTARG;;
+ h) help=1;;
+ '?') err=1; warn "invalid option: \`-$OPTARG'";;
+ :) err=1; warn "missing argument to \`-$OPTARG' option";;
+ *) err=1; warn "internal error: \`-$OPTARG' not handled";;
+ esac
+done
+test $err = 1 && { try_h; exit 1; }
+test $help = 1 && { usage; exit 0; }
+
+do_checks
+
+mkdir -p $imgdir
+
+# define the fake managed nodes we will use.
+for i in `seq 3 5` ; do
+ gen_fake_managed_node $i
+done
diff --git a/get-ovirt-appliance b/get-ovirt-appliance
new file mode 100755
index 0000000..88b4a49
--- /dev/null
+++ b/get-ovirt-appliance
@@ -0,0 +1,100 @@
+#!/bin/bash
+#
+# Install oVirt Appliance disk images from local directory or from
+# remote URL
+# Copyright 2008 Red Hat, Inc.
+# Written by Perry Myers <pmyers at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+. $(dirname $0)/ovirt-appliance-functions
+
+usage() {
+ case $# in 1) warn "$1"; try_h; exit 1;; esac
+ cat <<EOF
+Usage: $ME [-d image_dir] [-n name] [-l appliance location]
+ -d: directory to place virtual disk (default: $IMGDIR_DEFAULT)
+ -n: appliance name (default: $NAME_DEFAULT)
+ -l: directory or url to get appliance archive and checksum files (default: $OVIRT_URL)
+ this can either be http:// url or relative/absolute path
+ -h: display this help and exit
+EOF
+}
+
+err=0 help=0
+app_loc=$OVIRT_URL
+while getopts :d:n:l:h c; do
+ case $c in
+ d) imgdir=$OPTARG;;
+ n) name=$OPTARG;;
+ l) app_loc=$OPTARG;;
+ h) help=1;;
+ '?') err=1; warn "invalid option: \`-$OPTARG'";;
+ :) err=1; warn "missing argument to \`-$OPTARG' option";;
+ *) err=1; warn "internal error: \`-$OPTARG' not handled";;
+ esac
+done
+test $err = 1 && { try_h; exit 1; }
+test $help = 1 && { usage; exit 0; }
+
+do_checks
+
+pkgfile=$name-$version-$(uname -i).$PKG_FMT
+sumfile=$pkgfile.$SUM
+
+if echo $app_loc | grep "^http://" > /dev/null 2>&1 ; then
+ echo "Using http at $app_loc to retrieve appliance"
+
+ if verify_sum $pkgfile $sumfile ; then
+ app_loc=$(pwd)
+ else
+ wget -c $app_loc/$sumfile || die "error downloading $app_loc/$sumfile"
+ wget -c $app_loc/$pkgfile || die "error downloading $app_loc/$pkgfile"
+ if verify_sum $pkgfile $sumfile ; then
+ app_loc=$(pwd)
+ else
+ die "appliance files not available, aborting"
+ fi
+ fi
+else
+ echo "Using local files in $app_loc for appliance"
+
+ if [ -d $app_loc ]; then
+ if ! verify_sum $app_loc/$pkgfile $app_loc/$sumfile ; then
+ die "appliance files not available, aborting"
+ fi
+ elif [ -f $app_loc -a -f $app_loc.$SUM ]; then
+ if ! verify_sum $app_loc $app_loc.$SUM ; then
+ die "appliance files not available, aborting"
+ fi
+ fi
+fi
+
+mkdir -p $imgdir
+
+appdisk=$name/$name-sda.$DISK_FMT
+datadisk=$name/$name-sdb.$DISK_FMT
+
+# This is the only bit of PKG_FMT that is hardcoded. If we really want to support
+# multiple formats for distribution we should have a case statement here
+tar -xvf $app_loc/$pkgfile -C $imgdir
+
+test ! -r $imgdir/$appdisk && die "Disk image not found at $imgdir/$appdisk"
+test ! -r $imgdir/$datadisk && die "Disk image not found at $imgdir/$datadisk"
+
+virsh destroy $name > /dev/null 2>&1
+virsh undefine $name > /dev/null 2>&1
+
+echo "Appliance Disks installed to $imgdir"
+echo "Run create-ovirt-appliance to define and start the appliance"
diff --git a/ovirt-appliance-functions b/ovirt-appliance-functions
new file mode 100644
index 0000000..a81660e
--- /dev/null
+++ b/ovirt-appliance-functions
@@ -0,0 +1,180 @@
+# -*-Shell-script-*-
+#
+# Common functions for the oVirt Appliance scripts
+# Copyright 2008 Red Hat, Inc.
+# Written by Perry Myers <pmyers at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+PATH=$PATH:/sbin:/usr/sbin
+
+ME=$(basename "$0")
+warn() { printf '%s: %s\n' "$ME" "$*" >&2; }
+try_h() { printf "Try \`$ME -h' for more information.\n" >&2; }
+die() { warn "$@"; try_h; exit 1; }
+
+IMGDIR_DEFAULT=/var/lib/libvirt/images
+NAME_DEFAULT=ovirt-appliance
+NET_SCRIPTS=/etc/sysconfig/network-scripts
+
+BRIDGENAME=ovirtbr0
+NETWORK=192.168.50.0
+NETMASK=255.255.255.0
+
+PKG_FMT=tar
+SUM=sha1sum
+
+DISK_FMT=qcow2
+OVIRT_URL=http://ovirt.org/download
+
+NODE_DISK_FMT=qcow2
+NODE_DISK_SIZE=128M
+
+imgdir=$IMGDIR_DEFAULT
+name=$NAME_DEFAULT
+
+do_checks() {
+ # first, check to see we are root
+ if [ $( id -u ) -ne 0 ]; then
+ die "Must run as root"
+ fi
+
+ # now make sure the packages we need are installed
+ if [ -e /etc/redhat-release ]; then
+ # We rely on RPM deps for this in Red Hat/Fedora systems
+ CHECK=0
+ KVM_BINARY=/usr/bin/qemu-kvm
+ version=$(rpm -q --qf '%{version}' ovirt-appliance)
+ elif [ -e /etc/debian_version ]; then
+ # Works in Ubuntu 8.04. Still needs testing in Debian
+ PACKAGES="libvirt0 libvirt-bin kvm qemu"
+ CHECK=$(dpkg -l $PACKAGES &> /dev/null; echo $?)
+ KVM_BINARY=/usr/bin/kvm
+ version=LATEST
+ else
+ die "Not a supported system"
+ fi
+
+ if [ $CHECK -ne 0 ]; then
+ # one of the previous packages wasn't installed; bail out
+ die "Must have the $PACKAGES packages installed"
+ fi
+
+ service NetworkManager status > /dev/null 2>&1 \
+ && die "NetworkManager is running, disable and use standard network scripts before proceeding"
+
+ service iptables status > /dev/null 2>&1 \
+ || service iptables start > /dev/null 2>&1
+ chkconfig iptables on
+
+ service libvirtd status > /dev/null 2>&1 \
+ || service libvirtd start > /dev/null 2>&1
+ chkconfig libvirtd on
+}
+
+gen_bridge() {
+ cat << EOF
+<network>
+ <name>$BRIDGENAME</name>
+ <bridge name="$BRIDGENAME" stp="off" forwardDelay="0" />
+ <forward/>
+ <ip address="${NETWORK%.*}.1" netmask="$NETMASK"/>
+</network>
+EOF
+}
+
+gen_fake_managed_node() {
+ local num=$1
+ local last_mac=$(( 54 + $num ))
+
+ echo "Creating fake node$num..."
+ virsh destroy node$num > /dev/null 2>&1
+ virsh undefine node$num > /dev/null 2>&1
+ rm -f $imgdir/node${i}-sda.$NODE_DISK_FMT
+ qemu-img create -f $NODE_DISK_FMT $imgdir/node${i}-sda.$NODE_DISK_FMT \
+ $NODE_DISK_SIZE
+ # FIXME: virt-install should be changed to have a --nostart parameter
+ # that just defines the VM w/o starting it.
+ virt-install --name=node$num --ram=512 --vcpus=1 \
+ --disk path=$imgdir/node${i}-sda.$NODE_DISK_FMT \
+ --network=bridge:$BRIDGENAME --mac=00:16:3e:12:34:$last_mac \
+ --vnc --accelerate --hvm --noautoconsole \
+ --os-type=linux --os-variant=fedora9 \
+ --force --noreboot --pxe
+ virsh destroy node$num > /dev/null 2>&1
+ # FIXME: virt-install should be changed to allow network boot
+ # to be a permanent selection
+ TMPXML=$(mktemp) || exit 1
+ virsh dumpxml node$num | sed "s/boot dev='.*'/boot dev='network'/" > $TMPXML
+ virsh define $TMPXML
+ rm -f $TMPXML
+ echo "node$num created"
+}
+
+net_debug() {
+ # Some output for debugging problems
+ echo "Currently active bridges:"
+ echo "-------------------------"
+ brctl show
+ echo
+ echo "Currently defined libvirt networks:"
+ echo "-----------------------------------"
+ virsh net-list --all
+ echo
+}
+
+cleanup_old_apps() {
+ # Cleanup to handle older version of script that used these domain names
+ virsh destroy developer
+ virsh undefine developer
+ virsh destroy bundled
+ virsh undefine bundled
+} > /dev/null 2>&1
+
+cleanup_old_nets() {
+ # Cleanup to handle older version of script that used these bridge names
+ virsh net-destroy dummybridge
+ virsh net-undefine dummybridge
+ brctl delif eth1bridge eth1
+ virsh net-destroy eth1bridge
+ virsh net-undefine eth1bridge
+ old_bridge=$(brctl show \
+ | awk -v BRIDGENAME=ovirtbr '$1==BRIDGENAME {print $4}')
+ if [ -n "$old_bridge" ]; then
+ ifconfig $old_bridge down
+ fi
+ brctl delif ovirtbr $old_bridge
+ virsh net-destroy ovirtbr
+ virsh net-undefine ovirtbr
+ sed -i "/# ovirtbr$/d" /etc/rc.d/rc.local
+} > /dev/null 2>&1
+
+verify_sum() {
+ local pkgfile=$1
+ local sumfile=$2
+
+ test ! -f $sumfile && { echo "$sumfile not found" ; return 1 ; }
+ test ! -f $pkgfile && { echo "$pkgfile not found" ; return 1 ; }
+
+ local actual_sum=$($SUM $pkgfile | awk '{print $1}')
+ local expect_sum=$(awk '{print $1}' $sumfile)
+
+ if [ "$actual_sum" = "$expect_sum" ]; then
+ echo "checksum verified"
+ return 0
+ else
+ echo "checksum failed"
+ return 1
+ fi
+}
diff --git a/ovirt-appliance.ks b/ovirt-appliance.ks
index 69286fb..8fabdb7 100644
--- a/ovirt-appliance.ks
+++ b/ovirt-appliance.ks
@@ -2,7 +2,7 @@ install
lang en_US.UTF-8
keyboard us
-network --device eth0 --bootproto dhcp
+network --device=eth0 --bootproto=static --ip=192.168.50.2 --netmask=255.255.255.0 --onboot=on --nameserver=192.168.50.2 --hostname=management.priv.ovirt.org
# Root password is 'ovirt'
rootpw --iscrypted Xa8QeYfWrtscM
firewall --disabled
@@ -24,8 +24,6 @@ part swap --ondisk=sda --fstype=swap --size=512
part /mnt/data --ondisk=sdb --fstype=ext3 --size=20000
reboot
-network --device=eth1 --bootproto=static --ip=192.168.50.2 --netmask=255.255.255.0 --onboot=on --nameserver=192.168.50.2 --hostname=management.priv.ovirt.org
-
%include repos.ks
%packages --nobase
diff --git a/ovirt-appliance.spec.in b/ovirt-appliance.spec.in
index c35530b..191fc2d 100644
--- a/ovirt-appliance.spec.in
+++ b/ovirt-appliance.spec.in
@@ -37,6 +37,10 @@ mkdir %{buildroot}
%{__install} -p -m0644 COPYING %{buildroot}%{app_root}
%{__install} -d -m0755 %{buildroot}%{_sbindir}
%{__install} -p -m0755 create-%{name} %{buildroot}%{_sbindir}
+%{__install} -p -m0755 create-ovirt-network %{buildroot}%{_sbindir}
+%{__install} -p -m0755 create-ovirt-nodes %{buildroot}%{_sbindir}
+%{__install} -p -m0755 get-%{name} %{buildroot}%{_sbindir}
+%{__install} -p -m0644 %{name}-functions %{buildroot}%{_sbindir}
%clean
%{__rm} -rf %{buildroot}
@@ -46,6 +50,11 @@ mkdir %{buildroot}
%{app_root}/COPYING
%defattr(-,root,root,0755)
%{_sbindir}/create-%{name}
+%{_sbindir}/create-ovirt-network
+%{_sbindir}/create-ovirt-nodes
+%{_sbindir}/get-%{name}
+%defattr(-,root,root,0644)
+%{_sbindir}/%{name}-functions
%changelog
* Wed Nov 05 2008 Perry Myers <pmyers at redhat.com> 0.96
--
1.6.0.3
More information about the ovirt-devel
mailing list