blob: 03aaa0344b08f45abfcde7b7ecbf623d917aae91 [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
Stephen Finucane5bf9d132024-12-09 14:03:44 +000040PLACEMENT_UWSGI=placement.wsgi.api:application
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)
Stephen Finucaned5182ce2024-04-19 12:27:14 +010071 remove_uwsgi_config "$PLACEMENT_UWSGI_CONF" "placement-api"
Chris Dent4d601752016-07-12 19:34:09 +000072}
73
Chris Dent3027c202018-11-20 22:18:26 +000074# create_placement_conf() - Write config
Chris Dent78a564b2018-10-05 10:17:56 +010075function create_placement_conf {
76 rm -f $PLACEMENT_CONF
77 iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement`
78 iniset $PLACEMENT_CONF DEFAULT debug "$ENABLE_DEBUG_LOG_LEVEL"
79 iniset $PLACEMENT_CONF api auth_strategy $PLACEMENT_AUTH_STRATEGY
Dirk Mueller8ab64b32017-11-17 19:52:29 +010080 configure_keystone_authtoken_middleware $PLACEMENT_CONF placement
Chris Dent78a564b2018-10-05 10:17:56 +010081 setup_logging $PLACEMENT_CONF
Sean Dague51a225c2016-12-15 16:32:08 -050082}
Chris Dent4d601752016-07-12 19:34:09 +000083
Sean Dague51a225c2016-12-15 16:32:08 -050084# configure_placement() - Set config files, create data dirs, etc
85function configure_placement {
Chris Dent78a564b2018-10-05 10:17:56 +010086 sudo install -d -o $STACK_USER $PLACEMENT_CONF_DIR
87 create_placement_conf
Chris Dente0be9e32017-04-18 16:52:25 +010088
Stephen Finucane5bf9d132024-12-09 14:03:44 +000089 write_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" "/placement" "" "placement-api"
Ghanshyam Mann16c2b382022-11-30 14:24:07 -060090 if [[ "$PLACEMENT_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == "True" ]]; then
91 iniset $PLACEMENT_CONF oslo_policy enforce_new_defaults True
92 iniset $PLACEMENT_CONF oslo_policy enforce_scope True
Ghanshyam Mann69d71cf2023-01-10 20:13:47 -060093 else
94 iniset $PLACEMENT_CONF oslo_policy enforce_new_defaults False
95 iniset $PLACEMENT_CONF oslo_policy enforce_scope False
Ghanshyam Mann16c2b382022-11-30 14:24:07 -060096 fi
Chris Dent4d601752016-07-12 19:34:09 +000097}
98
99# create_placement_accounts() - Set up required placement accounts
100# and service and endpoints.
101function create_placement_accounts {
102 create_service_user "placement" "admin"
103 local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement"
104 get_or_create_service "placement" "placement" "Placement Service"
105 get_or_create_endpoint \
106 "placement" \
107 "$REGION_NAME" \
Chris Dent4d601752016-07-12 19:34:09 +0000108 "$placement_api_url"
109}
110
111# init_placement() - Create service user and endpoints
Chris Dent4d601752016-07-12 19:34:09 +0000112function init_placement {
Chris Dent78a564b2018-10-05 10:17:56 +0100113 recreate_database placement
114 $PLACEMENT_BIN_DIR/placement-manage db sync
Chris Dent4d601752016-07-12 19:34:09 +0000115 create_placement_accounts
116}
117
118# install_placement() - Collect source and prepare
119function install_placement {
Roman Podoliakaa066abe2017-04-18 16:18:14 +0300120 # Install the openstackclient placement client plugin for CLI
Chris Dent78a564b2018-10-05 10:17:56 +0100121 pip_install_gr osc-placement
122 git_clone $PLACEMENT_REPO $PLACEMENT_DIR $PLACEMENT_BRANCH
123 setup_develop $PLACEMENT_DIR
Chris Dent4d601752016-07-12 19:34:09 +0000124}
125
126# start_placement_api() - Start the API processes ahead of other things
127function start_placement_api {
Stephen Finucanee1465f12024-10-11 15:38:42 +0100128 run_process "placement-api" "$(which uwsgi) --procname-prefix placement --ini $PLACEMENT_UWSGI_CONF"
Chris Dent4d601752016-07-12 19:34:09 +0000129
130 echo "Waiting for placement-api to start..."
131 if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then
132 die $LINENO "placement-api did not start"
133 fi
134}
135
136function start_placement {
137 start_placement_api
138}
139
140# stop_placement() - Disable the api service and stop it.
141function stop_placement {
Stephen Finucanee1465f12024-10-11 15:38:42 +0100142 stop_process "placement-api"
Chris Dent4d601752016-07-12 19:34:09 +0000143}
144
145# Restore xtrace
146$_XTRACE_LIB_PLACEMENT
147
148# Tell emacs to use shell-script-mode
149## Local variables:
150## mode: shell-script
151## End: