diff options
author | 2015-08-13 08:26:05 +0000 | |
---|---|---|
committer | 2015-08-13 08:26:05 +0000 | |
commit | ade17ce57eb08dbf262cb9b6f1893367e2832dc1 (patch) | |
tree | 3f6c489086ca0f002f15114e71f4d64d1564f2b8 /deploy/network.sh | |
parent | 7951b094df92c40417ec66c4be58871911bbed07 (diff) | |
parent | 10e776642a16b2584be88e5be8740f05535d7d06 (diff) |
Merge "Add deploy scripts for compass"
Diffstat (limited to 'deploy/network.sh')
-rwxr-xr-x | deploy/network.sh | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/deploy/network.sh b/deploy/network.sh new file mode 100755 index 00000000..851a685a --- /dev/null +++ b/deploy/network.sh @@ -0,0 +1,70 @@ +function destroy_nets() { + sudo virsh net-destroy mgmt > /dev/null 2>&1 + sudo virsh net-undefine mgmt > /dev/null 2>&1 + + sudo virsh net-destroy install > /dev/null 2>&1 + sudo virsh net-undefine install > /dev/null 2>&1 + rm -rf $COMPASS_DIR/deploy/work/network/*.xml +} + +function setup_om_bridge() { + local device=$1 + local gw=$2 + ip link set br_install down + ip addr flush $device + brctl delbr br_install + + brctl addbr br_install + brctl addif br_install $device + ip link set br_install up + + shift;shift + for ip in $*;do + ip addr add $ip dev br_install + done + + route add default gw $gw +} + +function setup_om_nat() { + # create install network + sed -e "s/REPLACE_BRIDGE/br_install/g" \ + -e "s/REPLACE_NAME/install/g" \ + -e "s/REPLACE_GATEWAY/$INSTALL_GW/g" \ + -e "s/REPLACE_MASK/$INSTALL_MASK/g" \ + -e "s/REPLACE_START/$INSTALL_IP_START/g" \ + -e "s/REPLACE_END/$INSTALL_IP_END/g" \ + $COMPASS_DIR/deploy/template/network/nat.xml \ + > $WORK_DIR/network/install.xml + + sudo virsh net-define $WORK_DIR/network/install.xml + sudo virsh net-start install +} + +function create_nets() { + destroy_nets + + # create mgmt network + sed -e "s/REPLACE_BRIDGE/br_mgmt/g" \ + -e "s/REPLACE_NAME/mgmt/g" \ + -e "s/REPLACE_GATEWAY/$MGMT_GW/g" \ + -e "s/REPLACE_MASK/$MGMT_MASK/g" \ + -e "s/REPLACE_START/$MGMT_IP_START/g" \ + -e "s/REPLACE_END/$MGMT_IP_END/g" \ + $COMPASS_DIR/deploy/template/network/nat.xml \ + > $WORK_DIR/network/mgmt.xml + + sudo virsh net-define $WORK_DIR/network/mgmt.xml + sudo virsh net-start mgmt + + # create install network + if [[ ! -z $VIRT_NUMBER ]];then + setup_om_nat + else + mask=`echo $INSTALL_MASK | awk -F'.' '{print ($1*(2^24)+$2*(2^16)+$3*(2^8)+$4)}'` + mask_len=`echo "obase=2;${mask}"|bc|awk -F'0' '{print length($1)}'` + setup_om_bridge $OM_NIC $OM_GW $INSTALL_GW/$mask_len $OM_IP + fi + +} + |