blob: da69e39264e43eee744d4c16a711a911e2f95da4 [file] [log] [blame]
Chris Dent4d601752016-07-12 19:34:09 +00001#!/bin/bash
2#
3# lib/placement
4# Functions to control the configuration and operation of the **Placement** service
5#
Chris Dent4d601752016-07-12 19:34:09 +00006
7# Dependencies:
8#
9# - ``functions`` file
10# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
11# - ``FILES``
12
13# ``stack.sh`` calls the entry points in this order:
14#
15# - install_placement
16# - cleanup_placement
17# - configure_placement
18# - init_placement
19# - start_placement
20# - stop_placement
21
22# Save trace setting
23_XTRACE_LIB_PLACEMENT=$(set +o | grep xtrace)
24set +o xtrace
25
26# Defaults
27# --------
28
Chris Dent78a564b2018-10-05 10:17:56 +010029PLACEMENT_DIR=$DEST/placement
30PLACEMENT_CONF_DIR=/etc/placement
31PLACEMENT_CONF=$PLACEMENT_CONF_DIR/placement.conf
32PLACEMENT_AUTH_CACHE_DIR=${PLACEMENT_AUTH_CACHE_DIR:-/var/cache/placement}
33PLACEMENT_AUTH_STRATEGY=${PLACEMENT_AUTH_STRATEGY:-keystone}
34# Placement virtual environment
Sean Dague64ffff92017-04-13 13:36:42 -040035if [[ ${USE_VENV} = True ]]; then
Chris Dent78a564b2018-10-05 10:17:56 +010036 PROJECT_VENV["placement"]=${PLACEMENT_DIR}.venv
37 PLACEMENT_BIN_DIR=${PROJECT_VENV["placement"]}/bin
Sean Dague64ffff92017-04-13 13:36:42 -040038else
39 PLACEMENT_BIN_DIR=$(get_python_exec_prefix)
40fi
Chris Dent78a564b2018-10-05 10:17:56 +010041PLACEMENT_UWSGI=$PLACEMENT_BIN_DIR/placement-api
Sean Dague64ffff92017-04-13 13:36:42 -040042PLACEMENT_UWSGI_CONF=$PLACEMENT_CONF_DIR/placement-uwsgi.ini
Chris Dent4d601752016-07-12 19:34:09 +000043
Sean Daguef3b2f4c2017-04-13 10:11:48 -040044if is_service_enabled tls-proxy; then
Chris Dent4d601752016-07-12 19:34:09 +000045 PLACEMENT_SERVICE_PROTOCOL="https"
46fi
47
48# Public facing bits
49PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
50PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST}
Chris Dent4d601752016-07-12 19:34:09 +000051
52# Functions
53# ---------
54
55# Test if any placement services are enabled
56# is_placement_enabled
57function is_placement_enabled {
Sean Dague51a225c2016-12-15 16:32:08 -050058 [[ ,${ENABLED_SERVICES} =~ ,"placement-api" ]] && return 0
Chris Dent4d601752016-07-12 19:34:09 +000059 return 1
60}
61
62# cleanup_placement() - Remove residual data files, anything left over from previous
63# runs that a clean run would need to clean up
64function cleanup_placement {
65 sudo rm -f $(apache_site_config_for placement-api)
Chris Dent1489b9e2017-12-05 23:46:58 +000066 remove_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI"
Chris Dent78a564b2018-10-05 10:17:56 +010067 sudo rm -f $PLACEMENT_AUTH_CACHE_DIR/*
Chris Dent4d601752016-07-12 19:34:09 +000068}
69
70# _config_placement_apache_wsgi() - Set WSGI config files
71function _config_placement_apache_wsgi {
Chris Dent4d601752016-07-12 19:34:09 +000072 local placement_api_apache_conf
Chris Dent4d601752016-07-12 19:34:09 +000073 local venv_path=""
Chris Dent78a564b2018-10-05 10:17:56 +010074 local placement_bin_dir=""
75 placement_bin_dir=$(get_python_exec_prefix)
Chris Dent4d601752016-07-12 19:34:09 +000076 placement_api_apache_conf=$(apache_site_config_for placement-api)
77
Chris Dent4d601752016-07-12 19:34:09 +000078 if [[ ${USE_VENV} = True ]]; then
Chris Dent78a564b2018-10-05 10:17:56 +010079 venv_path="python-path=${PROJECT_VENV["placement"]}/lib/$(python_version)/site-packages"
80 placement_bin_dir=${PROJECT_VENV["placement"]}/bin
Chris Dent4d601752016-07-12 19:34:09 +000081 fi
82
Chris Dent4d601752016-07-12 19:34:09 +000083 sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
84 sudo sed -e "
Chris Dent4d601752016-07-12 19:34:09 +000085 s|%APACHE_NAME%|$APACHE_NAME|g;
Chris Dent78a564b2018-10-05 10:17:56 +010086 s|%PUBLICWSGI%|$placement_bin_dir/placement-api|g;
Chris Dent4d601752016-07-12 19:34:09 +000087 s|%SSLENGINE%|$placement_ssl|g;
88 s|%SSLCERTFILE%|$placement_certfile|g;
89 s|%SSLKEYFILE%|$placement_keyfile|g;
90 s|%USER%|$STACK_USER|g;
91 s|%VIRTUALENV%|$venv_path|g
92 s|%APIWORKERS%|$API_WORKERS|g
93 " -i $placement_api_apache_conf
94}
95
Sean Dague51a225c2016-12-15 16:32:08 -050096function configure_placement_nova_compute {
Matt Riedemannf6d566c2017-12-22 11:39:29 -050097 # Use the provided config file path or default to $NOVA_CONF.
98 local conf=${1:-$NOVA_CONF}
99 iniset $conf placement auth_type "password"
100 iniset $conf placement auth_url "$KEYSTONE_SERVICE_URI"
101 iniset $conf placement username placement
102 iniset $conf placement password "$SERVICE_PASSWORD"
103 iniset $conf placement user_domain_name "$SERVICE_DOMAIN_NAME"
104 iniset $conf placement project_name "$SERVICE_TENANT_NAME"
105 iniset $conf placement project_domain_name "$SERVICE_DOMAIN_NAME"
Chris Dent78a564b2018-10-05 10:17:56 +0100106 iniset $conf placement auth_strategy $PLACEMENT_AUTH_STRATEGY
107}
108
Chris Dent3027c202018-11-20 22:18:26 +0000109# create_placement_conf() - Write config
Chris Dent78a564b2018-10-05 10:17:56 +0100110function create_placement_conf {
111 rm -f $PLACEMENT_CONF
112 iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
113 iniset $PLACEMENT_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
114 iniset $PLACEMENT_CONF api auth_strategy $PLACEMENT_AUTH_STRATEGY
115 configure_auth_token_middleware $PLACEMENT_CONF placement $PLACEMENT_AUTH_CACHE_DIR
116 setup_logging $PLACEMENT_CONF
Sean Dague51a225c2016-12-15 16:32:08 -0500117}
Chris Dent4d601752016-07-12 19:34:09 +0000118
Sean Dague51a225c2016-12-15 16:32:08 -0500119# configure_placement() - Set config files, create data dirs, etc
120function configure_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100121 sudo install -d -o $STACK_USER $PLACEMENT_CONF_DIR
122 create_placement_conf
Chris Dente0be9e32017-04-18 16:52:25 +0100123
Sean Dague64ffff92017-04-13 13:36:42 -0400124 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
125 write_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" "/placement"
126 else
127 _config_placement_apache_wsgi
128 fi
Chris Dent4d601752016-07-12 19:34:09 +0000129}
130
131# create_placement_accounts() - Set up required placement accounts
132# and service and endpoints.
133function create_placement_accounts {
134 create_service_user "placement" "admin"
135 local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
136 get_or_create_service "placement" "placement" "Placement Service"
137 get_or_create_endpoint \
138 "placement" \
139 "$REGION_NAME" \
Chris Dent4d601752016-07-12 19:34:09 +0000140 "$placement_api_url"
141}
142
Chris Dent78a564b2018-10-05 10:17:56 +0100143# create_placement_cache_dir() - Create directories for keystone cache
144function create_placement_cache_dir {
145 # Create cache dir
146 sudo install -d -o $STACK_USER $PLACEMENT_AUTH_CACHE_DIR
147 rm -f $PLACEMENT_AUTH_CACHE_DIR/*
148}
149
Chris Dent4d601752016-07-12 19:34:09 +0000150# init_placement() - Create service user and endpoints
Chris Dent4d601752016-07-12 19:34:09 +0000151function init_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100152 recreate_database placement
153 $PLACEMENT_BIN_DIR/placement-manage db sync
Chris Dent4d601752016-07-12 19:34:09 +0000154 create_placement_accounts
Chris Dent78a564b2018-10-05 10:17:56 +0100155 create_placement_cache_dir
Chris Dent4d601752016-07-12 19:34:09 +0000156}
157
158# install_placement() - Collect source and prepare
159function install_placement {
160 install_apache_wsgi
Roman Podoliakaa066abe2017-04-18 16:18:14 +0300161 # Install the openstackclient placement client plugin for CLI
Chris Dent78a564b2018-10-05 10:17:56 +0100162 pip_install_gr osc-placement
163 git_clone $PLACEMENT_REPO $PLACEMENT_DIR $PLACEMENT_BRANCH
164 setup_develop $PLACEMENT_DIR
Chris Dent4d601752016-07-12 19:34:09 +0000165}
166
167# start_placement_api() - Start the API processes ahead of other things
168function start_placement_api {
Sean Dague64ffff92017-04-13 13:36:42 -0400169 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
Davanum Srinivasaceb27e2017-08-17 08:59:59 -0400170 run_process "placement-api" "$PLACEMENT_BIN_DIR/uwsgi --procname-prefix placement --ini $PLACEMENT_UWSGI_CONF"
Sean Dague64ffff92017-04-13 13:36:42 -0400171 else
172 enable_apache_site placement-api
173 restart_apache_server
174 tail_log placement-api /var/log/$APACHE_NAME/placement-api.log
175 fi
Chris Dent4d601752016-07-12 19:34:09 +0000176
177 echo "Waiting for placement-api to start..."
178 if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
179 die $LINENO "placement-api did not start"
180 fi
181}
182
183function start_placement {
184 start_placement_api
185}
186
187# stop_placement() - Disable the api service and stop it.
188function stop_placement {
Sean Dague64ffff92017-04-13 13:36:42 -0400189 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
190 stop_process "placement-api"
Sean Dague64ffff92017-04-13 13:36:42 -0400191 else
192 disable_apache_site placement-api
193 restart_apache_server
194 fi
Chris Dent4d601752016-07-12 19:34:09 +0000195}
196
197# Restore xtrace
198$_XTRACE_LIB_PLACEMENT
199
200# Tell emacs to use shell-script-mode
201## Local variables:
202## mode: shell-script
203## End: