github.com/arkadijs/deis@v1.5.1/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 # DEIS_NETWORK: name of neutron network to use. 9 10 set -e 11 12 THIS_DIR=$(cd $(dirname $0); pwd) # absolute path 13 CONTRIB_DIR=$(dirname $THIS_DIR) 14 DEIS_NETWORK=${DEIS_NETWORK:-deis} 15 DEIS_SECGROUP=${DEIS_SECGROUP:-deis} 16 17 source $CONTRIB_DIR/utils.sh 18 19 if [ -z "$2" ]; then 20 echo_red 'Usage: provision-openstack-cluster.sh <coreos image name/id> <key pair name> [flavor]' 21 exit 1 22 fi 23 COREOS_IMAGE=$1 24 KEYPAIR=$2 25 26 if ! which nova > /dev/null; then 27 echo_red 'Please install nova and ensure it is in your $PATH.' 28 exit 1 29 fi 30 31 if ! which neutron > /dev/null; then 32 echo_red 'Please install neutron and ensure it is in your $PATH.' 33 exit 1 34 fi 35 36 if [ -z "$3" ]; then 37 FLAVOR="m1.large" 38 else 39 FLAVOR=$3 40 fi 41 42 if [ -z "$OS_AUTH_URL" ]; then 43 echo_red "nova credentials are not set. Please source openrc.sh" 44 exit 1 45 fi 46 47 if neutron net-list|grep -q $DEIS_NETWORK &>/dev/null; then 48 NETWORK_ID=$(neutron net-list | grep internal | awk -F'| ' '{print $2}') 49 else 50 echo_yellow "Creating deis private network..." 51 CIDR=${DEIS_CIDR:-10.21.12.0/24} 52 SUBNET_OPTIONS="" 53 [ ! -z "$DEIS_DNS" ] && SUBNET_OPTIONS=$(echo $DEIS_DNS|awk -F "," '{for (i=1; i<=NF; i++) printf "--dns-nameserver %s ", $i}') 54 NETWORK_ID=$(neutron net-create $DEIS_NETWORK | awk '{ printf "%s", ($2 == "id" ? $4 : "")}') 55 echo "DBG: SUBNET_OPTIONS=$SUBNET_OPTIONS" 56 SUBNET_ID=$(neutron subnet-create --name deis_subnet $SUBNET_OPTIONS $NETWORK_ID $CIDR| awk '{ printf "%s", ($2 == "id" ? $4 : "")}') 57 fi 58 59 if ! neutron security-group-list | grep -q $DEIS_SECGROUP &>/dev/null; then 60 neutron security-group-create $DEIS_SECGROUP 61 neutron security-group-rule-create --protocol tcp --remote-ip-prefix 0/0 --port-range-min 22 --port-range-max 22 $DEIS_SECGROUP 62 neutron security-group-rule-create --protocol tcp --remote-ip-prefix 0/0 --port-range-min 2222 --port-range-max 22222 $DEIS_SECGROUP 63 neutron security-group-rule-create --protocol tcp --remote-ip-prefix 0/0 --port-range-min 80 --port-range-max 80 $DEIS_SECGROUP 64 neutron security-group-rule-create --protocol icmp --remote-ip-prefix 0/0 $DEIS_SECGROUP 65 fi 66 67 if [ -z "$DEIS_NUM_INSTANCES" ]; then 68 DEIS_NUM_INSTANCES=3 69 fi 70 71 # check that the CoreOS user-data file is valid 72 $CONTRIB_DIR/util/check-user-data.sh 73 74 i=1 ; while [[ $i -le $DEIS_NUM_INSTANCES ]] ; do \ 75 echo_yellow "Provisioning deis-$i..." 76 nova boot --image $COREOS_IMAGE --flavor $FLAVOR --key-name $KEYPAIR \ 77 --security-groups $DEIS_SECGROUP --user-data ../coreos/user-data \ 78 --nic net-id=$NETWORK_ID deis-$i ; \ 79 ((i = i + 1)) ; \ 80 done 81 82 echo_green "Your Deis cluster has successfully deployed to OpenStack." 83 echo_green "Please continue to follow the instructions in the README."