//
you're reading...
Bash Scripts, Centos, Code, KVM, Open vSwitch, OpenStack, Systems

Open vSwitch init script for KVM/OpenStack

This is a script I use to setup Open vSwitch bridges for OpenStack on KVM.

#!/bin/bash
#
#    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, either version 3 of the License, or
#    (at your option) any later version.
#
#    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 General Public License for more details.
#
#    <http://www.gnu.org/licenses/>.
#
# ovs bridge script
#
# chkconfig: 2345 09 91
# description: Manage Open vSwitch Bridges
# Script used to add/remove setup of private, management, and external bridges

VMIPS="/etc/sysconfig/ovsbs"
IFCFG="/etc/sysconfig/network-scripts/ifcfg"
INT_NIC="eth1"
OMG_NIC="eth2"
EX_NIC="eth3"

add_br()
{
    if [ -e "${IFCFG}-br-int" ] && [ ! -z "$INT_NIC" ]; then
        echo "Adding Integration Bridge"
        ovs-vsctl add-br br-int
        ovs-vsctl add-port br-int $INT_NIC
        echo 1 > /proc/sys/net/ipv6/conf/br-int/disable_ipv6
        ifup br-int up
    fi

    if [ -e "${IFCFG}-br-omg" ] && [ ! -z "$OMG_NIC" ]; then
        echo "Adding Management Bridge"
        ovs-vsctl add-br br-omg
        ovs-vsctl add-port br-omg $OMG_NIC
        echo 1 > /proc/sys/net/ipv6/conf/br-omg/disable_ipv6
        ifup br-omg up
    fi

    if [ -e "${IFCFG}-br-ex" ] && [ ! -z "$EX_NIC" ]; then
        echo "Adding External Bridge"
        ovs-vsctl add-br br-ex
        ovs-vsctl add-port br-ex $EX_NIC
        echo 1 > /proc/sys/net/ipv6/conf/br-omg/disable_ipv6
        ifup br-ex up
    fi

    #ovs−vsctl set Bridge $brname stp_enable=true
}

del_br()
{
    echo "Removing Bridges"
    for br in `ovs-vsctl list-br`; do
        ifconfig $br down
        ovs-vsctl del-br $br
    done

    echo "Removing TAPs"
    for tap in `ifconfig -a |grep tap|awk '{print $1}'`; do
        ip link delete $tap
    done
}

case $1 in
    start)
        add_br
        ;;
    stop)
        del_br
        ;;
    restart)
        del_br
        add_br
        ;;
    status)
        ovs-vsctl show
        ;;
    *)
        printf "$0 [start|stop|status]\n"
        exit 1
        ;;
esac

You will still need the normal Open vSwitch init script to load the kernel modules and the ifcfg scripts to setup the interfaces.

This script should be run before the VM’s are started or the vnet’s won’t connect to the ovsbr interfaces.

Stopping the script also removes the TAP devices created by OpenStack.

Advertisements

Discussion

3 thoughts on “Open vSwitch init script for KVM/OpenStack

  1. Looks like you have a cut and paste error in the code segment for br-ex. You start br-omg instead of br-ex.

    Posted by Rick Minton | May 6, 2013, 6:47 am
  2. Thanks, I corrected it, since I don’t use openstack anymore I guess I never noticed it.

    Posted by koaps | May 8, 2013, 2:13 pm

Trackbacks/Pingbacks

  1. Pingback: KVM and OpenVSwitch on Centos 6.3 Minimal « Nullworks - September 27, 2012

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s