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.
 
 
 
 

581 lines
22 KiB

  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. # Set nova credentials (used for os-assisted-snapshots)
  263. configure_keystone_authtoken_middleware $CINDER_CONF nova nova
  264. iniset $CINDER_CONF nova region_name "$REGION_NAME"
  265. iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
  266. if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
  267. iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
  268. elif is_service_enabled etcd3; then
  269. iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
  270. fi
  271. }
  272. # create_cinder_accounts() - Set up common required cinder accounts
  273. # Tenant User Roles
  274. # ------------------------------------------------------------------
  275. # service cinder admin # if enabled
  276. # Migrated from keystone_data.sh
  277. function create_cinder_accounts {
  278. # Cinder
  279. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  280. create_service_user "cinder"
  281. # block-storage is the official service type
  282. get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
  283. if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  284. get_or_create_endpoint \
  285. "block-storage" \
  286. "$REGION_NAME" \
  287. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
  288. get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
  289. get_or_create_endpoint \
  290. "volumev2" \
  291. "$REGION_NAME" \
  292. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
  293. get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
  294. get_or_create_endpoint \
  295. "volumev3" \
  296. "$REGION_NAME" \
  297. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
  298. else
  299. get_or_create_endpoint \
  300. "block-storage" \
  301. "$REGION_NAME" \
  302. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
  303. get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
  304. get_or_create_endpoint \
  305. "volumev2" \
  306. "$REGION_NAME" \
  307. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v2/\$(project_id)s"
  308. get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
  309. get_or_create_endpoint \
  310. "volumev3" \
  311. "$REGION_NAME" \
  312. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
  313. fi
  314. configure_cinder_internal_tenant
  315. fi
  316. }
  317. # init_cinder() - Initialize database and volume group
  318. function init_cinder {
  319. if is_service_enabled $DATABASE_BACKENDS; then
  320. # (Re)create cinder database
  321. recreate_database cinder
  322. time_start "dbsync"
  323. # Migrate cinder database
  324. $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
  325. time_stop "dbsync"
  326. fi
  327. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  328. local be be_name be_type
  329. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  330. be_type=${be%%:*}
  331. be_name=${be##*:}
  332. if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
  333. # Always init the default volume group for lvm.
  334. if [[ "$be_type" == "lvm" ]]; then
  335. init_default_lvm_volume_group
  336. fi
  337. init_cinder_backend_${be_type} ${be_name}
  338. fi
  339. done
  340. fi
  341. mkdir -p $CINDER_STATE_PATH/volumes
  342. }
  343. # install_cinder() - Collect source and prepare
  344. function install_cinder {
  345. git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
  346. setup_develop $CINDER_DIR
  347. if [[ "$CINDER_ISCSI_HELPER" == "tgtadm" ]]; then
  348. install_package tgt
  349. elif [[ "$CINDER_ISCSI_HELPER" == "lioadm" ]]; then
  350. if is_ubuntu; then
  351. # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
  352. sudo mkdir -p /etc/target
  353. install_package targetcli-fb
  354. else
  355. install_package targetcli
  356. fi
  357. fi
  358. }
  359. # install_cinderclient() - Collect source and prepare
  360. function install_cinderclient {
  361. if use_library_from_git "python-brick-cinderclient-ext"; then
  362. git_clone_by_name "python-brick-cinderclient-ext"
  363. setup_dev_lib "python-brick-cinderclient-ext"
  364. fi
  365. if use_library_from_git "python-cinderclient"; then
  366. git_clone_by_name "python-cinderclient"
  367. setup_dev_lib "python-cinderclient"
  368. sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-cinderclient"]}/tools/,/etc/bash_completion.d/}cinder.bash_completion
  369. fi
  370. }
  371. # apply config.d approach for cinder volumes directory
  372. function _configure_tgt_for_config_d {
  373. if [[ ! -d /etc/tgt/stack.d/ ]]; then
  374. sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
  375. fi
  376. if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
  377. echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
  378. fi
  379. }
  380. # start_cinder() - Start running processes
  381. function start_cinder {
  382. local service_port=$CINDER_SERVICE_PORT
  383. local service_protocol=$CINDER_SERVICE_PROTOCOL
  384. local cinder_url
  385. if is_service_enabled tls-proxy && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  386. service_port=$CINDER_SERVICE_PORT_INT
  387. service_protocol="http"
  388. fi
  389. if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
  390. if is_service_enabled c-vol; then
  391. # Delete any old stack.conf
  392. sudo rm -f /etc/tgt/conf.d/stack.conf
  393. _configure_tgt_for_config_d
  394. if is_ubuntu; then
  395. sudo service tgt restart
  396. elif is_suse; then
  397. # NOTE(dmllr): workaround restart bug
  398. # https://bugzilla.suse.com/show_bug.cgi?id=934642
  399. stop_service tgtd
  400. start_service tgtd
  401. else
  402. restart_service tgtd
  403. fi
  404. # NOTE(gfidente): ensure tgtd is running in debug mode
  405. sudo tgtadm --mode system --op update --name debug --value on
  406. fi
  407. fi
  408. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  409. if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  410. run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
  411. cinder_url=$service_protocol://$SERVICE_HOST:$service_port
  412. # Start proxy if tls enabled
  413. if is_service_enabled tls-proxy; then
  414. start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
  415. fi
  416. else
  417. run_process "c-api" "$(which uwsgi) --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
  418. cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
  419. fi
  420. fi
  421. echo "Waiting for Cinder API to start..."
  422. if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
  423. die $LINENO "c-api did not start"
  424. fi
  425. run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
  426. run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
  427. run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
  428. # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
  429. # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
  430. # has started. This is a quick fix for lp bug/1189595
  431. }
  432. # stop_cinder() - Stop running processes
  433. function stop_cinder {
  434. stop_process c-api
  435. stop_process c-bak
  436. stop_process c-sch
  437. stop_process c-vol
  438. }
  439. # create_volume_types() - Create Cinder's configured volume types
  440. function create_volume_types {
  441. # Create volume types
  442. if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  443. local be be_name
  444. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  445. be_name=${be##*:}
  446. # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
  447. if is_service_enabled keystone; then
  448. openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
  449. else
  450. # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
  451. # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
  452. local cinder_url
  453. cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
  454. OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create ${be_name}
  455. 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}
  456. fi
  457. done
  458. fi
  459. }
  460. # Compatibility for Grenade
  461. function create_cinder_volume_group {
  462. # During a transition period Grenade needs to have this function defined
  463. # It is effectively a no-op in the Grenade 'target' use case
  464. :
  465. }
  466. function configure_cinder_internal_tenant {
  467. # Re-use the Cinder service account for simplicity.
  468. iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
  469. iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
  470. }
  471. function configure_cinder_image_volume_cache {
  472. # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
  473. # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
  474. # be the backend specific configuration stanza in cinder.conf.
  475. for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
  476. local be_name=${be##*:}
  477. iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
  478. if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
  479. iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
  480. fi
  481. if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
  482. iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
  483. fi
  484. done
  485. }
  486. # Restore xtrace
  487. $_XTRACE_CINDER
  488. # Tell emacs to use shell-script-mode
  489. ## Local variables:
  490. ## mode: shell-script
  491. ## End: