tools/deployment/libvirt/setup_network.sh
Dean Troyer bd4b59dde2 Clean up the libvirt install bits
* Split the network setup/teardown bits into their own scripts
  so you can shoot yourself in the foot with intention
  rather then unexpectedly.
* Cowardly refuse to configure a network if the first interface name exists
* Change the default bridge name to stxbr
* Make the network variables all configurable via the environment
* Don't make assumptions about where ISOIMAGE is located
* Include a basic doc that outlines the differences from existing
  installation steps. (Needs more!)

Change-Id: Ic46c03a09da97765b9f6bfe07e089efa38738993
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2018-08-30 10:40:57 -05:00

41 lines
989 B
Bash
Executable File

#!/usr/bin/env bash
usage() {
echo "$0 [-h]"
echo ""
echo "Options:"
# echo " -i: StarlingX ISO image"
echo ""
}
while getopts "i:" o; do
case "${o}" in
*)
usage
exit 1
;;
esac
done
shift $((OPTIND-1))
BRIDGE_INTERFACE=${BRIDGE_INTERFACE:-stxbr}
INTERNAL_NETWORK=${INTERNAL_NETWORK:-10.10.10.0/24}
INTERNAL_IP=${INTERNAL_IP:-10.10.10.1/24}
EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-192.168.204.0/24}
EXTERNAL_IP=${EXTERNAL_IP:-192.168.204.1/24}
if [[ -r /sys/class/net/${BRIDGE_INTERFACE}1 ]]; then
echo "${BRIDGE_INTERFACE}1 exists, cowardly refusing to overwrite it, exiting..."
exit 1
fi
for i in {1..4}; do
sudo brctl addbr ${BRIDGE_INTERFACE}$i
done
sudo ifconfig ${BRIDGE_INTERFACE}1 $INTERNAL_IP up
sudo ifconfig ${BRIDGE_INTERFACE}2 $EXTERNAL_IP up
sudo ifconfig ${BRIDGE_INTERFACE}3 up
sudo ifconfig ${BRIDGE_INTERFACE}4 up
sudo iptables -t nat -A POSTROUTING -s $EXTERNAL_NETWORK -j MASQUERADE