github.com/inflatablewoman/deis@v1.0.1-0.20141111034523-a4511c46a6ce/contrib/openstack/provision-openstack-cluster.sh (about) 1 #!/usr/bin/env bash 2 # 3 # Usage: ./provision-openstack-cluster.sh <key pair name> [flavor] 4 # 5 # Supported environment variables: 6 # DEIS_DNS: Comma separated list of names servers for use in the deis private network (default: none) 7 # DEIS_NUM_INSTANCES: Number of instances to create (default: 3) 8 9 set -e 10 11 THIS_DIR=$(cd $(dirname $0); pwd) # absolute path 12 CONTRIB_DIR=$(dirname $THIS_DIR) 13 14 source $CONTRIB_DIR/utils.sh 15 16 if [ -z "$2" ]; then 17 echo_red 'Usage: provision-openstack-cluster.sh <coreos image name/id> <key pair name> [flavor]' 18 exit 1 19 fi 20 COREOS_IMAGE=$1 21 KEYPAIR=$2 22 23 if ! which nova > /dev/null; then 24 echo_red 'Please install nova and ensure it is in your $PATH.' 25 exit 1 26 fi 27 28 if ! which neutron > /dev/null; then 29 echo_red 'Please install neutron and ensure it is in your $PATH.' 30 exit 1 31 fi 32 33 if [ -z "$3" ]; then 34 FLAVOR="m1.large" 35 else 36 FLAVOR=$3 37 fi 38 39 if [ -z "$OS_AUTH_URL" ]; then 40 echo_red "nova credentials are not set. Please source openrc.sh" 41 exit 1 42 fi 43 44 if ! nova network-list|grep -q deis &>/dev/null; then 45 echo_yellow "Creating deis private network..." 46 CIDR=${DEIS_CIDR:-10.21.12.0/24} 47 SUBNET_OPTIONS="" 48 [ ! -z "$DEIS_DNS" ] && SUBNET_OPTIONS=$(echo $DEIS_DNS|awk -F "," '{for (i=1; i<=NF; i++) printf "--dns-nameserver %s ", $i}') 49 NETWORK_ID=$(neutron net-create deis | awk '{ printf "%s", ($2 == "id" ? $4 : "")}') 50 echo "DBG: SUBNET_OPTIONS=$SUBNET_OPTIONS" 51 SUBNET_ID=$(neutron subnet-create --name deis_subnet $SUBNET_OPTIONS deis $CIDR| awk '{ printf "%s", ($2 == "id" ? $4 : "")}') 52 else 53 NETWORK_ID=$(neutron net-list | awk '{printf "%s", ($4 == "deis" ? $2 : "")}') 54 fi 55 56 57 if [ -z "$DEIS_NUM_INSTANCES" ]; then 58 DEIS_NUM_INSTANCES=3 59 fi 60 61 # check that the CoreOS user-data file is valid 62 $CONTRIB_DIR/util/check-user-data.sh 63 64 i=1 ; while [[ $i -le $DEIS_NUM_INSTANCES ]] ; do \ 65 echo_yellow "Provisioning deis-$i..." 66 nova boot --image $COREOS_IMAGE --flavor $FLAVOR --key-name $KEYPAIR --user-data ../coreos/user-data --nic net-id=$NETWORK_ID deis-$i ; \ 67 ((i = i + 1)) ; \ 68 done 69 70 echo_green "Your Deis cluster has successfully deployed to OpenStack." 71 echo_green "Please continue to follow the instructions in the README."