Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # lib/placement |
| 4 | # Functions to control the configuration and operation of the **Placement** service |
| 5 | # |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 6 | |
| 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) |
| 24 | set +o xtrace |
| 25 | |
| 26 | # Defaults |
| 27 | # -------- |
| 28 | |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 29 | PLACEMENT_DIR=$DEST/placement |
| 30 | PLACEMENT_CONF_DIR=/etc/placement |
| 31 | PLACEMENT_CONF=$PLACEMENT_CONF_DIR/placement.conf |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 32 | PLACEMENT_AUTH_STRATEGY=${PLACEMENT_AUTH_STRATEGY:-keystone} |
| 33 | # Placement virtual environment |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 34 | if [[ ${USE_VENV} = True ]]; then |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 35 | PROJECT_VENV["placement"]=${PLACEMENT_DIR}.venv |
| 36 | PLACEMENT_BIN_DIR=${PROJECT_VENV["placement"]}/bin |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 37 | else |
| 38 | PLACEMENT_BIN_DIR=$(get_python_exec_prefix) |
| 39 | fi |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 40 | PLACEMENT_UWSGI=$PLACEMENT_BIN_DIR/placement-api |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 41 | PLACEMENT_UWSGI_CONF=$PLACEMENT_CONF_DIR/placement-uwsgi.ini |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 42 | |
Sean Dague | f3b2f4c | 2017-04-13 10:11:48 -0400 | [diff] [blame] | 43 | if is_service_enabled tls-proxy; then |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 44 | PLACEMENT_SERVICE_PROTOCOL="https" |
| 45 | fi |
| 46 | |
| 47 | # Public facing bits |
| 48 | PLACEMENT_SERVICE_PROTOCOL=${PLACEMENT_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL} |
| 49 | PLACEMENT_SERVICE_HOST=${PLACEMENT_SERVICE_HOST:-$SERVICE_HOST} |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 50 | |
Ghanshyam Mann | 16c2b38 | 2022-11-30 14:24:07 -0600 | [diff] [blame] | 51 | # 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 |
| 55 | PLACEMENT_ENFORCE_SCOPE=$(trueorfalse False PLACEMENT_ENFORCE_SCOPE) |
| 56 | |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 57 | # Functions |
| 58 | # --------- |
| 59 | |
| 60 | # Test if any placement services are enabled |
| 61 | # is_placement_enabled |
| 62 | function is_placement_enabled { |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 63 | [[ ,${ENABLED_SERVICES} =~ ,"placement-api" ]] && return 0 |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 64 | 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 |
| 69 | function cleanup_placement { |
| 70 | sudo rm -f $(apache_site_config_for placement-api) |
Chris Dent | 1489b9e | 2017-12-05 23:46:58 +0000 | [diff] [blame] | 71 | remove_uwsgi_config "$PLACEMENT_UWSGI_CONF" "$PLACEMENT_UWSGI" |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | # _config_placement_apache_wsgi() - Set WSGI config files |
| 75 | function _config_placement_apache_wsgi { |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 76 | local placement_api_apache_conf |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 77 | local venv_path="" |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 78 | local placement_bin_dir="" |
| 79 | placement_bin_dir=$(get_python_exec_prefix) |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 80 | placement_api_apache_conf=$(apache_site_config_for placement-api) |
| 81 | |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 82 | if [[ ${USE_VENV} = True ]]; then |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 83 | venv_path="python-path=${PROJECT_VENV["placement"]}/lib/$(python_version)/site-packages" |
| 84 | placement_bin_dir=${PROJECT_VENV["placement"]}/bin |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 85 | fi |
| 86 | |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 87 | sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf |
| 88 | sudo sed -e " |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 89 | s|%APACHE_NAME%|$APACHE_NAME|g; |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 90 | s|%PUBLICWSGI%|$placement_bin_dir/placement-api|g; |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 91 | 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 Dent | 3027c20 | 2018-11-20 22:18:26 +0000 | [diff] [blame] | 100 | # create_placement_conf() - Write config |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 101 | function 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 Mueller | 8ab64b3 | 2017-11-17 19:52:29 +0100 | [diff] [blame] | 106 | configure_keystone_authtoken_middleware $PLACEMENT_CONF placement |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 107 | setup_logging $PLACEMENT_CONF |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 108 | } |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 109 | |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 110 | # configure_placement() - Set config files, create data dirs, etc |
| 111 | function configure_placement { |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 112 | sudo install -d -o $STACK_USER $PLACEMENT_CONF_DIR |
| 113 | create_placement_conf |
Chris Dent | e0be9e3 | 2017-04-18 16:52:25 +0100 | [diff] [blame] | 114 | |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 115 | 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 Mann | 16c2b38 | 2022-11-30 14:24:07 -0600 | [diff] [blame] | 120 | 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 Mann | 69d71cf | 2023-01-10 20:13:47 -0600 | [diff] [blame] | 123 | else |
| 124 | iniset $PLACEMENT_CONF oslo_policy enforce_new_defaults False |
| 125 | iniset $PLACEMENT_CONF oslo_policy enforce_scope False |
Ghanshyam Mann | 16c2b38 | 2022-11-30 14:24:07 -0600 | [diff] [blame] | 126 | fi |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | # create_placement_accounts() - Set up required placement accounts |
| 130 | # and service and endpoints. |
| 131 | function 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 Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 138 | "$placement_api_url" |
| 139 | } |
| 140 | |
| 141 | # init_placement() - Create service user and endpoints |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 142 | function init_placement { |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 143 | recreate_database placement |
| 144 | $PLACEMENT_BIN_DIR/placement-manage db sync |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 145 | create_placement_accounts |
| 146 | } |
| 147 | |
| 148 | # install_placement() - Collect source and prepare |
| 149 | function install_placement { |
| 150 | install_apache_wsgi |
Roman Podoliaka | a066abe | 2017-04-18 16:18:14 +0300 | [diff] [blame] | 151 | # Install the openstackclient placement client plugin for CLI |
Chris Dent | 78a564b | 2018-10-05 10:17:56 +0100 | [diff] [blame] | 152 | pip_install_gr osc-placement |
| 153 | git_clone $PLACEMENT_REPO $PLACEMENT_DIR $PLACEMENT_BRANCH |
| 154 | setup_develop $PLACEMENT_DIR |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | # start_placement_api() - Start the API processes ahead of other things |
| 158 | function start_placement_api { |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 159 | if [[ "$WSGI_MODE" == "uwsgi" ]]; then |
Ian Wienand | 312517d | 2018-06-22 22:23:29 +1000 | [diff] [blame] | 160 | run_process "placement-api" "$(which uwsgi) --procname-prefix placement --ini $PLACEMENT_UWSGI_CONF" |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 161 | else |
| 162 | enable_apache_site placement-api |
| 163 | restart_apache_server |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 164 | fi |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 165 | |
| 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 | |
| 172 | function start_placement { |
| 173 | start_placement_api |
| 174 | } |
| 175 | |
| 176 | # stop_placement() - Disable the api service and stop it. |
| 177 | function stop_placement { |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 178 | if [[ "$WSGI_MODE" == "uwsgi" ]]; then |
| 179 | stop_process "placement-api" |
Sean Dague | 64ffff9 | 2017-04-13 13:36:42 -0400 | [diff] [blame] | 180 | else |
| 181 | disable_apache_site placement-api |
| 182 | restart_apache_server |
| 183 | fi |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 184 | } |
| 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: |