lib/cinder
e263c82e
 #!/bin/bash
 #
67787e6b
 # lib/cinder
6d04fd7b
 # Install and start **Cinder** volume service
67787e6b
 
 # Dependencies:
6a5aa7c6
 #
67787e6b
 # - functions
91b8d13e
 # - DEST, DATA_DIR, STACK_USER must be defined
6a5aa7c6
 # - SERVICE_{TENANT_NAME|PASSWORD} must be defined
 # - ``KEYSTONE_TOKEN_FORMAT`` must be defined
67787e6b
 
 # stack.sh
 # ---------
6a5aa7c6
 # - install_cinder
 # - configure_cinder
 # - init_cinder
 # - start_cinder
 # - stop_cinder
 # - cleanup_cinder
67787e6b
 
7903b795
 # Save trace setting
523f4880
 _XTRACE_CINDER=$(set +o | grep xtrace)
7903b795
 set +o xtrace
67787e6b
 
 
 # Defaults
 # --------
 
b2fdafea
 # set up default driver
 CINDER_DRIVER=${CINDER_DRIVER:-default}
d0860cc2
 CINDER_PLUGINS=$TOP_DIR/lib/cinder_plugins
09718335
 CINDER_BACKENDS=$TOP_DIR/lib/cinder_backends
d0860cc2
 
 # grab plugin config if specified via cinder_driver
 if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
     source $CINDER_PLUGINS/$CINDER_DRIVER
 fi
b2fdafea
 
67787e6b
 # set up default directories
e08ab104
 GITDIR["python-cinderclient"]=$DEST/python-cinderclient
8d0d3115
 GITDIR["python-brick-cinderclient-ext"]=$DEST/python-brick-cinderclient-ext
67787e6b
 CINDER_DIR=$DEST/cinder
6aaad5f7
 
 # Cinder virtual environment
 if [[ ${USE_VENV} = True ]]; then
     PROJECT_VENV["cinder"]=${CINDER_DIR}.venv
     CINDER_BIN_DIR=${PROJECT_VENV["cinder"]}/bin
 else
     CINDER_BIN_DIR=$(get_python_exec_prefix)
 fi
 
50ac7921
 CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
671c16e6
 
50ac7921
 CINDER_CONF_DIR=/etc/cinder
 CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
daf12744
 CINDER_UWSGI=$CINDER_BIN_DIR/cinder-wsgi
 CINDER_UWSGI_CONF=$CINDER_CONF_DIR/cinder-api-uwsgi.ini
671c16e6
 CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
50ac7921
 
560346b5
 # Public facing bits
f3b2f4c8
 if is_service_enabled tls-proxy; then
18d4778c
     CINDER_SERVICE_PROTOCOL="https"
 fi
560346b5
 CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
 CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
 CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
 CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
dc7b4294
 CINDER_SERVICE_LISTEN_ADDRESS=${CINDER_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
560346b5
 
ce8e6f6a
 # What type of LVM device should Cinder use for LVM backend
486376e9
 # Defaults to auto, which will do thin provisioning if it's a fresh
 # volume group, otherwise it will do thick. The other valid choices are
 # default, which is thick, or thin, which as the name implies utilizes lvm
 # thin provisioning.
 CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-auto}
09718335
 
 # Default backends
 # The backend format is type:name where type is one of the supported backend
 # types (lvm, nfs, etc) and name is the identifier used in the Cinder
 # configuration and for the volume type name.  Multiple backends are
 # comma-separated.
311f4876
 # The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
 # CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
 CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
09718335
 
dfcc3871
 CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
 CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
b7490da9
 
61f6cafe
 # Centos7 and OpenSUSE switched to using LIO and that's all that's supported,
 # although the tgt bits are in EPEL and OpenSUSE we don't want that for CI
 if is_fedora || is_suse; then
a881b887
     CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-lioadm}
     if [[ ${CINDER_ISCSI_HELPER} != "lioadm" ]]; then
