blob: ff630e29d8b5675251ba9ec2a9adee8086498a85 [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
Chris Dent4d601752016-07-12 19:34:09 +000043if is_ssl_enabled_service "placement-api" || is_service_enabled tls-proxy; then
44 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}
50PLACEMENT_SERVICE_PORT=${PLACEMENT_SERVICE_PORT:-8778}
51
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)
66}
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
71 local placement_api_port=$PLACEMENT_SERVICE_PORT
72 local venv_path=""
Sean Dague43ff27b2016-08-30 21:13:15 -040073 local nova_bin_dir=""
74 nova_bin_dir=$(get_python_exec_prefix)
Chris Dent4d601752016-07-12 19:34:09 +000075 placement_api_apache_conf=$(apache_site_config_for placement-api)
76
77 # reuse nova's cert if a cert is being used
78 if is_ssl_enabled_service "placement-api"; then
79 placement_ssl="SSLEngine On"
80 placement_certfile="SSLCertificateFile $NOVA_SSL_CERT"
81 placement_keyfile="SSLCertificateKeyFile $NOVA_SSL_KEY"
82 fi
83 # reuse nova's venv if there is one as placement code lives
84 # there
85 if [[ ${USE_VENV} = True ]]; then
86 venv_path="python-path=${PROJECT_VENV["nova"]}/lib/$(python_version)/site-packages"
Sean Dague43ff27b2016-08-30 21:13:15 -040087 nova_bin_dir=${PROJECT_VENV["nova"]}/bin
Chris Dent4d601752016-07-12 19:34:09 +000088 fi
89
Chris Dent4d601752016-07-12 19:34:09 +000090 sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf
91 sudo sed -e "
92 s|%PUBLICPORT%|$placement_api_port|g;
93 s|%APACHE_NAME%|$APACHE_NAME|g;
Sean Dague43ff27b2016-08-30 21:13:15 -040094 s|%PUBLICWSGI%|$nova_bin_dir/nova-placement-api|g;
Chris Dent4d601752016-07-12 19:34:09 +000095 s|%SSLENGINE%|$placement_ssl|g;
96 s|%SSLCERTFILE%|$placement_certfile|g;
97 s|%SSLKEYFILE%|$placement_keyfile|g;
98 s|%USER%|$STACK_USER|g;
99 s|%VIRTUALENV%|$venv_path|g
100 s|%APIWORKERS%|$API_WORKERS|g
101 " -i $placement_api_apache_conf
102}
103
Sean Dague51a225c2016-12-15 16:32:08 -0500104function configure_placement_nova_compute {
Chris Dent4d601752016-07-12 19:34:09 +0000105 iniset $NOVA_CONF placement auth_type "password"
106 iniset $NOVA_CONF placement auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v3"
107 iniset $NOVA_CONF placement username placement
108 iniset $NOVA_CONF placement password "$SERVICE_PASSWORD"
109 iniset $NOVA_CONF placement user_domain_name "Default"
110 iniset $NOVA_CONF placement project_name "$SERVICE_TENANT_NAME"
111 iniset $NOVA_CONF placement project_domain_name "Default"
Matt Riedemann44bf88c2016-08-31 10:39:46 -0400112 iniset $NOVA_CONF placement os_region_name "$REGION_NAME"
Chris Dent4d601752016-07-12 19:34:09 +0000113 # TODO(cdent): auth_strategy, which is common to see in these
114 # blocks is not currently used here. For the time being the
115 # placement api uses the auth_strategy configuration setting
116 # established by the nova api. This avoids, for the time, being,
117 # creating redundant configuration items that are just used for
118 # testing.
Sean Dague51a225c2016-12-15 16:32:08 -0500119}
Chris Dent4d601752016-07-12 19:34:09 +0000120
Sean Dague51a225c2016-12-15 16:32:08 -0500121# configure_placement() - Set config files, create data dirs, etc
122function configure_placement {
123 if [ "$PLACEMENT_DB_ENABLED" != False ]; then
124 iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
125 fi
Chris Dent4d601752016-07-12 19:34:09 +0000126 _config_placement_apache_wsgi
127}
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" \
138 "$placement_api_url" \
139 "$placement_api_url" \
140 "$placement_api_url"
141}
142
143# init_placement() - Create service user and endpoints
144# If PLACEMENT_DB_ENABLED is true, create the separate placement db
145# using, for now, the api_db migrations.
146function init_placement {
147 if [ "$PLACEMENT_DB_ENABLED" != False ]; then
148 recreate_database placement
149 $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync
150 fi
151 create_placement_accounts
152}
153
154# install_placement() - Collect source and prepare
155function install_placement {
156 install_apache_wsgi
157 if is_ssl_enabled_service "placement-api"; then
158 enable_mod_ssl
159 fi
160}
161
162# start_placement_api() - Start the API processes ahead of other things
163function start_placement_api {
164 # Get right service port for testing
165 local service_port=$PLACEMENT_SERVICE_PORT
166 local placement_api_port=$PLACEMENT_SERVICE_PORT
167
168 enable_apache_site placement-api
169 restart_apache_server
170 tail_log placement-api /var/log/$APACHE_NAME/placement-api.log
171
172 echo "Waiting for placement-api to start..."
173 if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
174 die $LINENO "placement-api did not start"
175 fi
176}
177
178function start_placement {
179 start_placement_api
180}
181
182# stop_placement() - Disable the api service and stop it.
183function stop_placement {
184 disable_apache_site placement-api
185 restart_apache_server
186}
187
188# Restore xtrace
189$_XTRACE_LIB_PLACEMENT
190
191# Tell emacs to use shell-script-mode
192## Local variables:
193## mode: shell-script
194## End: