Created
April 15, 2018 22:58
-
-
Save johnsom/7a7d14a8de8ea2be91b70fbda391cf1e to your computer and use it in GitHub Desktop.
createlb.sh
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 | |
function wait_for_lb_active { | |
echo "Waiting for $1 to become ACTIVE..." | |
status=$(openstack loadbalancer show $1 | awk '/provisioning_status/ {print $4}') | |
while [ "$status" != "ACTIVE" ] | |
do | |
sleep 1 | |
status=$(openstack loadbalancer show $1 | awk '/provisioning_status/ {print $4}') | |
if [ $status == "ERROR" ] | |
then | |
echo "$1 ERRORED. Exiting." | |
exit 1; | |
fi | |
done | |
} | |
webserver1ip=$(nova show webserver1 | awk '/ network/ {gsub(/,$/, "", $5); a = $5; if (a ~ "\\.") print a; else print $6}') | |
webserver2ip=$(nova show webserver2 | awk '/ network/ {gsub(/,$/, "", $5); a = $5; if (a ~ "\\.") print a; else print $6}') | |
openstack loadbalancer create --name lb1 --vip-subnet-id private-subnet | |
wait_for_lb_active "lb1" | |
openstack loadbalancer listener create --name listener1 --protocol HTTP --protocol-port 80 lb1 | |
wait_for_lb_active "lb1" | |
openstack loadbalancer pool create --name pool1 --lb-algorithm ROUND_ROBIN --listener listener1 --protocol HTTP # --session-persistence type=SOURCE_IP | |
wait_for_lb_active "lb1" | |
openstack loadbalancer healthmonitor create --delay 5 --timeout 2 --max-retries 1 --type HTTP pool1 | |
wait_for_lb_active "lb1" | |
openstack loadbalancer member create --subnet-id tenant-1-subnet --address $webserver1ip --protocol-port 80 pool1 | |
wait_for_lb_active "lb1" | |
openstack loadbalancer member create --subnet-id tenant-2-subnet --address $webserver2ip --protocol-port 80 pool1 | |
wait_for_lb_active "lb1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment