blob: b7798669a1b88f0c945bcf4211b825d1b407eb2e [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
Chris Dent78a564b2018-10-05 10:17:56 +010032PLACEMENT_AUTH_STRATEGY=${PLACEMENT_AUTH_STRATEGY:-keystone}
33# Placement virtual environment
Sean Dague64ffff92017-04-13 13:36:42 -040034if [[ ${USE_VENV} = True ]]; then
Chris Dent78a564b2018-10-05 10:17:56 +010035 PROJECT_VENV["placement"]=${PLACEMENT_DIR}.venv
36 PLACEMENT_BIN_DIR=${PROJECT_VENV["placement"]}/bin
Sean Dague64ffff92017-04-13 13:36:42 -040037else
38 PLACEMENT_BIN_DIR=$(get_python_exec_prefix)
39fi
Chris Dent78a564b2018-10-05 10:17:56 +010040PLACEMENT_UWSGI=$PLACEMENT_BIN_DIR/placement-api
Sean Dague64ffff92017-04-13 13:36:42 -040041PLACEMENT_UWSGI_CONF=$PLACEMENT_CONF_DIR/placement-uwsgi.ini
Chris Dent4d601752016-07-12 19:34:09 +000042
Sean Daguef3b2f4c2017-04-13 10:11:48 -040043if is_service_enabled tls-proxy; then
Chris Dent4d601752016-07-12 19:34:09 +000044 PLACEMENT_SERVICE_PROTOCOL="https"
45fi
46
47# Public facing bits
48PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
49PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST}
Chris Dent4d601752016-07-12 19:34:09 +000050
51# Functions
52# ---------
53
54# Test if any placement services are enabled
55# is_placement_enabled
56function is_placement_enabled {
Sean Dague51a225c2016-12-15 16:32:08 -050057 [[ ,${ENABLED_SERVICES} =~ ,"placement-api" ]] && return 0
Chris Dent4d601752016-07-12 19:34:09 +000058 return 1
59}
60
61# cleanup_placement() - Remove residual data files, anything left over from previous
62# runs that a clean run would need to clean up
63function cleanup_placement {
64 sudo rm -f $(apache_site_config_for placement-api)
Chris Dent1489b9e2017-12-05 23:46:58 +000065 remove_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI"
Chris Dent4d601752016-07-12 19:34:09 +000066}
67
68# _config_placement_apache_wsgi() - Set WSGI config files
69function _config_placement_apache_wsgi {
Chris Dent4d601752016-07-12 19:34:09 +000070 local placement_api_apache_conf
Chris Dent4d601752016-07-12 19:34:09 +000071 local venv_path=""
Chris Dent78a564b2018-10-05 10:17:56 +010072 local placement_bin_dir=""
73 placement_bin_dir=$(get_python_exec_prefix)
Chris Dent4d601752016-07-12 19:34:09 +000074 placement_api_apache_conf=$(apache_site_config_for placement-api)
75
Chris Dent4d601752016-07-12 19:34:09 +000076 if [[ ${USE_VENV} = True ]]; then
Chris Dent78a564b2018-10-05 10:17:56 +010077 venv_path="python-path=${PROJECT_VENV["placement"]}/lib/$(python_version)/site-packages"
78 placement_bin_dir=${PROJECT_VENV["placement"]}/bin
Chris Dent4d601752016-07-12 19:34:09 +000079 fi
80
Chris Dent4d601752016-07-12 19:34:09 +000081 sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
82 sudo sed -e "
Chris Dent4d601752016-07-12 19:34:09 +000083 s|%APACHE_NAME%|$APACHE_NAME|g;
Chris Dent78a564b2018-10-05 10:17:56 +010084 s|%PUBLICWSGI%|$placement_bin_dir/placement-api|g;
Chris Dent4d601752016-07-12 19:34:09 +000085 s|%SSLENGINE%|$placement_ssl|g;
86 s|%SSLCERTFILE%|$placement_certfile|g;
87 s|%SSLKEYFILE%|$placement_keyfile|g;
88 s|%USER%|$STACK_USER|g;
89 s|%VIRTUALENV%|$venv_path|g
90 s|%APIWORKERS%|$API_WORKERS|g
91 " -i $placement_api_apache_conf
92}
93
Chris Dent3027c202018-11-20 22:18:26 +000094# create_placement_conf() - Write config
Chris Dent78a564b2018-10-05 10:17:56 +010095function create_placement_conf {
96 rm -f $PLACEMENT_CONF
97 iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
98 iniset $PLACEMENT_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
99 iniset $PLACEMENT_CONF api auth_strategy $PLACEMENT_AUTH_STRATEGY
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100100 configure_keystone_authtoken_middleware $PLACEMENT_CONF placement
Chris Dent78a564b2018-10-05 10:17:56 +0100101 setup_logging $PLACEMENT_CONF
Sean Dague51a225c2016-12-15 16:32:08 -0500102}
Chris Dent4d601752016-07-12 19:34:09 +0000103
Sean Dague51a225c2016-12-15 16:32:08 -0500104# configure_placement() - Set config files, create data dirs, etc
105function configure_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100106 sudo install -d -o $STACK_USER $PLACEMENT_CONF_DIR
107 create_placement_conf
Chris Dente0be9e32017-04-18 16:52:25 +0100108
Sean Dague64ffff92017-04-13 13:36:42 -0400109 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
110 write_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" "/placement"
111 else
112 _config_placement_apache_wsgi
113 fi
Chris Dent4d601752016-07-12 19:34:09 +0000114}
115
116# create_placement_accounts() - Set up required placement accounts
117# and service and endpoints.
118function create_placement_accounts {
119 create_service_user "placement" "admin"
120 local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
121 get_or_create_service "placement" "placement" "Placement Service"
122 get_or_create_endpoint \
123 "placement" \
124 "$REGION_NAME" \
Chris Dent4d601752016-07-12 19:34:09 +0000125 "$placement_api_url"
126}
127
128# init_placement() - Create service user and endpoints
Chris Dent4d601752016-07-12 19:34:09 +0000129function init_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100130 recreate_database placement
131 $PLACEMENT_BIN_DIR/placement-manage db sync
Chris Dent4d601752016-07-12 19:34:09 +0000132 create_placement_accounts
133}
134
135# install_placement() - Collect source and prepare
136function install_placement {
137 install_apache_wsgi
Roman Podoliakaa066abe2017-04-18 16:18:14 +0300138 # Install the openstackclient placement client plugin for CLI
Chris Dent78a564b2018-10-05 10:17:56 +0100139 pip_install_gr osc-placement
140 git_clone $PLACEMENT_REPO $PLACEMENT_DIR $PLACEMENT_BRANCH
141 setup_develop $PLACEMENT_DIR
Chris Dent4d601752016-07-12 19:34:09 +0000142}
143
144# start_placement_api() - Start the API processes ahead of other things
145function start_placement_api {
Sean Dague64ffff92017-04-13 13:36:42 -0400146 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
Ian Wienand312517d2018-06-22 22:23:29 +1000147 run_process "placement-api" "$(which uwsgi) --procname-prefix placement --ini $PLACEMENT_UWSGI_CONF"
Sean Dague64ffff92017-04-13 13:36:42 -0400148 else
149 enable_apache_site placement-api
150 restart_apache_server
Sean Dague64ffff92017-04-13 13:36:42 -0400151 fi
Chris Dent4d601752016-07-12 19:34:09 +0000152
153 echo "Waiting for placement-api to start..."
154 if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
155 die $LINENO "placement-api did not start"
156 fi
157}
158
159function start_placement {
160 start_placement_api
161}
162
163# stop_placement() - Disable the api service and stop it.
164function stop_placement {
Sean Dague64ffff92017-04-13 13:36:42 -0400165 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
166 stop_process "placement-api"
Sean Dague64ffff92017-04-13 13:36:42 -0400167 else
168 disable_apache_site placement-api
169 restart_apache_server
170 fi
Chris Dent4d601752016-07-12 19:34:09 +0000171}
172
173# Restore xtrace
174$_XTRACE_LIB_PLACEMENT
175
176# Tell emacs to use shell-script-mode
177## Local variables:
178## mode: shell-script
179## End: