Skip to content

Commit 4d60175

Browse files
committed
Add support for placement API to devstack
Uses lib/placement, but relies on some functionality from lib/nova. This leads to some weirdness since the nova has special status in stack.sh. If/when placement is extracted it may be good to follow the devstack plugin structure instead. Because the placement code is currently a part of nova, there are dependencies in lib/placement on a some $NOVA_* variable and, if virtenv is being used, the virtualenv used by nova. Because placement currently runs using nova's configuration settings, not a lot actually happens in lib/placement: apache is configured and keystone accounts and endpoints are created. If PLACEMENT_DB_ENABLED is true then a separate placement db will be configured. When complete the initial version of the placement service will provide support for managing resource providers, inventories and allocations. The placement api only runs under mod-wsgi. Change-Id: I53dd3e6b41de17387a0e179fc9ac64c143b6a9eb
1 parent 23fc4e0 commit 4d60175

5 files changed

Lines changed: 249 additions & 0 deletions

File tree

clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ source $TOP_DIR/lib/horizon
4646
source $TOP_DIR/lib/keystone
4747
source $TOP_DIR/lib/glance
4848
source $TOP_DIR/lib/nova
49+
source $TOP_DIR/lib/placement
4950
source $TOP_DIR/lib/cinder
5051
source $TOP_DIR/lib/swift
5152
source $TOP_DIR/lib/heat
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Listen %PUBLICPORT%
2+
3+
<VirtualHost *:%PUBLICPORT%>
4+
WSGIDaemonProcess placement-api processes=%APIWORKERS% threads=1 user=%USER% display-name=%{GROUP} %VIRTUALENV%
5+
WSGIProcessGroup placement-api
6+
WSGIScriptAlias / %PUBLICWSGI%
7+
WSGIApplicationGroup %{GLOBAL}
8+
WSGIPassAuthorization On
9+
<IfVersion >= 2.4>
10+
ErrorLogFormat "%M"
11+
</IfVersion>
12+
ErrorLog /var/log/%APACHE_NAME%/placement-api.log
13+
%SSLENGINE%
14+
%SSLCERTFILE%
15+
%SSLKEYFILE%
16+
</VirtualHost>
17+
18+
Alias /placement %PUBLICWSGI%
19+
<Location /placement>
20+
SetHandler wsgi-script
21+
Options +ExecCGI
22+
WSGIProcessGroup placement-api
23+
WSGIApplicationGroup %{GLOBAL}
24+
WSGIPassAuthorization On
25+
</Location>

lib/placement

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/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)
27+
set +o xtrace
28+
29+
# Defaults
30+
# --------
31+
32+
PLACEMENT_CONF_DIR=/etc/nova
33+
PLACEMENT_CONF=$PLACEMENT_CONF_DIR/nova.conf
34+
PLACEMENT_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.
41+
PLACEMENT_DB_ENABLED=$(trueorfalse False PLACEMENT_DB_ENABLED)
42+
43+
if is_suse; then
44+
PLACEMENT_WSGI_DIR=${PLACEMENT_WSGI_DIR:-/srv/www/htdocs/placement}
45+
else
46+
PLACEMENT_WSGI_DIR=${PLACEMENT_WSGI_DIR:-/var/www/placement}
47+
fi
48+
49+
if is_ssl_enabled_service "placement-api" || is_service_enabled tls-proxy; then
50+
PLACEMENT_SERVICE_PROTOCOL="https"
51+
fi
52+
53+
# Public facing bits
54+
PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
55+
PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST}
56+
PLACEMENT_SERVICE_PORT=${PLACEMENT_SERVICE_PORT:-8778}
57+
58+
# Functions
59+
# ---------
60+
61+
# Test if any placement services are enabled
62+
# is_placement_enabled
63+
function 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
70+
function cleanup_placement {
71+
sudo rm -f $(apache_site_config_for placement-api)
72+
}
73+
74+
# _config_placement_apache_wsgi() - Set WSGI config files
75+
function _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
113+
function 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.
138+
function 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.
153+
function 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
162+
function 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
170+
function 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+
185+
function start_placement {
186+
start_placement_api
187+
}
188+
189+
# stop_placement() - Disable the api service and stop it.
190+
function 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:

stack.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ source $TOP_DIR/lib/horizon
569569
source $TOP_DIR/lib/keystone
570570
source $TOP_DIR/lib/glance
571571
source $TOP_DIR/lib/nova
572+
source $TOP_DIR/lib/placement
572573
source $TOP_DIR/lib/cinder
573574
source $TOP_DIR/lib/swift
574575
source $TOP_DIR/lib/heat
@@ -859,6 +860,13 @@ if is_service_enabled nova; then
859860
configure_nova
860861
fi
861862

863+
if is_service_enabled placement; then
864+
# placement api
865+
stack_install_service placement
866+
cleanup_placement
867+
configure_placement
868+
fi
869+
862870
if is_service_enabled horizon; then
863871
# django openstack_auth
864872
install_django_openstack_auth
@@ -1160,6 +1168,11 @@ if is_service_enabled nova; then
11601168
init_nova_cells
11611169
fi
11621170

1171+
if is_service_enabled placement; then
1172+
echo_summary "Configuring placement"
1173+
init_placement
1174+
fi
1175+
11631176

11641177
# Extras Configuration
11651178
# ====================
@@ -1265,6 +1278,10 @@ if is_service_enabled nova; then
12651278
start_nova
12661279
create_flavors
12671280
fi
1281+
if is_service_enabled placement; then
1282+
echo_summary "Starting Placement"
1283+
start_placement
1284+
fi
12681285
if is_service_enabled cinder; then
12691286
echo_summary "Starting Cinder"
12701287
start_cinder

unstack.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ source $TOP_DIR/lib/horizon
6363
source $TOP_DIR/lib/keystone
6464
source $TOP_DIR/lib/glance
6565
source $TOP_DIR/lib/nova
66+
source $TOP_DIR/lib/placement
6667
source $TOP_DIR/lib/cinder
6768
source $TOP_DIR/lib/swift
6869
source $TOP_DIR/lib/heat
@@ -111,6 +112,10 @@ if is_service_enabled nova; then
111112
stop_nova
112113
fi
113114

115+
if is_service_enabled placement; then
116+
stop_placement
117+
fi
118+
114119
if is_service_enabled glance; then
115120
stop_glance
116121
fi

0 commit comments

Comments
 (0)