ff0d4d4c06
This adds a /opt/kolla/kolla-common.sh to the base image as a place to put commonly used functions. The goal is to avoid code duplication across all the images created from this base image. Change-Id: Ib670fe369bb8048aa69979b74a984fa4ddaae7d9
67 lines
1.7 KiB
Bash
67 lines
1.7 KiB
Bash
#!/bin/bash
|
|
|
|
# Set some generally useful defaults.
|
|
MY_IP=$(ip route get $(ip route | awk '$1 == "default" {print $3}') |
|
|
awk '$4 == "src" {print $5}')
|
|
|
|
: ${PUBLIC_IP:=${MY_IP}}
|
|
|
|
# Iterate over a list of variable names and exit if one is
|
|
# undefined.
|
|
check_required_vars() {
|
|
for var in $*; do
|
|
if [ -z "${!var}" ]; then
|
|
echo "ERROR: missing $var" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
}
|
|
|
|
# Exit unless we receive a successful response from the Glance API.
|
|
check_for_glance() {
|
|
check_required_vars GLANCE_API_SERVICE_HOST
|
|
GLANCE_API_URL="http://${GLANCE_API_SERVICE_HOST}:9292/"
|
|
|
|
curl -sf -o /dev/null "$GLANCE_API_URL" || {
|
|
echo "ERROR: glance is not available @ $GLANCE_API_URL" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "glance is active @ $GLANCE_API_URL"
|
|
}
|
|
|
|
# Exit unless we receive a successful response from the Keystone API.
|
|
check_for_keystone() {
|
|
check_required_vars KEYSTONE_PUBLIC_SERVICE_HOST
|
|
|
|
KEYSTONE_URL="http://${KEYSTONE_PUBLIC_SERVICE_HOST}:5000/v2.0"
|
|
|
|
curl -sf -o /dev/null "$KEYSTONE_URL" || {
|
|
echo "ERROR: keystone is not available @ $KEYSTONE_URL" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "keystone is active @ $KEYSTONE_URL"
|
|
}
|
|
|
|
# Exit unless we receive a successful response from the database server.
|
|
check_for_db() {
|
|
check_required_vars MARIADB_SERVICE_HOST DB_ROOT_PASSWORD
|
|
|
|
mysql -h ${MARIADB_SERVICE_HOST} -u root -p"${DB_ROOT_PASSWORD}" \
|
|
-e "select 1" mysql > /dev/null 2>&1 || {
|
|
echo "ERROR: database is not available @ $MARIADB_SERVICE_HOST" >&2
|
|
exit 1
|
|
}
|
|
|
|
echo "database is active @ ${MARIADB_SERVICE_HOST}"
|
|
}
|
|
|
|
# Dump shell environment to a file
|
|
dump_vars() {
|
|
set -o posix
|
|
set > /pid_$$_vars.sh
|
|
set +o posix
|
|
}
|
|
|