OpenStack in a snap!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

95 lines
3.2 KiB

#!/bin/bash
set -ex
ospassword=$(snapctl get ospassword)
extgateway=$(snapctl get extgateway)
extcidr=$(snapctl get extcidr)
dns=$(snapctl get dns)
if [ -z "$ospassword" -o -z "$extgateway" -o -z "$dns" -o -z "$extcidr"]; then
echo "Missing required config value."
snapctl get microstack
exit 1
fi
snap-openstack setup # Write out templates
source $SNAP_COMMON/etc/microstack.rc
# Open up networking so that instances can route to the Internet (see
# bin/setup-br-ex for more networking setup, executed on microstack
# services start.)
sudo sysctl net.ipv4.ip_forward=1
# Create all of the databases
echo "Creating OpenStack Databases"
# Wait for MySQL to startup
while ! nc -z $extgateway 3306; do sleep 0.1; done;
sleep 5
# Wait for rabbitmq to start
while ! nc -z $extgateway 5672; do sleep 0.1; done;
for db in neutron nova nova_api nova_cell0 cinder glance keystone; do
echo "CREATE DATABASE IF NOT EXISTS ${db}; GRANT ALL PRIVILEGES ON ${db}.* TO '${db}'@'$extgateway' IDENTIFIED BY '${db}';" \
| mysql-start-client -u root
done
# Grant nova user access to cell0
echo "GRANT ALL PRIVILEGES ON nova_cell0.* TO 'nova'@'$extgateway' IDENTIFIED BY 'nova';" | mysql-start-client -u root
# Endpoints from localhost -> $extgateway
# TODO Rebuild database so that these are already set to $extgateway,
# after lp:1824176 is addressed, and the process of building a new
# mysql.tar.xz is less fraught.
openstack endpoint list | grep localhost | while read line; do openstack endpoint set `echo $line | cut -d" " -f2` --url `echo $line | cut -d" " -f14 | sed "s/localhost/$extgateway/"`; done
# RabbitMQ
echo "Configuring RabbitMQ"
# Rabbitmq isn't always started when we run this. Wait for it to start.
while :;
do
grep "Starting broker..." ${SNAP_COMMON}/log/rabbitmq/startup_log && \
grep "completed" ${SNAP_COMMON}/log/rabbitmq/startup_log && \
break
echo "waiting for rabbitmq to start" && sleep 1;
done
HOME=$SNAP_COMMON/lib/rabbitmq rabbitmqctl add_user openstack rabbitmq || :
HOME=$SNAP_COMMON/lib/rabbitmq rabbitmqctl set_permissions openstack ".*" ".*" ".*"
# Glance
echo "Waiting for glance to start."
while ! nc -z $extgateway 9292; do sleep 0.1; done;
sleep 5
# Wait for identity service
while ! nc -z $extgateway 5000; do sleep 0.1; done;
# Setup the cirros image, which is used by the launch app
openstack image show cirros || {
[ -f $SNAP_COMMON/images/cirros-0.4.0-x86_64-disk.img ] || {
mkdir -p $SNAP_COMMON/images
wget \
http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img \
-O ${SNAP_COMMON}/images/cirros-0.4.0-x86_64-disk.img
}
openstack image create \
--file ${SNAP_COMMON}/images/cirros-0.4.0-x86_64-disk.img \
--public --container-format=bare --disk-format=qcow2 cirros
}
# Restart libvirt and virtlogd to get logging
# TODO: figure out why this doesn't Just Work initially
systemctl restart snap.microstack.*virt*
# Wait for horizon
while ! nc -z $extgateway 80; do sleep 0.1; done;
# Restart Placement API
# Workaround for issue w/ base:core18, where the Placement API throws
# http 500s until it has been restarted.
# TODO: root cause and fix the problem.
systemctl restart snap.microstack.nova-uwsgi.service