Created
July 19, 2013 04:16
-
-
Save joestringer/6035189 to your computer and use it in GitHub Desktop.
Script to compile, copy and (re)install OVS from local sources to a remote host. Kernel versions on both hosts must be identical.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
OVSDIR=/tmp/ovstest | |
MODDIR=$OVSDIR/lib/modules/`uname -r`/extra | |
OVSTAR=$OVSDIR.tar | |
OVSSCRIPT=ovstest.sh | |
USER=root | |
HOST=192.168.122.28 | |
REMOTE=$USER@$HOST | |
setup_keys() { | |
ssh $REMOTE "mkdir -p /$USER/.ssh" | |
scp ~/.ssh/id_rsa.pub $REMOTE:/$USER/.ssh/authorized_keys | |
eval `ssh-agent` | |
ssh-add ~/.ssh/id_rsa | |
} | |
create_script() { | |
cat <<EOF > $OVSDIR/$OVSSCRIPT | |
#!/bin/bash | |
if [ -f /$OVSSCRIPT ]; then | |
rmmod openvswitch 2>/dev/null | |
killall ovsdb-server ovs-vswitchd 2>/dev/null | |
else | |
mkdir -p /usr/local/etc/openvswitch | |
mkdir -p //usr/local/var/run/openvswitch | |
ovsdb-tool create /usr/local/etc/openvswitch/conf.db \ | |
/usr/local/share/openvswitch/vswitch.ovsschema | |
fi | |
depmod -a | |
modprobe openvswitch | |
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \ | |
--remote=db:Open_vSwitch,Open_vSwitch,manager_options \ | |
--private-key=db:Open_vSwitch,SSL,private_key \ | |
--certificate=db:Open_vSwitch,SSL,certificate \ | |
--bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \ | |
--pidfile --detach | |
if [ ! -f /$OVSSCRIPT ]; then | |
ovs-vsctl --no-wait init | |
ovs-vsctl add-br br0 | |
ovs-vsctl add-port br0 eth0 | |
fi | |
ovs-vswitchd --pidfile --detach | |
ovs-vsctl set-controller br0 ptcp:6633 | |
ip addr del dev eth0 $HOST/24 | |
ip addr add dev br0 $HOST/24 | |
EOF | |
} | |
vm_install() { | |
echo "Creating Open vSwitch tarball" | |
make install DESTDIR=$OVSDIR >/dev/null | |
mkdir -p $MODDIR | |
cp datapath/linux/openvswitch.ko $MODDIR | |
tar -cf $OVSTAR -C $OVSDIR lib usr $OVSSCRIPT | |
scp $OVSTAR $REMOTE:$OVSTAR | |
ssh $REMOTE "cd /; tar -xf $OVSTAR" | |
} | |
main() { | |
if [ $# -gt 2 ]; then | |
USER=$1 | |
HOST=$2 | |
REMOTE=$1@$2 | |
fi | |
ping -c 1 $HOST >/dev/null | |
if [ $? -ne 0 ]; then | |
echo "Couldn't connect to $HOST." | |
exit | |
fi | |
create_script | |
vm_install | |
ssh $REMOTE "sh /$OVSSCRIPT" | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment