Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **setup-network** |
| 4 | |
| 5 | # Setups openvswitch libvirt network suitable for |
| 6 | # running baremetal poseur nodes for ironic testing purposes |
| 7 | |
| 8 | set -exu |
| 9 | |
Adam Gandelman | bd93f02 | 2014-03-17 16:31:49 -0700 | [diff] [blame] | 10 | LIBVIRT_CONNECT_URI=${LIBVIRT_CONNECT_URI:-"qemu:///system"} |
| 11 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 12 | # Keep track of the DevStack directory |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 13 | TOP_DIR=$(cd $(dirname "$0")/.. && pwd) |
| 14 | BRIDGE_SUFFIX=${1:-''} |
| 15 | BRIDGE_NAME=brbm$BRIDGE_SUFFIX |
| 16 | |
Adam Gandelman | bd93f02 | 2014-03-17 16:31:49 -0700 | [diff] [blame] | 17 | export VIRSH_DEFAULT_CONNECT_URI="$LIBVIRT_CONNECT_URI" |
| 18 | |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 19 | # Only add bridge if missing |
| 20 | (sudo ovs-vsctl list-br | grep ${BRIDGE_NAME}$) || sudo ovs-vsctl add-br ${BRIDGE_NAME} |
| 21 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 22 | # Remove bridge before replacing it. |
Alexander Gordeev | 06fb29c | 2014-01-31 18:02:07 +0400 | [diff] [blame] | 23 | (virsh net-list | grep "${BRIDGE_NAME} ") && virsh net-destroy ${BRIDGE_NAME} |
| 24 | (virsh net-list --inactive | grep "${BRIDGE_NAME} ") && virsh net-undefine ${BRIDGE_NAME} |
| 25 | |
| 26 | virsh net-define <(sed s/brbm/$BRIDGE_NAME/ $TOP_DIR/templates/brbm.xml) |
| 27 | virsh net-autostart ${BRIDGE_NAME} |
| 28 | virsh net-start ${BRIDGE_NAME} |