4d601756 |
#!/bin/bash
#
# lib/placement
# Functions to control the configuration and operation of the **Placement** service
#
# Dependencies:
#
# - ``functions`` file
# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
# - ``FILES``
# ``stack.sh`` calls the entry points in this order:
#
# - install_placement
# - cleanup_placement
# - configure_placement
# - init_placement
# - start_placement
# - stop_placement
# Save trace setting
_XTRACE_LIB_PLACEMENT=$(set +o | grep xtrace)
set +o xtrace
# Defaults
# --------
|
78a564bb |
PLACEMENT_DIR=$DEST/placement
PLACEMENT_CONF_DIR=/etc/placement
PLACEMENT_CONF=$PLACEMENT_CONF_DIR/placement.conf
PLACEMENT_AUTH_STRATEGY=${PLACEMENT_AUTH_STRATEGY:-keystone}
# Placement virtual environment |
64ffff9b |
if [[ ${USE_VENV} = True ]]; then |
78a564bb |
PROJECT_VENV["placement"]=${PLACEMENT_DIR}.venv
PLACEMENT_BIN_DIR=${PROJECT_VENV["placement"]}/bin |
64ffff9b |
else
PLACEMENT_BIN_DIR=$(get_python_exec_prefix)
fi |
78a564bb |
PLACEMENT_UWSGI=$PLACEMENT_BIN_DIR/placement-api |
64ffff9b |
PLACEMENT_UWSGI_CONF=$PLACEMENT_CONF_DIR/placement-uwsgi.ini |
4d601756 |
|
f3b2f4c8 |
if is_service_enabled tls-proxy; then |
4d601756 |
PLACEMENT_SERVICE_PROTOCOL="https"
fi
# Public facing bits
PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST}
# Functions
# ---------
# Test if any placement services are enabled
# is_placement_enabled
function is_placement_enabled { |
51a225c5 |
[[ ,${ENABLED_SERVICES} =~ ,"placement-api" ]] && return 0 |
4d601756 |
return 1
}
# cleanup_placement() - Remove residual data files, anything left over from previous
# runs that a clean run would need to clean up
function cleanup_placement {
sudo rm -f $(apache_site_config_for placement-api) |
1489b9e7 |
remove_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" |
4d601756 |
}
# _config_placement_apache_wsgi() - Set WSGI config files
function _config_placement_apache_wsgi {
local placement_api_apache_conf
local venv_path="" |
78a564bb |
local placement_bin_dir=""
placement_bin_dir=$(get_python_exec_prefix) |
4d601756 |
placement_api_apache_conf=$(apache_site_config_for placement-api)
if [[ ${USE_VENV} = True ]]; then |
78a564bb |
venv_path="python-path=${PROJECT_VENV["placement"]}/lib/$(python_version)/site-packages"
placement_bin_dir=${PROJECT_VENV["placement"]}/bin |
4d601756 |
fi
sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
sudo sed -e "
s|%APACHE_NAME%|$APACHE_NAME|g; |
78a564bb |
s|%PUBLICWSGI%|$placement_bin_dir/placement-api|g; |
4d601756 |
s|%SSLENGINE%|$placement_ssl|g;
s|%SSLCERTFILE%|$placement_certfile|g;
s|%SSLKEYFILE%|$placement_keyfile|g;
s|%USER%|$STACK_USER|g;
s|%VIRTUALENV%|$venv_path|g
s|%APIWORKERS%|$API_WORKERS|g
" -i $placement_api_apache_conf
}
|
3027c205 |
# create_placement_conf() - Write config |
78a564bb |
function create_placement_conf {
rm -f $PLACEMENT_CONF
iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
iniset $PLACEMENT_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
iniset $PLACEMENT_CONF api auth_strategy $PLACEMENT_AUTH_STRATEGY |
8ab64b32 |
configure_keystone_authtoken_middleware $PLACEMENT_CONF placement |
78a564bb |
setup_logging $PLACEMENT_CONF |
51a225c5 |
} |
4d601756 |
|
51a225c5 |
# configure_placement() - Set config files, create data dirs, etc
function configure_placement { |
78a564bb |
sudo install -d -o $STACK_USER $PLACEMENT_CONF_DIR
create_placement_conf |
e0be9e3a |
|
64ffff9b |
if [[ "$WSGI_MODE" == "uwsgi" ]]; then
write_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" "/placement"
else
_config_placement_apache_wsgi
fi |
4d601756 |
}
# create_placement_accounts() - Set up required placement accounts
# and service and endpoints.
function create_placement_accounts {
create_service_user "placement" "admin"
local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
get_or_create_service "placement" "placement" "Placement Service"
get_or_create_endpoint \
"placement" \
"$REGION_NAME" \
"$placement_api_url"
}
# init_placement() - Create service user and endpoints
function init_placement { |
78a564bb |
recreate_database placement
$PLACEMENT_BIN_DIR/placement-manage db sync |
4d601756 |
create_placement_accounts
}
# install_placement() - Collect source and prepare
function install_placement {
install_apache_wsgi |
a066abed |
# Install the openstackclient placement client plugin for CLI |
78a564bb |
pip_install_gr osc-placement
git_clone $PLACEMENT_REPO $PLACEMENT_DIR $PLACEMENT_BRANCH
setup_develop $PLACEMENT_DIR |
4d601756 |
}
# start_placement_api() - Start the API processes ahead of other things
function start_placement_api { |
64ffff9b |
if [[ "$WSGI_MODE" == "uwsgi" ]]; then |
312517d5 |
run_process "placement-api" "$(which uwsgi) --procname-prefix placement --ini $PLACEMENT_UWSGI_CONF" |
64ffff9b |
else
enable_apache_site placement-api
restart_apache_server
tail_log placement-api /var/log/$APACHE_NAME/placement-api.log
fi |
4d601756 |
echo "Waiting for placement-api to start..."
if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
die $LINENO "placement-api did not start"
fi
}
function start_placement {
start_placement_api
}
# stop_placement() - Disable the api service and stop it.
function stop_placement { |
64ffff9b |
if [[ "$WSGI_MODE" == "uwsgi" ]]; then
stop_process "placement-api"
else
disable_apache_site placement-api
restart_apache_server
fi |
4d601756 |
}
# Restore xtrace
$_XTRACE_LIB_PLACEMENT
# Tell emacs to use shell-script-mode
## Local variables:
## mode: shell-script
## End: |