[Ovirt-devel] [PATCH appliance] create real ovirtbr0 bridge for -e <eth bridge>
Perry Myers
pmyers at redhat.com
Thu Oct 16 04:25:44 UTC 2008
From: Alan Pevec <apevec at redhat.com>
NOTE: distro specific networking scripts are used
Signed-off-by: Alan Pevec <apevec at redhat.com>
Signed-off-by: Perry Myers <pmyers at redhat.com>
---
create-ovirt-appliance | 119 +++++++++++++++++++++++++++-------------------
ovirt-appliance.spec.in | 1 +
2 files changed, 71 insertions(+), 49 deletions(-)
diff --git a/create-ovirt-appliance b/create-ovirt-appliance
index 88d0188..9454377 100755
--- a/create-ovirt-appliance
+++ b/create-ovirt-appliance
@@ -13,6 +13,7 @@ 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
@@ -84,9 +85,9 @@ gen_fake_managed_node() {
<source file='$disk'/>
<target dev='hda'/>
</disk>
- <interface type='network'>
+ <interface type='$NET_TYPE'>
<mac address='00:16:3e:12:34:$last_mac'/>
- <source network='$BRIDGENAME'/>
+ <source $NET_TYPE='$BRIDGENAME'/>
</interface>
<serial type='pty'>
<target port='0'/>
@@ -130,8 +131,8 @@ gen_app() {
<source network='default'/>
<model type='virtio'/>
</interface>
- <interface type='network'>
- <source network='$BRIDGENAME'/>
+ <interface type='$NET_TYPE'>
+ <source $NET_TYPE='$BRIDGENAME'/>
<model type='virtio'/>
</interface>
<serial type='pty'>
@@ -147,6 +148,18 @@ gen_app() {
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"
@@ -193,33 +206,33 @@ chkconfig libvirtd on
sed -i "/# ovirtbr$/d" /etc/rc.d/rc.local
} > /dev/null 2>&1
-# Some output for debugging problems
-brctl show
-virsh net-list
+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 make sure that the system is not already using the interface
- test -f $NET_SCRIPTS/ifcfg-$bridge \
- && die "$bridge defined in $NET_SCRIPTS, 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 see if the eth device does not have an active inet address
- ip address show dev $bridge \
- | grep "inet.*$bridge" > /dev/null 2>&1 ; bridge_dev_active=$?
- test $bridge_dev_active == 0 \
- && die "$bridge device active with ip address, aborting!"
+ # 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
mkdir -p $imgdir
@@ -238,16 +251,6 @@ for i in `seq 3 5` ; do
rm $TMPXML
done
-virsh net-dumpxml $BRIDGENAME >& /dev/null
-RETVAL=$?
-if [ $( brctl show | grep -c $BRIDGENAME ) -ne 0 -a $RETVAL -ne 0 ]; then
- # in this case, the bridge exists, but isn't managed by libvirt
- # abort, since the user will have to clean up themselves
- echo "Bridge $BRIDGENAME already exists. Please make sure you"
- echo "unconfigure $BRIDGENAME, and then try the command again"
- exit 1
-fi
-
# Remove old bridge device if it exists
sed -i "/# $BRIDGENAME/d" /etc/rc.d/rc.local
old_bridge=$(brctl show \
@@ -256,36 +259,54 @@ 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
-virsh net-destroy $BRIDGENAME > /dev/null 2>&1
-virsh net-undefine $BRIDGENAME > /dev/null 2>&1
-TMPXML=$(mktemp) || exit 1
-gen_bridge $BRIDGENAME > $TMPXML
-virsh net-define $TMPXML
-rm $TMPXML
-virsh net-start $BRIDGENAME
-virsh net-autostart $BRIDGENAME
+{
+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
- # FIXME: unfortunately, these two can't be done by libvirt at the
- # moment, so we do them by hand here and persist the config by
- # by adding to rc.local
- echo "Adding new bridge $bridge"
- TMPBRCTL=$(mktemp) || exit 1
- cat > $TMPBRCTL << EOF
-brctl setfd $BRIDGENAME 0 # $BRIDGENAME
-brctl addif $BRIDGENAME $bridge # $BRIDGENAME
-ifconfig $bridge up # $BRIDGENAME
+ # 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
- chmod a+x $TMPBRCTL /etc/rc.d/rc.local
-
- cat $TMPBRCTL >> /etc/rc.d/rc.local
-
- $TMPBRCTL
- rm $TMPBRCTL
+ 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
+
# Cleanup to handle older version of script that used these domain names
{
virsh destroy developer
diff --git a/ovirt-appliance.spec.in b/ovirt-appliance.spec.in
index d96e7bf..f42982d 100644
--- a/ovirt-appliance.spec.in
+++ b/ovirt-appliance.spec.in
@@ -27,6 +27,7 @@ BuildRequires: wget
Requires: libvirt >= 0.4.4-2ovirt2
Requires: kvm >= 72-3ovirt3
Requires: /usr/bin/qemu-img
+Requires: augeas
%define app_root %{_datadir}/%{name}
--
1.5.5.1
More information about the ovirt-devel
mailing list