2015-04-28 12:12:14 +09:00
|
|
|
#!/bin/bash
|
2019-06-28 12:32:52 +01:00
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
|
2015-04-28 12:12:14 +09:00
|
|
|
# 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.
|
|
|
|
|
2018-01-03 10:16:29 +00:00
|
|
|
ARCH=$(uname -m)
|
2017-08-28 14:38:50 +02:00
|
|
|
IMAGE_PATH=/opt/cache/files/
|
2018-01-03 10:16:29 +00:00
|
|
|
IMAGE_URL=http://download.cirros-cloud.net/0.4.0/
|
|
|
|
IMAGE=cirros-0.4.0-${ARCH}-disk.img
|
2017-01-24 14:51:48 +00:00
|
|
|
IMAGE_NAME=cirros
|
2017-03-13 10:47:30 +00:00
|
|
|
IMAGE_TYPE=linux
|
2017-12-15 08:38:43 +00:00
|
|
|
|
|
|
|
# This EXT_NET_CIDR is your public network,that you want to connect to the internet via.
|
2019-07-10 17:48:28 +01:00
|
|
|
ENABLE_EXT_NET=${ENABLE_EXT_NET:-1}
|
2017-01-24 14:51:48 +00:00
|
|
|
EXT_NET_CIDR='10.0.2.0/24'
|
|
|
|
EXT_NET_RANGE='start=10.0.2.150,end=10.0.2.199'
|
|
|
|
EXT_NET_GATEWAY='10.0.2.1'
|
|
|
|
|
2015-06-04 15:33:30 +00:00
|
|
|
# Sanitize language settings to avoid commands bailing out
|
|
|
|
# with "unsupported locale setting" errors.
|
|
|
|
unset LANG
|
|
|
|
unset LANGUAGE
|
|
|
|
LC_ALL=C
|
|
|
|
export LC_ALL
|
2016-12-12 15:25:19 +00:00
|
|
|
for i in curl openstack; do
|
2017-01-24 14:51:48 +00:00
|
|
|
if [[ ! $(type ${i} 2>/dev/null) ]]; then
|
|
|
|
if [ "${i}" == 'curl' ]; then
|
|
|
|
echo "Please install ${i} before proceeding"
|
2016-09-13 23:40:01 +08:00
|
|
|
else
|
2016-12-12 15:25:19 +00:00
|
|
|
echo "Please install python-${i}client before proceeding"
|
2016-09-13 23:40:01 +08:00
|
|
|
fi
|
|
|
|
exit
|
|
|
|
fi
|
2016-03-08 17:50:51 +00:00
|
|
|
done
|
2015-04-28 12:12:14 +09:00
|
|
|
|
|
|
|
# Test for credentials set
|
|
|
|
if [[ "${OS_USERNAME}" == "" ]]; then
|
2018-07-27 09:39:17 +08:00
|
|
|
echo "No Keystone credentials specified. Try running source /etc/kolla/admin-openrc.sh command"
|
2015-04-28 12:12:14 +09:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Test to ensure configure script is run only once
|
2016-12-12 15:25:19 +00:00
|
|
|
if openstack image list | grep -q cirros; then
|
2015-04-28 12:12:14 +09:00
|
|
|
echo "This tool should only be run once per deployment."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2017-08-28 14:38:50 +02:00
|
|
|
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.
|
2015-04-28 12:12:14 +09:00
|
|
|
fi
|
2018-01-03 12:01:13 +01:00
|
|
|
|
2015-04-28 12:12:14 +09:00
|
|
|
echo Creating glance image.
|
2016-12-12 15:25:19 +00:00
|
|
|
openstack image create --disk-format qcow2 --container-format bare --public \
|
2019-06-04 08:56:57 +02:00
|
|
|
--property os_type=${IMAGE_TYPE} --file ${IMAGE_PATH}/${IMAGE} ${IMAGE_NAME}
|
2015-04-28 12:12:14 +09:00
|
|
|
|
2016-12-01 01:44:29 +08:00
|
|
|
echo Configuring neutron.
|
2019-07-10 17:48:28 +01:00
|
|
|
if [[ $ENABLE_EXT_NET -eq 1 ]]; then
|
|
|
|
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
|
|
|
|
fi
|
2016-12-12 15:25:19 +00:00
|
|
|
|
|
|
|
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
|
2019-07-10 17:48:28 +01:00
|
|
|
if [[ $ENABLE_EXT_NET -eq 1 ]]; then
|
|
|
|
openstack router set --external-gateway public1 demo-router
|
|
|
|
fi
|
2015-04-28 12:12:14 +09:00
|
|
|
|
2017-01-24 15:07:26 +00:00
|
|
|
# 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}')
|
|
|
|
|
2016-12-01 01:44:29 +08:00
|
|
|
# Sec Group Config
|
2016-12-12 15:25:19 +00:00
|
|
|
openstack security group rule create --ingress --ethertype IPv4 \
|
2017-10-26 23:50:17 +02:00
|
|
|
--protocol icmp ${ADMIN_SEC_GROUP}
|
2016-12-12 15:25:19 +00:00
|
|
|
openstack security group rule create --ingress --ethertype IPv4 \
|
2017-01-24 15:07:26 +00:00
|
|
|
--protocol tcp --dst-port 22 ${ADMIN_SEC_GROUP}
|
2016-12-01 01:44:29 +08:00
|
|
|
# Open heat-cfn so it can run on a different host
|
2016-12-12 15:25:19 +00:00
|
|
|
openstack security group rule create --ingress --ethertype IPv4 \
|
2017-01-24 15:07:26 +00:00
|
|
|
--protocol tcp --dst-port 8000 ${ADMIN_SEC_GROUP}
|
2016-12-12 15:25:19 +00:00
|
|
|
openstack security group rule create --ingress --ethertype IPv4 \
|
2017-01-24 15:07:26 +00:00
|
|
|
--protocol tcp --dst-port 8080 ${ADMIN_SEC_GROUP}
|
2015-04-28 12:12:14 +09:00
|
|
|
|
2016-09-26 18:19:20 +08:00
|
|
|
if [ ! -f ~/.ssh/id_rsa.pub ]; then
|
|
|
|
echo Generating ssh key.
|
|
|
|
ssh-keygen -t rsa -f ~/.ssh/id_rsa
|
|
|
|
fi
|
2015-04-28 12:12:14 +09:00
|
|
|
if [ -r ~/.ssh/id_rsa.pub ]; then
|
|
|
|
echo Configuring nova public key and quotas.
|
2016-12-12 15:25:19 +00:00
|
|
|
openstack keypair create --public-key ~/.ssh/id_rsa.pub mykey
|
2015-04-28 12:12:14 +09:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Increase the quota to allow 40 m1.small instances to be created
|
|
|
|
|
|
|
|
# 40 instances
|
2017-01-24 14:51:48 +00:00
|
|
|
openstack quota set --instances 40 ${ADMIN_PROJECT_ID}
|
2015-04-28 12:12:14 +09:00
|
|
|
|
|
|
|
# 40 cores
|
2017-01-24 14:51:48 +00:00
|
|
|
openstack quota set --cores 40 ${ADMIN_PROJECT_ID}
|
2015-04-28 12:12:14 +09:00
|
|
|
|
|
|
|
# 96GB ram
|
2017-01-24 14:51:48 +00:00
|
|
|
openstack quota set --ram 96000 ${ADMIN_PROJECT_ID}
|
2016-04-06 23:31:10 -07:00
|
|
|
|
|
|
|
# add default flavors, if they don't already exist
|
|
|
|
if ! openstack flavor list | grep -q m1.tiny; then
|
2016-12-12 15:25:19 +00:00
|
|
|
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
|
2016-04-06 23:31:10 -07:00
|
|
|
fi
|
2016-09-15 15:46:56 +01:00
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
|
|
|
|
Done.
|
|
|
|
|
|
|
|
To deploy a demo instance, run:
|
|
|
|
|
|
|
|
openstack server create \\
|
2017-01-24 14:51:48 +00:00
|
|
|
--image ${IMAGE_NAME} \\
|
2016-09-15 15:46:56 +01:00
|
|
|
--flavor m1.tiny \\
|
|
|
|
--key-name mykey \\
|
2018-04-13 17:17:04 +01:00
|
|
|
--network demo-net \\
|
2016-09-15 15:46:56 +01:00
|
|
|
demo1
|
|
|
|
EOF
|