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