blob: 4e80c55c264831d5fbbcb30627be506c32bebbce [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#
6# Currently the placement service is embedded in nova. Eventually we
7# expect this to change so this file is started as a separate entity
8# despite making use of some *NOVA* variables and files.
9
10# Dependencies:
11#
12# - ``functions`` file
13# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
14# - ``FILES``
15
16# ``stack.sh`` calls the entry points in this order:
17#
18# - install_placement
19# - cleanup_placement
20# - configure_placement
21# - init_placement
22# - start_placement
23# - stop_placement
24
25# Save trace setting
26_XTRACE_LIB_PLACEMENT=$(set +o | grep xtrace)
27set +o xtrace
28
29# Defaults
30# --------
31
32PLACEMENT_CONF_DIR=/etc/nova
33PLACEMENT_CONF=$PLACEMENT_CONF_DIR/nova.conf
34PLACEMENT_AUTH_STRATEGY=${PLACEMENT_AUTH_STRATEGY:-placement}
35
36
37# The placement service can optionally use a separate database
38# connection. Set PLACEMENT_DB_ENABLED to True to use it.
39# NOTE(cdent): This functionality depends on some code that is not
40# yet merged in nova but is coming soon.
41PLACEMENT_DB_ENABLED=$(trueorfalse False PLACEMENT_DB_ENABLED)
42
43if is_suse; then
44 PLACEMENT_WSGI_DIR=${PLACEMENT_WSGI_DIR:-/srv/www/htdocs/placement}
45else
46 PLACEMENT_WSGI_DIR=${PLACEMENT_WSGI_DIR:-/var/www/placement}
47fi
48
49if is_ssl_enabled_service "placement-api" || is_service_enabled tls-proxy; then
50 PLACEMENT_SERVICE_PROTOCOL="https"
51fi
52
53# Public facing bits
54PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
55PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST}
56PLACEMENT_SERVICE_PORT=${PLACEMENT_SERVICE_PORT:-8778}
57
58# Functions
59# ---------
60
61# Test if any placement services are enabled
62# is_placement_enabled
63function is_placement_enabled {
64 [[ ,${ENABLED_SERVICES} =~ ,"placement-" ]] && return 0
65 return 1
66}
67
68# cleanup_placement() - Remove residual data files, anything left over from previous
69# runs that a clean run would need to clean up
70function cleanup_placement {
71 sudo rm -f $(apache_site_config_for placement-api)
72}
73
74# _config_placement_apache_wsgi() - Set WSGI config files
75function _config_placement_apache_wsgi {
76 sudo mkdir -p $PLACEMENT_WSGI_DIR
77
78 local placement_api_apache_conf
79 local placement_api_port=$PLACEMENT_SERVICE_PORT
80 local venv_path=""
81 placement_api_apache_conf=$(apache_site_config_for placement-api)
82
83 # reuse nova's cert if a cert is being used
84 if is_ssl_enabled_service "placement-api"; then
85 placement_ssl="SSLEngine On"
86 placement_certfile="SSLCertificateFile $NOVA_SSL_CERT"
87 placement_keyfile="SSLCertificateKeyFile $NOVA_SSL_KEY"
88 fi
89 # reuse nova's venv if there is one as placement code lives
90 # there
91 if [[ ${USE_VENV} = True ]]; then
92 venv_path="python-path=${PROJECT_VENV["nova"]}/lib/$(python_version)/site-packages"
93 fi
94
95 # copy wsgi application file
96 sudo cp $NOVA_DIR/nova/api/openstack/placement/placement-api.py $PLACEMENT_WSGI_DIR/placement-api
97
98 sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
99 sudo sed -e "
100 s|%PUBLICPORT%|$placement_api_port|g;
101 s|%APACHE_NAME%|$APACHE_NAME|g;
102 s|%PUBLICWSGI%|$PLACEMENT_WSGI_DIR/placement-api|g;
103 s|%SSLENGINE%|$placement_ssl|g;
104 s|%SSLCERTFILE%|$placement_certfile|g;
105 s|%SSLKEYFILE%|$placement_keyfile|g;
106 s|%USER%|$STACK_USER|g;
107 s|%VIRTUALENV%|$venv_path|g
108 s|%APIWORKERS%|$API_WORKERS|g
109 " -i $placement_api_apache_conf
110}
111
112# configure_placement() - Set config files, create data dirs, etc
113function configure_placement {
114 if [ "$PLACEMENT_DB_ENABLED" != False ]; then
115 iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
116 fi
117
118 iniset $NOVA_CONF placement auth_type "password"
119 iniset $NOVA_CONF placement auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v3"
120 iniset $NOVA_CONF placement username placement
121 iniset $NOVA_CONF placement password "$SERVICE_PASSWORD"
122 iniset $NOVA_CONF placement user_domain_name "Default"
123 iniset $NOVA_CONF placement project_name "$SERVICE_TENANT_NAME"
124 iniset $NOVA_CONF placement project_domain_name "Default"
125 iniset $NOVA_CONF placement region_name "$REGION_NAME"
126 # TODO(cdent): auth_strategy, which is common to see in these
127 # blocks is not currently used here. For the time being the
128 # placement api uses the auth_strategy configuration setting
129 # established by the nova api. This avoids, for the time, being,
130 # creating redundant configuration items that are just used for
131 # testing.
132
133 _config_placement_apache_wsgi
134}
135
136# create_placement_accounts() - Set up required placement accounts
137# and service and endpoints.
138function create_placement_accounts {
139 create_service_user "placement" "admin"
140 local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
141 get_or_create_service "placement" "placement" "Placement Service"
142 get_or_create_endpoint \
143 "placement" \
144 "$REGION_NAME" \
145 "$placement_api_url" \
146 "$placement_api_url" \
147 "$placement_api_url"
148}
149
150# init_placement() - Create service user and endpoints
151# If PLACEMENT_DB_ENABLED is true, create the separate placement db
152# using, for now, the api_db migrations.
153function init_placement {
154 if [ "$PLACEMENT_DB_ENABLED" != False ]; then
155 recreate_database placement
156 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
157 fi
158 create_placement_accounts
159}
160
161# install_placement() - Collect source and prepare
162function install_placement {
163 install_apache_wsgi
164 if is_ssl_enabled_service "placement-api"; then
165 enable_mod_ssl
166 fi
167}
168
169# start_placement_api() - Start the API processes ahead of other things
170function start_placement_api {
171 # Get right service port for testing
172 local service_port=$PLACEMENT_SERVICE_PORT
173 local placement_api_port=$PLACEMENT_SERVICE_PORT
174
175 enable_apache_site placement-api
176 restart_apache_server
177 tail_log placement-api /var/log/$APACHE_NAME/placement-api.log
178
179 echo "Waiting for placement-api to start..."
180 if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
181 die $LINENO "placement-api did not start"
182 fi
183}
184
185function start_placement {
186 start_placement_api
187}
188
189# stop_placement() - Disable the api service and stop it.
190function stop_placement {
191 disable_apache_site placement-api
192 restart_apache_server
193}
194
195# Restore xtrace
196$_XTRACE_LIB_PLACEMENT
197
198# Tell emacs to use shell-script-mode
199## Local variables:
200## mode: shell-script
201## End: