-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-runonce
executable file
·145 lines (121 loc) · 4.8 KB
/
init-runonce
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
#
# This script is meant to be run once after running start for the first
# time. This script downloads a cirros image and registers it. Then it
# configures networking and nova quotas to allow 40 m1.small instances
# to be created.
ARCH=$(uname -m)
IMAGE_PATH=/opt/cache/files/
IMAGE_URL=http://download.cirros-cloud.net/0.4.0/
IMAGE=cirros-0.4.0-${ARCH}-disk.img
IMAGE_NAME=cirros
IMAGE_TYPE=linux
# This EXT_NET_CIDR is your public network,that you want to connect to the internet via.
EXT_NET_CIDR='203.0.113.0/24'
EXT_NET_RANGE='start=203.0.113.150,end=203.0.113.199'
EXT_NET_GATEWAY='203.0.113.1'
# Sanitize language settings to avoid commands bailing out
# with "unsupported locale setting" errors.
unset LANG
unset LANGUAGE
LC_ALL=C
export LC_ALL
for i in curl openstack; do
if [[ ! $(type ${i} 2>/dev/null) ]]; then
if [ "${i}" == 'curl' ]; then
echo "Please install ${i} before proceeding"
else
echo "Please install python-${i}client before proceeding"
fi
exit
fi
done
# Test for credentials set
if [[ "${OS_USERNAME}" == "" ]]; then
echo "No Keystone credentials specified. Try running source openrc"
exit
fi
# Test to ensure configure script is run only once
if openstack image list | grep -q cirros; then
echo "This tool should only be run once per deployment."
exit
fi
echo Checking for locally available cirros image.
# Let's first try to see if the image is available locally
# nodepool nodes caches them in $IMAGE_PATH
if ! [ -f "${IMAGE_PATH}/${IMAGE}" ]; then
IMAGE_PATH='./'
if ! [ -f "${IMAGE_PATH}/${IMAGE}" ]; then
echo None found, downloading cirros image.
curl -L -o ${IMAGE_PATH}/${IMAGE} ${IMAGE_URL}/${IMAGE}
fi
else
echo Using cached cirros image from the nodepool node.
fi
EXTRA_PROPERTIES=
if [ ${ARCH} == aarch64 ]; then
EXTRA_PROPERTIES="--property hw_firmware_type=uefi"
fi
echo Creating glance image.
openstack image create --disk-format qcow2 --container-format bare --public \
--property os_type=${IMAGE_TYPE} ${EXTRA_PROPERTIES} --file ${IMAGE_PATH}/${IMAGE} ${IMAGE_NAME}
echo Configuring neutron.
openstack network create --external --provider-physical-network physnet1 \
--provider-network-type flat public1
openstack subnet create --no-dhcp \
--allocation-pool ${EXT_NET_RANGE} --network public1 \
--subnet-range ${EXT_NET_CIDR} --gateway ${EXT_NET_GATEWAY} public1-subnet
openstack network create --provider-network-type vxlan demo-net
openstack subnet create --subnet-range 10.0.0.0/24 --network demo-net \
--gateway 10.0.0.1 --dns-nameserver 8.8.8.8 demo-subnet
openstack router create demo-router
openstack router add subnet demo-router demo-subnet
openstack router set --external-gateway public1 demo-router
# Get admin user and tenant IDs
ADMIN_USER_ID=$(openstack user list | awk '/ admin / {print $2}')
ADMIN_PROJECT_ID=$(openstack project list | awk '/ admin / {print $2}')
ADMIN_SEC_GROUP=$(openstack security group list --project ${ADMIN_PROJECT_ID} | awk '/ default / {print $2}')
# Sec Group Config
openstack security group rule create --ingress --ethertype IPv4 \
--protocol icmp ${ADMIN_SEC_GROUP}
openstack security group rule create --ingress --ethertype IPv4 \
--protocol tcp --dst-port 22 ${ADMIN_SEC_GROUP}
# Open heat-cfn so it can run on a different host
openstack security group rule create --ingress --ethertype IPv4 \
--protocol tcp --dst-port 8000 ${ADMIN_SEC_GROUP}
openstack security group rule create --ingress --ethertype IPv4 \
--protocol tcp --dst-port 8080 ${ADMIN_SEC_GROUP}
if [ ! -f ~/.ssh/id_rsa.pub ]; then
echo Generating ssh key.
ssh-keygen -t rsa -f ~/.ssh/id_rsa
fi
if [ -r ~/.ssh/id_rsa.pub ]; then
echo Configuring nova public key and quotas.
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
fi
# Increase the quota to allow 40 m1.small instances to be created
# 40 instances
openstack quota set --instances 40 ${ADMIN_PROJECT_ID}
# 40 cores
openstack quota set --cores 40 ${ADMIN_PROJECT_ID}
# 96GB ram
openstack quota set --ram 96000 ${ADMIN_PROJECT_ID}
# add default flavors, if they don't already exist
if ! openstack flavor list | grep -q m1.tiny; then
openstack flavor create --id 1 --ram 512 --disk 1 --vcpus 1 m1.tiny
openstack flavor create --id 2 --ram 2048 --disk 20 --vcpus 1 m1.small
openstack flavor create --id 3 --ram 4096 --disk 40 --vcpus 2 m1.medium
openstack flavor create --id 4 --ram 8192 --disk 80 --vcpus 4 m1.large
openstack flavor create --id 5 --ram 16384 --disk 160 --vcpus 8 m1.xlarge
fi
DEMO_NET_ID=$(openstack network list | awk '/ demo-net / {print $2}')
cat << EOF
Done.
To deploy a demo instance, run:
openstack server create \\
--image ${IMAGE_NAME} \\
--flavor m1.tiny \\
--key-name mykey \\
--nic net-id=${DEMO_NET_ID} \\
demo1
EOF