Files
microstack/snap-overlay/bin/launch.sh
Pete Vander Giessen 92a6ea8dc7 Broke configuration out into a manual step.
Renamed the old and outdated "configure-openstack" script to "init.sh"

Updated init.sh and folded most of the configure hook into it.

Removed database installation step from install hook.

We can now install microstack without a database dump, which helps
immensely in updating. And we have a logical place to put additional
configuraiton, including some of the manual steps in DEMO.md, which
could be scripted if we gave users a chance to skip the system changes
that they wanted to skip.

Also updated README and DEMO file to match new flow. Updated test
files.

Future cleanup and features documented in Trello, but not included in
this PR, which is big enough already :-)

Change-Id: I8d926a8b463124494ddb7a4696adbe86f89db7d5
2019-08-01 21:12:05 +00:00

76 lines
2.5 KiB
Bash
Executable File

#!/bin/bash
set -e
# Check for microstack.init. TODO: just run microstack.init ...
if ! [ "$(snapctl get initialized)" == "true" ]; then
echo "Microstack is not initialized. Please run microstack.init!"
exit 1;
fi
source $SNAP_COMMON/etc/microstack.rc
if [ -z "$1" ]; then
echo "Please specify a name for the server."
exit 1
else
SERVER=$1
fi
if [[ ! $(openstack keypair list | grep "| microstack |") ]]; then
echo "creating keypair ($HOME/.ssh/id_microstack)"
mkdir -p $HOME/.ssh
chmod 700 $HOME/.ssh
openstack keypair create microstack > $HOME/.ssh/id_microstack
chmod 600 $HOME/.ssh/id_microstack
fi
echo "Launching instance ..."
openstack server create --flavor m1.tiny --image cirros --nic net-id=test --key-name microstack $SERVER
echo "Checking security groups ..."
SECGROUP_ID=`openstack security group list --project admin -f value -c ID`
if [[ ! $(openstack security group rule list | grep icmp | grep $SECGROUP_ID) ]]; then
echo "Creating security group rule for ping."
openstack security group rule create $SECGROUP_ID --proto icmp
fi
if [[ ! $(openstack security group rule list | grep tcp | grep $SECGROUP_ID) ]]; then
echo "Creating security group rule for ssh."
openstack security group rule create $SECGROUP_ID --proto tcp --dst-port 22
fi
TRIES=0
while [[ $(openstack server list | grep $SERVER | grep ERROR) ]]; do
TRIES=$(($TRIES + 1))
if test $TRIES -gt 3; then
break
fi
echo "I ran into an issue launching an instance. Retrying ... (try $TRIES of 3)"
openstack server delete $SERVER
openstack server create --flavor m1.tiny --image cirros --nic net-id=test --key-name microstack $SERVER
while [[ $(openstack server list | grep $SERVER | grep BUILD) ]]; do
sleep 1;
done
done
echo "Allocating floating ip ..."
ALLOCATED_FIP=`openstack floating ip create -f value -c floating_ip_address external`
openstack server add floating ip $SERVER $ALLOCATED_FIP
echo "Waiting for server to become ACTIVE."
while :; do
if [[ $(openstack server list | grep $SERVER | grep ACTIVE) ]]; then
openstack server list
echo "Access your server with 'ssh -i $HOME/.ssh/id_microstack cirros@$ALLOCATED_FIP'"
break
fi
if [[ $(openstack server list | grep $SERVER | grep ERROR) ]]; then
openstack server list
echo "Uh-oh. There was an error. See /var/snap/microstack/common/log for details."
exit 1
fi
done
echo "You can also visit the openstack dashboard at 'http://$extgateway/'"