System for quickly installing an OpenStack cloud from upstream git for testing and development.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

585 lines
22KB

  1. #!/bin/bash
  2. #
  3. # lib/cinder
  4. # Install and start **Cinder** volume service
  5. # Dependencies:
  6. #
  7. # - functions
  8. # - DEST, DATA_DIR, STACK_USER must be defined
  9. # - SERVICE_{TENANT_NAME|PASSWORD} must be defined
  10. # - ``KEYSTONE_TOKEN_FORMAT`` must be defined
  11. # stack.sh
  12. # ---------
  13. # - install_cinder
  14. # - configure_cinder
  15. # - init_cinder
  16. # - start_cinder
  17. # - stop_cinder
  18. # - cleanup_cinder
  19. # Save trace setting
  20. _XTRACE_CINDER=$(set +o | grep xtrace)
  21. set +o xtrace
  22. # Defaults
  23. # --------
  24. # set up default driver
  25. CINDER_DRIVER=${CINDER_DRIVER:-default}
  26. CINDER_PLUGINS=$TOP_DIR/lib/cinder_plugins
  27. CINDER_BACKENDS=$TOP_DIR/lib/cinder_backends
  28. # grab plugin config if specified via cinder_driver
  29. if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
  30. source $CINDER_PLUGINS/$CINDER_DRIVER
  31. fi
  32. # set up default directories
  33. GITDIR["python-cinderclient"]=$DEST/python-cinderclient
  34. GITDIR["python-brick-cinderclient-ext"]=$DEST/python-brick-cinderclient-ext
  35. CINDER_DIR=$DEST/cinder
  36. # Cinder virtual environment
  37. if [[ ${USE_VENV} = True ]]; then
  38. PROJECT_VENV["cinder"]=${CINDER_DIR}.venv
  39. CINDER_BIN_DIR=${PROJECT_VENV["cinder"]}/bin
  40. else
  41. CINDER_BIN_DIR=$(get_python_exec_prefix)
  42. fi
  43. CINDER_STATE_PATH=${CINDER_STATE_PATH:=$DATA_DIR/cinder}
  44. CINDER_CONF_DIR=/etc/cinder
  45. CINDER_CONF=$CINDER_CONF_DIR/cinder.conf
  46. CINDER_UWSGI=$CINDER_BIN_DIR/cinder-wsgi
  47. CINDER_UWSGI_CONF=$CINDER_CONF_DIR/cinder-api-uwsgi.ini
  48. CINDER_API_PASTE_INI=$CINDER_CONF_DIR/api-paste.ini
  49. # Public facing bits
  50. if is_service_enabled tls-proxy; then
  51. CINDER_SERVICE_PROTOCOL="https"
  52. fi
  53. CINDER_SERVICE_HOST=${CINDER_SERVICE_HOST:-$SERVICE_HOST}
  54. CINDER_SERVICE_PORT=${CINDER_SERVICE_PORT:-8776}
  55. CINDER_SERVICE_PORT_INT=${CINDER_SERVICE_PORT_INT:-18776}
  56. CINDER_SERVICE_PROTOCOL=${CINDER_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
  57. CINDER_SERVICE_LISTEN_ADDRESS=${CINDER_SERVICE_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
  58. # What type of LVM device should Cinder use for LVM backend
  59. # Defaults to auto, which will do thin provisioning if it's a fresh
  60. # volume group, otherwise it will do thick. The other valid choices are
  61. # default, which is thick, or thin, which as the name implies utilizes lvm
  62. # thin provisioning.
  63. CINDER_LVM_TYPE=${CINDER_LVM_TYPE:-auto}
  64. # Default backends
  65. # The backend format is type:name where type is one of the supported backend
  66. # types (lvm, nfs, etc) and name is the identifier used in the Cinder
  67. # configuration and for the volume type name. Multiple backends are
  68. # comma-separated.
  69. # The old ``CINDER_MULTI_LVM_BACKEND=True`` setting had a default of:
  70. # CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2}
  71. CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1}
  72. CINDER_VOLUME_CLEAR=${CINDER_VOLUME_CLEAR:-${CINDER_VOLUME_CLEAR_DEFAULT:-zero}}
  73. CINDER_VOLUME_CLEAR=$(echo ${CINDER_VOLUME_CLEAR} | tr '[:upper:]' '[:lower:]')
  74. # Centos7 and OpenSUSE switched to using LIO and that's all that's supported,
  75. # although the tgt bits are in EPEL and OpenSUSE we don't want that for CI
  76. if is_fedora || is_suse; then
  77. CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-lioadm}
  78. if [[ ${CINDER_ISCSI_HELPER} != "lioadm" ]]; then
  79. die "lioadm is the only valid Cinder target_helper config on this platform"
  80. fi
  81. else
  82. CINDER_ISCSI_HELPER=${CINDER_ISCSI_HELPER:-tgtadm}
  83. fi
  84. # Toggle for deploying Cinder under a wsgi server. Legacy mod_wsgi
  85. # reference should be cleaned up to more accurately refer to uwsgi.
  86. CINDER_USE_MOD_WSGI=${CINDER_USE_MOD_WSGI:-True}
  87. # Source the enabled backends
  88. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  89. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  90. be_type=${be%%:*}
  91. be_name=${be##*:}
  92. if [[ -r $CINDER_BACKENDS/${be_type} ]]; then
  93. source $CINDER_BACKENDS/${be_type}
  94. fi
  95. done
  96. fi
  97. # Environment variables to configure the image-volume cache
  98. CINDER_IMG_CACHE_ENABLED=${CINDER_IMG_CACHE_ENABLED:-True}
  99. # For limits, if left unset, it will use cinder defaults of 0 for unlimited
  100. CINDER_IMG_CACHE_SIZE_GB=${CINDER_IMG_CACHE_SIZE_GB:-}
  101. CINDER_IMG_CACHE_SIZE_COUNT=${CINDER_IMG_CACHE_SIZE_COUNT:-}
  102. # Configure which cinder backends will have the image-volume cache, this takes the same
  103. # form as the CINDER_ENABLED_BACKENDS config option. By default it will
  104. # enable the cache for all cinder backends.
  105. CINDER_CACHE_ENABLED_FOR_BACKENDS=${CINDER_CACHE_ENABLED_FOR_BACKENDS:-$CINDER_ENABLED_BACKENDS}
  106. # Functions
  107. # ---------
  108. # Test if any Cinder services are enabled
  109. # is_cinder_enabled
  110. function is_cinder_enabled {
  111. [[ ,${DISABLED_SERVICES} =~ ,"cinder" ]] && return 1
  112. [[ ,${ENABLED_SERVICES} =~ ,"c-" ]] && return 0
  113. return 1
  114. }
  115. # _cinder_cleanup_apache_wsgi() - Remove wsgi files, disable and remove apache vhost file
  116. function _cinder_cleanup_apache_wsgi {
  117. sudo rm -f $(apache_site_config_for osapi-volume)
  118. }
  119. # cleanup_cinder() - Remove residual data files, anything left over from previous
  120. # runs that a clean run would need to clean up
  121. function cleanup_cinder {
  122. # ensure the volume group is cleared up because fails might
  123. # leave dead volumes in the group
  124. if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
  125. local targets
  126. targets=$(sudo tgtadm --op show --mode target)
  127. if [ $? -ne 0 ]; then
  128. # If tgt driver isn't running this won't work obviously
  129. # So check the response and restart if need be
  130. echo "tgtd seems to be in a bad state, restarting..."
  131. if is_ubuntu; then
  132. restart_service tgt
  133. else
  134. restart_service tgtd
  135. fi
  136. targets=$(sudo tgtadm --op show --mode target)
  137. fi
  138. if [[ -n "$targets" ]]; then
  139. local iqn_list=( $(grep --no-filename -r iqn $SCSI_PERSIST_DIR | sed 's/<target //' | sed 's/>//') )
  140. for i in "${iqn_list[@]}"; do
  141. echo removing iSCSI target: $i
  142. sudo tgt-admin --delete $i
  143. done
  144. fi
  145. if is_ubuntu; then
  146. stop_service tgt
  147. else
  148. stop_service tgtd
  149. fi
  150. else
  151. sudo cinder-rtstool get-targets | sudo xargs -rn 1 cinder-rtstool delete
  152. fi
  153. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  154. local be be_name be_type
  155. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  156. be_type=${be%%:*}
  157. be_name=${be##*:}
  158. if type cleanup_cinder_backend_${be_type} >/dev/null 2>&1; then
  159. cleanup_cinder_backend_${be_type} ${be_name}
  160. fi
  161. done
  162. fi
  163. stop_process "c-api"
  164. remove_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI"
  165. }
  166. # configure_cinder() - Set config files, create data dirs, etc
  167. function configure_cinder {
  168. sudo install -d -o $STACK_USER -m 755 $CINDER_CONF_DIR
  169. rm -f $CINDER_CONF
  170. configure_rootwrap cinder
  171. if [[ -f "$CINDER_DIR/etc/cinder/resource_filters.json" ]]; then
  172. cp -p "$CINDER_DIR/etc/cinder/resource_filters.json" "$CINDER_CONF_DIR/resource_filters.json"
  173. fi
  174. cp $CINDER_DIR/etc/cinder/api-paste.ini $CINDER_API_PASTE_INI
  175. inicomment $CINDER_API_PASTE_INI filter:authtoken auth_host
  176. inicomment $CINDER_API_PASTE_INI filter:authtoken auth_port
  177. inicomment $CINDER_API_PASTE_INI filter:authtoken auth_protocol
  178. inicomment $CINDER_API_PASTE_INI filter:authtoken cafile
  179. inicomment $CINDER_API_PASTE_INI filter:authtoken admin_tenant_name
  180. inicomment $CINDER_API_PASTE_INI filter:authtoken admin_user
  181. inicomment $CINDER_API_PASTE_INI filter:authtoken admin_password
  182. inicomment $CINDER_API_PASTE_INI filter:authtoken signing_dir
  183. configure_keystone_authtoken_middleware $CINDER_CONF cinder
  184. iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
  185. iniset $CINDER_CONF DEFAULT target_helper "$CINDER_ISCSI_HELPER"
  186. iniset $CINDER_CONF database connection `database_connection_url cinder`
  187. iniset $CINDER_CONF DEFAULT api_paste_config $CINDER_API_PASTE_INI
  188. iniset $CINDER_CONF DEFAULT rootwrap_config "$CINDER_CONF_DIR/rootwrap.conf"
  189. iniset $CINDER_CONF DEFAULT osapi_volume_extension cinder.api.contrib.standard_extensions
  190. iniset $CINDER_CONF DEFAULT osapi_volume_listen $CINDER_SERVICE_LISTEN_ADDRESS
  191. iniset $CINDER_CONF DEFAULT state_path $CINDER_STATE_PATH
  192. iniset $CINDER_CONF oslo_concurrency lock_path $CINDER_STATE_PATH
  193. if [[ $SERVICE_IP_VERSION == 6 ]]; then
  194. iniset $CINDER_CONF DEFAULT my_ip "$HOST_IPV6"
  195. else
  196. iniset $CINDER_CONF DEFAULT my_ip "$HOST_IP"
  197. fi
  198. iniset $CINDER_CONF key_manager backend cinder.keymgr.conf_key_mgr.ConfKeyManager
  199. iniset $CINDER_CONF key_manager fixed_key $(openssl rand -hex 16)
  200. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  201. local enabled_backends=""
  202. local default_name=""
  203. local be be_name be_type
  204. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  205. be_type=${be%%:*}
  206. be_name=${be##*:}
  207. if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
  208. configure_cinder_backend_${be_type} ${be_name}
  209. fi
  210. if [[ -z "$default_name" ]]; then
  211. default_name=$be_name
  212. fi
  213. enabled_backends+=$be_name,
  214. iniset $CINDER_CONF $be_name volume_clear $CINDER_VOLUME_CLEAR
  215. done
  216. iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
  217. if [[ -n "$default_name" ]]; then
  218. iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
  219. fi
  220. configure_cinder_image_volume_cache
  221. fi
  222. if is_service_enabled c-bak; then
  223. # NOTE(mriedem): The default backup driver uses swift and if we're
  224. # on a subnode we might not know if swift is enabled, but chances are
  225. # good that it is on the controller so configure the backup service
  226. # to use it. If we want to configure the backup service to use
  227. # a non-swift driver, we'll likely need environment variables.
  228. iniset $CINDER_CONF DEFAULT backup_swift_url "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_"
  229. fi
  230. if is_service_enabled ceilometer; then
  231. iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
  232. fi
  233. if is_service_enabled tls-proxy; then
  234. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  235. # Set the service port for a proxy to take the original
  236. if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
  237. iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
  238. iniset $CINDER_CONF oslo_middleware enable_proxy_headers_parsing True
  239. else
  240. iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
  241. iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
  242. iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
  243. fi
  244. fi
  245. fi
  246. if [ "$SYSLOG" != "False" ]; then
  247. iniset $CINDER_CONF DEFAULT use_syslog True
  248. fi
  249. iniset_rpc_backend cinder $CINDER_CONF
  250. # Format logging
  251. setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
  252. write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume"
  253. if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
  254. configure_cinder_driver
  255. fi
  256. iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
  257. iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
  258. if is_service_enabled tls-proxy; then
  259. iniset $CINDER_CONF DEFAULT glance_protocol https
  260. iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
  261. fi
  262. if [ "$GLANCE_V1_ENABLED" != "True" ]; then
  263. iniset $CINDER_CONF DEFAULT glance_api_version 2
  264. fi
  265. # Set nova credentials (used for os-assisted-snapshots)
  266. configure_keystone_authtoken_middleware $CINDER_CONF nova nova
  267. iniset $CINDER_CONF nova region_name "$REGION_NAME"
  268. iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
  269. if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
  270. iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
  271. elif is_service_enabled etcd3; then
  272. iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
  273. fi
  274. }
  275. # create_cinder_accounts() - Set up common required cinder accounts
  276. # Tenant User Roles
  277. # ------------------------------------------------------------------
  278. # service cinder admin # if enabled
  279. # Migrated from keystone_data.sh
  280. function create_cinder_accounts {
  281. # Cinder
  282. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  283. create_service_user "cinder"
  284. # block-storage is the official service type
  285. get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
  286. if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  287. get_or_create_endpoint \
  288. "block-storage" \
  289. "$REGION_NAME" \
  290. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
  291. get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
  292. get_or_create_endpoint \
  293. "volumev2" \
  294. "$REGION_NAME" \
  295. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
  296. get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
  297. get_or_create_endpoint \
  298. "volumev3" \
  299. "$REGION_NAME" \
  300. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
  301. else
  302. get_or_create_endpoint \
  303. "block-storage" \
  304. "$REGION_NAME" \
  305. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
  306. get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
  307. get_or_create_endpoint \
  308. "volumev2" \
  309. "$REGION_NAME" \
  310. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v2/\$(project_id)s"
  311. get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
  312. get_or_create_endpoint \
  313. "volumev3" \
  314. "$REGION_NAME" \
  315. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
  316. fi
  317. configure_cinder_internal_tenant
  318. fi
  319. }
  320. # init_cinder() - Initialize database and volume group
  321. function init_cinder {
  322. if is_service_enabled $DATABASE_BACKENDS; then
  323. # (Re)create cinder database
  324. recreate_database cinder
  325. time_start "dbsync"
  326. # Migrate cinder database
  327. $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
  328. time_stop "dbsync"
  329. fi
  330. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  331. local be be_name be_type
  332. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  333. be_type=${be%%:*}
  334. be_name=${be##*:}
  335. if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
  336. # Always init the default volume group for lvm.
  337. if [[ "$be_type" == "lvm" ]]; then
  338. init_default_lvm_volume_group
  339. fi
  340. init_cinder_backend_${be_type} ${be_name}
  341. fi
  342. done
  343. fi
  344. mkdir -p $CINDER_STATE_PATH/volumes
  345. }
  346. # install_cinder() - Collect source and prepare
  347. function install_cinder {
  348. git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
  349. setup_develop $CINDER_DIR
  350. if [[ "$CINDER_ISCSI_HELPER" == "tgtadm" ]]; then
  351. install_package tgt
  352. elif [[ "$CINDER_ISCSI_HELPER" == "lioadm" ]]; then
  353. if [[ ${DISTRO} == "bionic" ]]; then
  354. # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
  355. sudo mkdir -p /etc/target
  356. install_package targetcli-fb
  357. else
  358. install_package targetcli
  359. fi
  360. fi
  361. }
  362. # install_cinderclient() - Collect source and prepare
  363. function install_cinderclient {
  364. if use_library_from_git "python-brick-cinderclient-ext"; then
  365. git_clone_by_name "python-brick-cinderclient-ext"
  366. setup_dev_lib "python-brick-cinderclient-ext"
  367. fi
  368. if use_library_from_git "python-cinderclient"; then
  369. git_clone_by_name "python-cinderclient"
  370. setup_dev_lib "python-cinderclient"
  371. sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-cinderclient"]}/tools/,/etc/bash_completion.d/}cinder.bash_completion
  372. fi
  373. }
  374. # apply config.d approach for cinder volumes directory
  375. function _configure_tgt_for_config_d {
  376. if [[ ! -d /etc/tgt/stack.d/ ]]; then
  377. sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
  378. fi
  379. if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
  380. echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
  381. fi
  382. }
  383. # start_cinder() - Start running processes
  384. function start_cinder {
  385. local service_port=$CINDER_SERVICE_PORT
  386. local service_protocol=$CINDER_SERVICE_PROTOCOL
  387. local cinder_url
  388. if is_service_enabled tls-proxy && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  389. service_port=$CINDER_SERVICE_PORT_INT
  390. service_protocol="http"
  391. fi
  392. if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
  393. if is_service_enabled c-vol; then
  394. # Delete any old stack.conf
  395. sudo rm -f /etc/tgt/conf.d/stack.conf
  396. _configure_tgt_for_config_d
  397. if is_ubuntu; then
  398. sudo service tgt restart
  399. elif is_suse; then
  400. # NOTE(dmllr): workaround restart bug
  401. # https://bugzilla.suse.com/show_bug.cgi?id=934642
  402. stop_service tgtd
  403. start_service tgtd
  404. else
  405. restart_service tgtd
  406. fi
  407. # NOTE(gfidente): ensure tgtd is running in debug mode
  408. sudo tgtadm --mode system --op update --name debug --value on
  409. fi
  410. fi
  411. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  412. if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  413. run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
  414. cinder_url=$service_protocol://$SERVICE_HOST:$service_port
  415. # Start proxy if tls enabled
  416. if is_service_enabled tls-proxy; then
  417. start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
  418. fi
  419. else
  420. run_process "c-api" "$CINDER_BIN_DIR/uwsgi --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
  421. cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
  422. fi
  423. fi
  424. echo "Waiting for Cinder API to start..."
  425. if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
  426. die $LINENO "c-api did not start"
  427. fi
  428. run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
  429. run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
  430. run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
  431. # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
  432. # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
  433. # has started. This is a quick fix for lp bug/1189595
  434. }
  435. # stop_cinder() - Stop running processes
  436. function stop_cinder {
  437. stop_process c-api
  438. stop_process c-bak
  439. stop_process c-sch
  440. stop_process c-vol
  441. }
  442. # create_volume_types() - Create Cinder's configured volume types
  443. function create_volume_types {
  444. # Create volume types
  445. if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  446. local be be_name
  447. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  448. be_name=${be##*:}
  449. # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
  450. if is_service_enabled keystone; then
  451. openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
  452. else
  453. # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
  454. # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
  455. local cinder_url
  456. cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
  457. OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create ${be_name}
  458. 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}
  459. fi
  460. done
  461. fi
  462. }
  463. # Compatibility for Grenade
  464. function create_cinder_volume_group {
  465. # During a transition period Grenade needs to have this function defined
  466. # It is effectively a no-op in the Grenade 'target' use case
  467. :
  468. }
  469. function configure_cinder_internal_tenant {
  470. # Re-use the Cinder service account for simplicity.
  471. iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
  472. iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
  473. }
  474. function configure_cinder_image_volume_cache {
  475. # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
  476. # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
  477. # be the backend specific configuration stanza in cinder.conf.
  478. for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
  479. local be_name=${be##*:}
  480. iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
  481. if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
  482. iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
  483. fi
  484. if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
  485. iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
  486. fi
  487. done
  488. }
  489. # Restore xtrace
  490. $_XTRACE_CINDER
  491. # Tell emacs to use shell-script-mode
  492. ## Local variables:
  493. ## mode: shell-script
  494. ## End: