github.com/greenboxal/deis@v1.12.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 $DEIS_NETWORK | awk -F'|' '{gsub(/ /, "", $0); 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 # Allow SSH from anywhere. 62 neutron security-group-rule-create --protocol tcp --remote-ip-prefix 0/0 --port-range-min 22 --port-range-max 22 $DEIS_SECGROUP 63 # Allow git push from anywhere 64 neutron security-group-rule-create --protocol tcp --remote-ip-prefix 0/0 --port-range-min 2222 --port-range-max 2222 $DEIS_SECGROUP 65 # allow web from anywhere 66 neutron security-group-rule-create --protocol tcp --remote-ip-prefix 0/0 --port-range-min 80 --port-range-max 80 $DEIS_SECGROUP 67 # allow ping from anywhere. 68 neutron security-group-rule-create --protocol icmp --remote-ip-prefix 0/0 $DEIS_SECGROUP 69 # allow intra-sec-group communication 70 neutron security-group-rule-create --remote-group-id $DEIS_SECGROUP $DEIS_SECGROUP 71 fi 72 73 if [ -z "$DEIS_NUM_INSTANCES" ]; then 74 DEIS_NUM_INSTANCES=3 75 fi 76 77 # check that the CoreOS user-data file is valid 78 $CONTRIB_DIR/util/check-user-data.sh 79 80 i=1 ; while [[ $i -le $DEIS_NUM_INSTANCES ]] ; do \ 81 echo_yellow "Provisioning deis-$i..." 82 nova boot --image $COREOS_IMAGE --flavor $FLAVOR --key-name $KEYPAIR \ 83 --security-groups $DEIS_SECGROUP --user-data ../coreos/user-data \ 84 --nic net-id=$NETWORK_ID deis-$i ; \ 85 ((i = i + 1)) ; \ 86 done 87 88 echo_green "Your Deis cluster has successfully deployed to OpenStack." 89 echo_green "Please continue to follow the instructions in the README."