blob: c6bf99f868bcc32cc857e76e3652078d2f73c9c5 [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
Ghanshyam Mann16c2b382022-11-30 14:24:07 -060051# Flag to set the oslo_policy.enforce_scope and oslo_policy.enforce_new_defaults.
52# This is used to switch the Placement API policies scope and new defaults.
53# By Default, these flag are False.
54# For more detail: https://docs.openstack.org/oslo.policy/latest/configuration/index.html#oslo_policy.enforce_scope
55PLACEMENT_ENFORCE_SCOPE=$(trueorfalse False PLACEMENT_ENFORCE_SCOPE)
56
Chris Dent4d601752016-07-12 19:34:09 +000057# Functions
58# ---------
59
60# Test if any placement services are enabled
61# is_placement_enabled
62function is_placement_enabled {
Sean Dague51a225c2016-12-15 16:32:08 -050063 [[ ,${ENABLED_SERVICES} =~ ,"placement-api" ]] && return 0
Chris Dent4d601752016-07-12 19:34:09 +000064 return 1
65}
66
67# cleanup_placement() - Remove residual data files, anything left over from previous
68# runs that a clean run would need to clean up
69function cleanup_placement {
70 sudo rm -f $(apache_site_config_for placement-api)
Chris Dent1489b9e2017-12-05 23:46:58 +000071 remove_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI"
Chris Dent4d601752016-07-12 19:34:09 +000072}
73
74# _config_placement_apache_wsgi() - Set WSGI config files
75function _config_placement_apache_wsgi {
Chris Dent4d601752016-07-12 19:34:09 +000076 local placement_api_apache_conf
Chris Dent4d601752016-07-12 19:34:09 +000077 local venv_path=""
Chris Dent78a564b2018-10-05 10:17:56 +010078 local placement_bin_dir=""
79 placement_bin_dir=$(get_python_exec_prefix)
Chris Dent4d601752016-07-12 19:34:09 +000080 placement_api_apache_conf=$(apache_site_config_for placement-api)
81
Chris Dent4d601752016-07-12 19:34:09 +000082 if [[ ${USE_VENV} = True ]]; then
Chris Dent78a564b2018-10-05 10:17:56 +010083 venv_path="python-path=${PROJECT_VENV["placement"]}/lib/$(python_version)/site-packages"
84 placement_bin_dir=${PROJECT_VENV["placement"]}/bin
Chris Dent4d601752016-07-12 19:34:09 +000085 fi
86
Chris Dent4d601752016-07-12 19:34:09 +000087 sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
88 sudo sed -e "
Chris Dent4d601752016-07-12 19:34:09 +000089 s|%APACHE_NAME%|$APACHE_NAME|g;
Chris Dent78a564b2018-10-05 10:17:56 +010090 s|%PUBLICWSGI%|$placement_bin_dir/placement-api|g;
Chris Dent4d601752016-07-12 19:34:09 +000091 s|%SSLENGINE%|$placement_ssl|g;
92 s|%SSLCERTFILE%|$placement_certfile|g;
93 s|%SSLKEYFILE%|$placement_keyfile|g;
94 s|%USER%|$STACK_USER|g;
95 s|%VIRTUALENV%|$venv_path|g
96 s|%APIWORKERS%|$API_WORKERS|g
97 " -i $placement_api_apache_conf
98}
99
Chris Dent3027c202018-11-20 22:18:26 +0000100# create_placement_conf() - Write config
Chris Dent78a564b2018-10-05 10:17:56 +0100101function create_placement_conf {
102 rm -f $PLACEMENT_CONF
103 iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
104 iniset $PLACEMENT_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
105 iniset $PLACEMENT_CONF api auth_strategy $PLACEMENT_AUTH_STRATEGY
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100106 configure_keystone_authtoken_middleware $PLACEMENT_CONF placement
Chris Dent78a564b2018-10-05 10:17:56 +0100107 setup_logging $PLACEMENT_CONF
Sean Dague51a225c2016-12-15 16:32:08 -0500108}
Chris Dent4d601752016-07-12 19:34:09 +0000109
Sean Dague51a225c2016-12-15 16:32:08 -0500110# configure_placement() - Set config files, create data dirs, etc
111function configure_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100112 sudo install -d -o $STACK_USER $PLACEMENT_CONF_DIR
113 create_placement_conf
Chris Dente0be9e32017-04-18 16:52:25 +0100114
Sean Dague64ffff92017-04-13 13:36:42 -0400115 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
116 write_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" "/placement"
117 else
118 _config_placement_apache_wsgi
119 fi
Ghanshyam Mann16c2b382022-11-30 14:24:07 -0600120 if [[ "$PLACEMENT_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == "True" ]]; then
121 iniset $PLACEMENT_CONF oslo_policy enforce_new_defaults True
122 iniset $PLACEMENT_CONF oslo_policy enforce_scope True
Ghanshyam Mann69d71cf2023-01-10 20:13:47 -0600123 else
124 iniset $PLACEMENT_CONF oslo_policy enforce_new_defaults False
125 iniset $PLACEMENT_CONF oslo_policy enforce_scope False
Ghanshyam Mann16c2b382022-11-30 14:24:07 -0600126 fi
Chris Dent4d601752016-07-12 19:34:09 +0000127}
128
129# create_placement_accounts() - Set up required placement accounts
130# and service and endpoints.
131function create_placement_accounts {
132 create_service_user "placement" "admin"
133 local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
134 get_or_create_service "placement" "placement" "Placement Service"
135 get_or_create_endpoint \
136 "placement" \
137 "$REGION_NAME" \
Chris Dent4d601752016-07-12 19:34:09 +0000138 "$placement_api_url"
139}
140
141# init_placement() - Create service user and endpoints
Chris Dent4d601752016-07-12 19:34:09 +0000142function init_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100143 recreate_database placement
144 $PLACEMENT_BIN_DIR/placement-manage db sync
Chris Dent4d601752016-07-12 19:34:09 +0000145 create_placement_accounts
146}
147
148# install_placement() - Collect source and prepare
149function install_placement {
150 install_apache_wsgi
Roman Podoliakaa066abe2017-04-18 16:18:14 +0300151 # Install the openstackclient placement client plugin for CLI
Chris Dent78a564b2018-10-05 10:17:56 +0100152 pip_install_gr osc-placement
153 git_clone $PLACEMENT_REPO $PLACEMENT_DIR $PLACEMENT_BRANCH
154 setup_develop $PLACEMENT_DIR
Chris Dent4d601752016-07-12 19:34:09 +0000155}
156
157# start_placement_api() - Start the API processes ahead of other things
158function start_placement_api {
Sean Dague64ffff92017-04-13 13:36:42 -0400159 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
Ian Wienand312517d2018-06-22 22:23:29 +1000160 run_process "placement-api" "$(which uwsgi) --procname-prefix placement --ini $PLACEMENT_UWSGI_CONF"
Sean Dague64ffff92017-04-13 13:36:42 -0400161 else
162 enable_apache_site placement-api
163 restart_apache_server
Sean Dague64ffff92017-04-13 13:36:42 -0400164 fi
Chris Dent4d601752016-07-12 19:34:09 +0000165
166 echo "Waiting for placement-api to start..."
167 if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
168 die $LINENO "placement-api did not start"
169 fi
170}
171
172function start_placement {
173 start_placement_api
174}
175
176# stop_placement() - Disable the api service and stop it.
177function stop_placement {
Sean Dague64ffff92017-04-13 13:36:42 -0400178 if [[ "$WSGI_MODE" == "uwsgi" ]]; then
179 stop_process "placement-api"
Sean Dague64ffff92017-04-13 13:36:42 -0400180 else
181 disable_apache_site placement-api
182 restart_apache_server
183 fi
Chris Dent4d601752016-07-12 19:34:09 +0000184}
185
186# Restore xtrace
187$_XTRACE_LIB_PLACEMENT
188
189# Tell emacs to use shell-script-mode
190## Local variables:
191## mode: shell-script
192## End: