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 | # |
| 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 | |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 43 | if is_ssl_enabled_service "placement-api" || is_service_enabled tls-proxy; then |
| 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 | |
| 51 | # Functions |
| 52 | # --------- |
| 53 | |
| 54 | # Test if any placement services are enabled |
| 55 | # is_placement_enabled |
| 56 | function is_placement_enabled { |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 57 | [[ ,${ENABLED_SERVICES} =~ ,"placement-api" ]] && return 0 |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 58 | return 1 |
| 59 | } |
| 60 | |
| 61 | # cleanup_placement() - Remove residual data files, anything left over from previous |
| 62 | # runs that a clean run would need to clean up |
| 63 | function cleanup_placement { |
| 64 | sudo rm -f $(apache_site_config_for placement-api) |
| 65 | } |
| 66 | |
| 67 | # _config_placement_apache_wsgi() - Set WSGI config files |
| 68 | function _config_placement_apache_wsgi { |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 69 | local placement_api_apache_conf |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 70 | local venv_path="" |
Sean Dague | 43ff27b | 2016-08-30 21:13:15 -0400 | [diff] [blame] | 71 | local nova_bin_dir="" |
| 72 | nova_bin_dir=$(get_python_exec_prefix) |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 73 | placement_api_apache_conf=$(apache_site_config_for placement-api) |
| 74 | |
| 75 | # reuse nova's cert if a cert is being used |
| 76 | if is_ssl_enabled_service "placement-api"; then |
| 77 | placement_ssl="SSLEngine On" |
| 78 | placement_certfile="SSLCertificateFile $NOVA_SSL_CERT" |
| 79 | placement_keyfile="SSLCertificateKeyFile $NOVA_SSL_KEY" |
| 80 | fi |
| 81 | # reuse nova's venv if there is one as placement code lives |
| 82 | # there |
| 83 | if [[ ${USE_VENV} = True ]]; then |
| 84 | venv_path="python-path=${PROJECT_VENV["nova"]}/lib/$(python_version)/site-packages" |
Sean Dague | 43ff27b | 2016-08-30 21:13:15 -0400 | [diff] [blame] | 85 | nova_bin_dir=${PROJECT_VENV["nova"]}/bin |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 86 | fi |
| 87 | |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 88 | sudo cp $FILES/apache-placement-api.template $placement_api_apache_conf |
| 89 | sudo sed -e " |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 90 | s|%APACHE_NAME%|$APACHE_NAME|g; |
Sean Dague | 43ff27b | 2016-08-30 21:13:15 -0400 | [diff] [blame] | 91 | s|%PUBLICWSGI%|$nova_bin_dir/nova-placement-api|g; |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 92 | s|%SSLENGINE%|$placement_ssl|g; |
| 93 | s|%SSLCERTFILE%|$placement_certfile|g; |
| 94 | s|%SSLKEYFILE%|$placement_keyfile|g; |
| 95 | s|%USER%|$STACK_USER|g; |
| 96 | s|%VIRTUALENV%|$venv_path|g |
| 97 | s|%APIWORKERS%|$API_WORKERS|g |
| 98 | " -i $placement_api_apache_conf |
| 99 | } |
| 100 | |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 101 | function configure_placement_nova_compute { |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 102 | iniset $NOVA_CONF placement auth_type "password" |
| 103 | iniset $NOVA_CONF placement auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v3" |
| 104 | iniset $NOVA_CONF placement username placement |
| 105 | iniset $NOVA_CONF placement password "$SERVICE_PASSWORD" |
Jens Rosenboom | 80b1d0a | 2017-01-04 16:58:04 +0100 | [diff] [blame] | 106 | iniset $NOVA_CONF placement user_domain_name "$SERVICE_DOMAIN_NAME" |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 107 | iniset $NOVA_CONF placement project_name "$SERVICE_TENANT_NAME" |
Jens Rosenboom | 80b1d0a | 2017-01-04 16:58:04 +0100 | [diff] [blame] | 108 | iniset $NOVA_CONF placement project_domain_name "$SERVICE_DOMAIN_NAME" |
Matt Riedemann | 44bf88c | 2016-08-31 10:39:46 -0400 | [diff] [blame] | 109 | iniset $NOVA_CONF placement os_region_name "$REGION_NAME" |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 110 | # TODO(cdent): auth_strategy, which is common to see in these |
| 111 | # blocks is not currently used here. For the time being the |
| 112 | # placement api uses the auth_strategy configuration setting |
| 113 | # established by the nova api. This avoids, for the time, being, |
| 114 | # creating redundant configuration items that are just used for |
| 115 | # testing. |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 116 | } |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 117 | |
Sean Dague | 51a225c | 2016-12-15 16:32:08 -0500 | [diff] [blame] | 118 | # configure_placement() - Set config files, create data dirs, etc |
| 119 | function configure_placement { |
| 120 | if [ "$PLACEMENT_DB_ENABLED" != False ]; then |
| 121 | iniset $PLACEMENT_CONF placement_database connection `database_connection_url placement` |
| 122 | fi |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 123 | _config_placement_apache_wsgi |
| 124 | } |
| 125 | |
| 126 | # create_placement_accounts() - Set up required placement accounts |
| 127 | # and service and endpoints. |
| 128 | function create_placement_accounts { |
| 129 | create_service_user "placement" "admin" |
| 130 | local placement_api_url="$PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement" |
| 131 | get_or_create_service "placement" "placement" "Placement Service" |
| 132 | get_or_create_endpoint \ |
| 133 | "placement" \ |
| 134 | "$REGION_NAME" \ |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 135 | "$placement_api_url" |
| 136 | } |
| 137 | |
| 138 | # init_placement() - Create service user and endpoints |
| 139 | # If PLACEMENT_DB_ENABLED is true, create the separate placement db |
| 140 | # using, for now, the api_db migrations. |
| 141 | function init_placement { |
| 142 | if [ "$PLACEMENT_DB_ENABLED" != False ]; then |
| 143 | recreate_database placement |
| 144 | $NOVA_BIN_DIR/nova-manage --config-file $NOVA_CONF api_db sync |
| 145 | fi |
| 146 | create_placement_accounts |
| 147 | } |
| 148 | |
| 149 | # install_placement() - Collect source and prepare |
| 150 | function install_placement { |
| 151 | install_apache_wsgi |
| 152 | if is_ssl_enabled_service "placement-api"; then |
| 153 | enable_mod_ssl |
| 154 | fi |
| 155 | } |
| 156 | |
| 157 | # start_placement_api() - Start the API processes ahead of other things |
| 158 | function start_placement_api { |
Chris Dent | 4d60175 | 2016-07-12 19:34:09 +0000 | [diff] [blame] | 159 | enable_apache_site placement-api |
| 160 | restart_apache_server |
| 161 | tail_log placement-api /var/log/$APACHE_NAME/placement-api.log |
| 162 | |
| 163 | echo "Waiting for placement-api to start..." |
| 164 | if ! wait_for_service $SERVICE_TIMEOUT $PLACEMENT_SERVICE_PROTOCOL://$PLACEMENT_SERVICE_HOST/placement; then |
| 165 | die $LINENO "placement-api did not start" |
| 166 | fi |
| 167 | } |
| 168 | |
| 169 | function start_placement { |
| 170 | start_placement_api |
| 171 | } |
| 172 | |
| 173 | # stop_placement() - Disable the api service and stop it. |
| 174 | function stop_placement { |
| 175 | disable_apache_site placement-api |
| 176 | restart_apache_server |
| 177 | } |
| 178 | |
| 179 | # Restore xtrace |
| 180 | $_XTRACE_LIB_PLACEMENT |
| 181 | |
| 182 | # Tell emacs to use shell-script-mode |
| 183 | ## Local variables: |
| 184 | ## mode: shell-script |
| 185 | ## End: |