f63ddd60
         die "lioadm is the only valid Cinder target_helper config on this platform"
a881b887
     fi
 else
     CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
 fi
c70605d1
 
daf12744
 # Toggle for deploying Cinder under a wsgi server. Legacy mod_wsgi
 # reference should be cleaned up to more accurately refer to uwsgi.
 CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-True}
cc6b4435
 
09718335
 # Source the enabled backends
 if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
     for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
e8a35acd
         be_type=${be%%:*}
         be_name=${be##*:}
         if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
             source $CINDER_BACKENDS/${be_type}
09718335
         fi
     done
 fi
 
dddb2c7b
 # Environment variables to configure the image-volume cache
 CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
 
 # For limits, if left unset, it will use cinder defaults of 0 for unlimited
 CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
 CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
 
 # Configure which cinder backends will have the image-volume cache, this takes the same
 # form as the CINDER_ENABLED_BACKENDS config option. By default it will
 # enable the cache for all cinder backends.
 CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
09718335
 
cc6b4435
 # Functions
 # ---------
e4fa7213
 
 # Test if any Cinder services are enabled
 # is_cinder_enabled
 function is_cinder_enabled {
902158bb
     [[ ,${DISABLED_SERVICES} =~ ,"cinder" ]] && return 1
e4fa7213
     [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
     return 1
 }
 
651cb1ad
 # _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
 function _cinder_cleanup_apache_wsgi {
     sudo rm -f $(apache_site_config_for osapi-volume)
 }
 
67787e6b
 # cleanup_cinder() - Remove residual data files, anything left over from previous
 # runs that a clean run would need to clean up
aee18c74
 function cleanup_cinder {
252f2f53
     # ensure the volume group is cleared up because fails might
     # leave dead volumes in the group
c70605d1
     if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
ada886dd
         local targets
         targets=$(sudo tgtadm --op show --mode target)
c70605d1
         if [ $? -ne 0 ]; then
             # If tgt driver isn't running this won't work obviously
             # So check the response and restart if need be
             echo "tgtd seems to be in a bad state, restarting..."
             if is_ubuntu; then
                 restart_service tgt
             else
                 restart_service tgtd
             fi
             targets=$(sudo tgtadm --op show --mode target)
252f2f53
         fi
 
c70605d1
         if [[ -n "$targets" ]]; then
             local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
             for i in "${iqn_list[@]}"; do
                 echo removing iSCSI target: $i
                 sudo tgt-admin --delete $i
             done
         fi
252f2f53
 
c70605d1
         if is_ubuntu; then
             stop_service tgt
         else
             stop_service tgtd
         fi
252f2f53
     else
c70605d1
         sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
252f2f53
     fi
 
09718335
     if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
e8a35acd
         local be be_name be_type
09718335
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
e8a35acd
             be_type=${be%%:*}
             be_name=${be##*:}
             if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
                 cleanup_cinder_backend_${be_type} ${be_name}
09718335
             fi
         done
dda2b7af
     fi
651cb1ad
 
daf12744
     stop_process "c-api"
     remove_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI"
67787e6b
 }
 
63e17843
 # configure_cinder() - Set config files, create data dirs, etc
aee18c74
 function configure_cinder {
8421c2b9
     sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
63e17843
 
cecbd1ff
     rm -f $CINDER_CONF
 
c6782413
     configure_rootwrap cinder
4e823ff4
 
401de4d2
     if [[ -f "$CINDER_DIR/etc/cinder/resource_filters.json" ]]; then
         cp -p "$CINDER_DIR/etc/cinder/resource_filters.json" "$CINDER_CONF_DIR/resource_filters.json"
     fi
 
67787e6b
     cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
82dea7c6
 
     inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
     inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
     inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
bd24a8d0
     inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
82dea7c6
     inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
     inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
     inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
1f82f430
     inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
bc071bce
 
8ab64b32
     configure_keystone_authtoken_middleware $CINDER_CONF cinder
82dea7c6
 
03997942
     iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
09718335
 
f63ddd60
     iniset $CINDER_CONF DEFAULT target_helper "$CINDER_ISCSI_HELPER"
23d6d506
     iniset $CINDER_CONF database connection `database_connection_url cinder`
67787e6b
     iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
a58382ac
     iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
9f22f07a
     iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
180f5eb6
     iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
50ac7921
     iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
23d6d506
     iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
d331fa7a
     if [[ $SERVICE_IP_VERSION == 6 ]]; then
         iniset $CINDER_CONF DEFAULT my_ip "$HOST_IPV6"
     else
         iniset $CINDER_CONF DEFAULT my_ip "$HOST_IP"
     fi
32712717
     iniset $CINDER_CONF key_manager backend cinder.keymgr.conf_key_mgr.ConfKeyManager
cb8256f2
     iniset $CINDER_CONF key_manager fixed_key $(openssl rand -hex 16)
a5b72b05
 
09718335
     if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
e8a35acd
         local enabled_backends=""
         local default_name=""
         local be be_name be_type
09718335
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
e8a35acd
             be_type=${be%%:*}
             be_name=${be##*:}
             if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
                 configure_cinder_backend_${be_type} ${be_name}
09718335
             fi
a25922b9
             if [[ -z "$default_name" ]]; then
                 default_name=$be_name
09718335
             fi
e8a35acd
             enabled_backends+=$be_name,
29ec2821
 
             iniset $CINDER_CONF $be_name volume_clear $CINDER_VOLUME_CLEAR
 
09718335
         done
         iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
6a4aa78f
         if [[ -n "$default_name" ]]; then
             iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
09718335
         fi
dddb2c7b
         configure_cinder_image_volume_cache
09718335
     fi
 
31c7d5c7
     if is_service_enabled c-bak; then
         # NOTE(mriedem): The default backup driver uses swift and if we're
         # on a subnode we might not know if swift is enabled, but chances are
         # good that it is on the controller so configure the backup service
         # to use it. If we want to configure the backup service to use
         # a non-swift driver, we'll likely need environment variables.
22f747b8
         iniset $CINDER_CONF DEFAULT backup_swift_url "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_"
2983474e
     fi
 
2bfbc779
     if is_service_enabled ceilometer; then
45da777d
         iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
2bfbc779
     fi
 
560346b5
     if is_service_enabled tls-proxy; then
daf12744
         if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
             # Set the service port for a proxy to take the original
             if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
                 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
411c34da
                 iniset $CINDER_CONF oslo_middleware enable_proxy_headers_parsing True
daf12744
             else
                 iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
                 iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
                 iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
             fi
         fi
560346b5
     fi
 
4d3049e7
     if [ "$SYSLOG" != "False" ]; then
         iniset $CINDER_CONF DEFAULT use_syslog True
     fi
 
2dd110ce
     iniset_rpc_backend cinder $CINDER_CONF
f71bf192
 
05ae833b
     # Format logging
9751be66
     setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
b2fdafea
 
daf12744
     write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume"
651cb1ad
 
d0860cc2
     if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
         configure_cinder_driver
b2fdafea
     fi
0db17137
 
05bd7b80
     iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
18d4778c
 
1fa65363
     iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
f3b2f4c8
     if is_service_enabled tls-proxy; then
18d4778c
         iniset $CINDER_CONF DEFAULT glance_protocol https
4b109297
         iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
18d4778c
     fi
 
c04ac03e
     # Set nova credentials (used for os-assisted-snapshots)
8ab64b32
     configure_keystone_authtoken_middleware $CINDER_CONF nova nova
c04ac03e
     iniset $CINDER_CONF nova region_name "$REGION_NAME"
7159b4ba
     iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
52b10746
 
c0d16c27
     if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
         iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
     elif is_service_enabled etcd3; then
27367bea
         iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
52b10746
     fi
67787e6b
 }
 
671c16e6
 # create_cinder_accounts() - Set up common required cinder accounts
 
 # Tenant               User       Roles
 # ------------------------------------------------------------------
 # service              cinder     admin        # if enabled
 
 # Migrated from keystone_data.sh
aee18c74
 function create_cinder_accounts {
671c16e6
     # Cinder
     if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
0abde393
 
e8bc2b82
         create_service_user "cinder"
0abde393
 
cda2cb55
         # block-storage is the official service type
         get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
daf12744
         if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
             get_or_create_endpoint \
cda2cb55
                 "block-storage" \
                 "$REGION_NAME" \
69057d46
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
cda2cb55
 
daf12744
             get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
             get_or_create_endpoint \
                 "volumev2" \
                 "$REGION_NAME" \
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
 
             get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
             get_or_create_endpoint \
                 "volumev3" \
                 "$REGION_NAME" \
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
         else
             get_or_create_endpoint \
cda2cb55
                 "block-storage" \
                 "$REGION_NAME" \
69057d46
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
cda2cb55
 
daf12744
             get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
             get_or_create_endpoint \
                 "volumev2" \
                 "$REGION_NAME" \
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v2/\$(project_id)s"
 
             get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
             get_or_create_endpoint \
                 "volumev3" \
                 "$REGION_NAME" \
                 "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
         fi
dddb2c7b
 
         configure_cinder_internal_tenant
671c16e6
     fi
 }
 
67787e6b
 # init_cinder() - Initialize database and volume group
aee18c74
 function init_cinder {
428af5a2
     if is_service_enabled $DATABASE_BACKENDS; then
f03bafeb
         # (Re)create cinder database
157c84b8
         recreate_database cinder
67787e6b
 
633dbc3d
         time_start "dbsync"
f03bafeb
         # Migrate cinder database
4f55c2d5
         $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
633dbc3d
         time_stop "dbsync"
67787e6b
     fi
 
09718335
     if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
e8a35acd
         local be be_name be_type
09718335
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
e8a35acd
             be_type=${be%%:*}
             be_name=${be##*:}
             if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
c070a3db
                 # Always init the default volume group for lvm.
                 if [[ "$be_type" == "lvm" ]]; then
                     init_default_lvm_volume_group
                 fi
e8a35acd
                 init_cinder_backend_${be_type} ${be_name}
0230aa89
             fi
09718335
         done
67787e6b
     fi
bc071bce
 
09718335
     mkdir -p $CINDER_STATE_PATH/volumes
67787e6b
 }
 
 # install_cinder() - Collect source and prepare
aee18c74
 function install_cinder {
67787e6b
     git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
4bf9d7a7
     setup_develop $CINDER_DIR
a881b887
     if [[ "$CINDER_ISCSI_HELPER" == "tgtadm" ]]; then
         install_package tgt
501aaeb4
     elif [[ "$CINDER_ISCSI_HELPER" == "lioadm" ]]; then
b066707d
         if is_ubuntu; then
f28c75f8
             # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
             sudo mkdir -p /etc/target
 
363acd9d
             install_package targetcli-fb
         else
             install_package targetcli
         fi
c70605d1
     fi
253a1a35
 }
4bf9d7a7
 
253a1a35
 # install_cinderclient() - Collect source and prepare
aee18c74
 function install_cinderclient {
8d0d3115
     if use_library_from_git "python-brick-cinderclient-ext"; then
         git_clone_by_name "python-brick-cinderclient-ext"
         setup_dev_lib "python-brick-cinderclient-ext"
     fi
 
e08ab104
     if use_library_from_git "python-cinderclient"; then
         git_clone_by_name "python-cinderclient"
         setup_dev_lib "python-cinderclient"
         sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-cinderclient"]}/tools/,/etc/bash_completion.d/}cinder.bash_completion
5cb19069
     fi
67787e6b
 }
 
18225d92
 # apply config.d approach for cinder volumes directory
aee18c74
 function _configure_tgt_for_config_d {
18225d92
     if [[ ! -d /etc/tgt/stack.d/ ]]; then
         sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
a263e7dd
     fi
     if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
18225d92
         echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
a39caaca
     fi
 }
 
0eebeb41
 # start_cinder() - Start running processes
aee18c74
 function start_cinder {
18d4778c
     local service_port=$CINDER_SERVICE_PORT
     local service_protocol=$CINDER_SERVICE_PROTOCOL
daf12744
     local cinder_url
8ea8660e
     if is_service_enabled tls-proxy && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
18d4778c
         service_port=$CINDER_SERVICE_PORT_INT
         service_protocol="http"
     fi
c70605d1
     if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
         if is_service_enabled c-vol; then
             # Delete any old stack.conf
             sudo rm -f /etc/tgt/conf.d/stack.conf
             _configure_tgt_for_config_d
             if is_ubuntu; then
                 sudo service tgt restart
6bc089fc
             elif is_suse; then
                 # NOTE(dmllr): workaround restart bug
                 # https://bugzilla.suse.com/show_bug.cgi?id=934642
                 stop_service tgtd
                 start_service tgtd
c70605d1
             else
6bc089fc
                 restart_service tgtd
c70605d1
             fi
             # NOTE(gfidente): ensure tgtd is running in debug mode
             sudo tgtadm --mode system --op update --name debug --value on
67787e6b
         fi
     fi
 
daf12744
     if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
         if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
2dfca047
             run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
daf12744
             cinder_url=$service_protocol://$SERVICE_HOST:$service_port
52609c68
             # Start proxy if tls enabled
             if is_service_enabled tls-proxy; then
                 start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
daf12744
             fi
         else
312517d5
             run_process "c-api" "$(which uwsgi) --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
daf12744
             cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
2dfca047
         fi
daf12744
     fi
4af6eeac
 
daf12744
     echo "Waiting for Cinder API to start..."
     if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
         die $LINENO "c-api did not start"
09718335
     fi
 
3159a821
     run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
     run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
     run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
e6d4fe5f
 
     # NOTE(jdg): For cinder, startup order matters.  To ensure that repor_capabilities is received
     # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
     # has started.  This is a quick fix for lp bug/1189595
67787e6b
 }
 
699a29f7
 # stop_cinder() - Stop running processes
aee18c74
 function stop_cinder {
daf12744
     stop_process c-api
0eebeb41
     stop_process c-bak
     stop_process c-sch
     stop_process c-vol
67787e6b
 }
7903b795
 
09718335
 # create_volume_types() - Create Cinder's configured volume types
 function create_volume_types {
     # Create volume types
     if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
494f7cdf
         local be be_name
09718335
         for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
e8a35acd
             be_name=${be##*:}
165199ee
             # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
             if is_service_enabled keystone; then
                 openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
             else
                 # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
                 # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
                 local cinder_url
                 cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
                 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create ${be_name}
                 OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-key ${be_name} set volume_backend_name=${be_name}
             fi
09718335
         done
     fi
 }
 
 # Compatibility for Grenade
 
 function create_cinder_volume_group {
     # During a transition period Grenade needs to have this function defined
     # It is effectively a no-op in the Grenade 'target' use case
     :
 }
 
dddb2c7b
 function configure_cinder_internal_tenant {
     # Re-use the Cinder service account for simplicity.
     iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
     iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
 }
 
 function configure_cinder_image_volume_cache {
     # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
     # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
     # be the backend specific configuration stanza in cinder.conf.
     for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
         local be_name=${be##*:}
 
         iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
 
         if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
             iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
         fi
 
         if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
             iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
         fi
     done
 }
 
cc6b4435
 
7903b795
 # Restore xtrace
523f4880
 $_XTRACE_CINDER
584d90ec
 
6a5aa7c6
 # Tell emacs to use shell-script-mode
 ## Local variables:
 ## mode: shell-script
 ## End: