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.

cinder 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  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. iniset $CINDER_CONF DEFAULT my_ip "$HOST_IP"
  194. iniset $CINDER_CONF key_manager backend cinder.keymgr.conf_key_mgr.ConfKeyManager
  195. iniset $CINDER_CONF key_manager fixed_key $(openssl rand -hex 16)
  196. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  197. local enabled_backends=""
  198. local default_name=""
  199. local be be_name be_type
  200. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  201. be_type=${be%%:*}
  202. be_name=${be##*:}
  203. if type configure_cinder_backend_${be_type} >/dev/null 2>&1; then
  204. configure_cinder_backend_${be_type} ${be_name}
  205. fi
  206. if [[ -z "$default_name" ]]; then
  207. default_name=$be_name
  208. fi
  209. enabled_backends+=$be_name,
  210. iniset $CINDER_CONF $be_name volume_clear $CINDER_VOLUME_CLEAR
  211. done
  212. iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*}
  213. if [[ -n "$default_name" ]]; then
  214. iniset $CINDER_CONF DEFAULT default_volume_type ${default_name}
  215. fi
  216. configure_cinder_image_volume_cache
  217. fi
  218. if is_service_enabled c-bak; then
  219. # NOTE(mriedem): The default backup driver uses swift and if we're
  220. # on a subnode we might not know if swift is enabled, but chances are
  221. # good that it is on the controller so configure the backup service
  222. # to use it. If we want to configure the backup service to use
  223. # a non-swift driver, we'll likely need environment variables.
  224. iniset $CINDER_CONF DEFAULT backup_swift_url "$SWIFT_SERVICE_PROTOCOL://$SERVICE_HOST:$SWIFT_DEFAULT_BIND_PORT/v1/AUTH_"
  225. fi
  226. if is_service_enabled ceilometer; then
  227. iniset $CINDER_CONF oslo_messaging_notifications driver "messagingv2"
  228. fi
  229. if is_service_enabled tls-proxy; then
  230. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  231. # Set the service port for a proxy to take the original
  232. if [ "$CINDER_USE_MOD_WSGI" == "True" ]; then
  233. iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
  234. iniset $CINDER_CONF oslo_middleware enable_proxy_headers_parsing True
  235. else
  236. iniset $CINDER_CONF DEFAULT osapi_volume_listen_port $CINDER_SERVICE_PORT_INT
  237. iniset $CINDER_CONF DEFAULT public_endpoint $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
  238. iniset $CINDER_CONF DEFAULT osapi_volume_base_URL $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT
  239. fi
  240. fi
  241. fi
  242. if [ "$SYSLOG" != "False" ]; then
  243. iniset $CINDER_CONF DEFAULT use_syslog True
  244. fi
  245. iniset_rpc_backend cinder $CINDER_CONF
  246. # Format logging
  247. setup_logging $CINDER_CONF $CINDER_USE_MOD_WSGI
  248. write_uwsgi_config "$CINDER_UWSGI_CONF" "$CINDER_UWSGI" "/volume"
  249. if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then
  250. configure_cinder_driver
  251. fi
  252. iniset $CINDER_CONF DEFAULT osapi_volume_workers "$API_WORKERS"
  253. iniset $CINDER_CONF DEFAULT glance_api_servers "$GLANCE_URL"
  254. if is_service_enabled tls-proxy; then
  255. iniset $CINDER_CONF DEFAULT glance_protocol https
  256. iniset $CINDER_CONF DEFAULT glance_ca_certificates_file $SSL_BUNDLE_FILE
  257. fi
  258. if [ "$GLANCE_V1_ENABLED" != "True" ]; then
  259. iniset $CINDER_CONF DEFAULT glance_api_version 2
  260. fi
  261. # Set nova credentials (used for os-assisted-snapshots)
  262. configure_keystone_authtoken_middleware $CINDER_CONF nova nova
  263. iniset $CINDER_CONF nova region_name "$REGION_NAME"
  264. iniset $CINDER_CONF DEFAULT graceful_shutdown_timeout "$SERVICE_GRACEFUL_SHUTDOWN_TIMEOUT"
  265. if [[ ! -z "$CINDER_COORDINATION_URL" ]]; then
  266. iniset $CINDER_CONF coordination backend_url "$CINDER_COORDINATION_URL"
  267. elif is_service_enabled etcd3; then
  268. iniset $CINDER_CONF coordination backend_url "etcd3+http://${SERVICE_HOST}:$ETCD_PORT"
  269. fi
  270. }
  271. # create_cinder_accounts() - Set up common required cinder accounts
  272. # Tenant User Roles
  273. # ------------------------------------------------------------------
  274. # service cinder admin # if enabled
  275. # Migrated from keystone_data.sh
  276. function create_cinder_accounts {
  277. # Cinder
  278. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  279. create_service_user "cinder"
  280. # block-storage is the official service type
  281. get_or_create_service "cinder" "block-storage" "Cinder Volume Service"
  282. if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  283. get_or_create_endpoint \
  284. "block-storage" \
  285. "$REGION_NAME" \
  286. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
  287. get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
  288. get_or_create_endpoint \
  289. "volumev2" \
  290. "$REGION_NAME" \
  291. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v2/\$(project_id)s"
  292. get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
  293. get_or_create_endpoint \
  294. "volumev3" \
  295. "$REGION_NAME" \
  296. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT/v3/\$(project_id)s"
  297. else
  298. get_or_create_endpoint \
  299. "block-storage" \
  300. "$REGION_NAME" \
  301. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
  302. get_or_create_service "cinderv2" "volumev2" "Cinder Volume Service V2"
  303. get_or_create_endpoint \
  304. "volumev2" \
  305. "$REGION_NAME" \
  306. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v2/\$(project_id)s"
  307. get_or_create_service "cinderv3" "volumev3" "Cinder Volume Service V3"
  308. get_or_create_endpoint \
  309. "volumev3" \
  310. "$REGION_NAME" \
  311. "$CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST/volume/v3/\$(project_id)s"
  312. fi
  313. configure_cinder_internal_tenant
  314. fi
  315. }
  316. # init_cinder() - Initialize database and volume group
  317. function init_cinder {
  318. if is_service_enabled $DATABASE_BACKENDS; then
  319. # (Re)create cinder database
  320. recreate_database cinder
  321. time_start "dbsync"
  322. # Migrate cinder database
  323. $CINDER_BIN_DIR/cinder-manage --config-file $CINDER_CONF db sync
  324. time_stop "dbsync"
  325. fi
  326. if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  327. local be be_name be_type
  328. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  329. be_type=${be%%:*}
  330. be_name=${be##*:}
  331. if type init_cinder_backend_${be_type} >/dev/null 2>&1; then
  332. # Always init the default volume group for lvm.
  333. if [[ "$be_type" == "lvm" ]]; then
  334. init_default_lvm_volume_group
  335. fi
  336. init_cinder_backend_${be_type} ${be_name}
  337. fi
  338. done
  339. fi
  340. mkdir -p $CINDER_STATE_PATH/volumes
  341. }
  342. # install_cinder() - Collect source and prepare
  343. function install_cinder {
  344. git_clone $CINDER_REPO $CINDER_DIR $CINDER_BRANCH
  345. setup_develop $CINDER_DIR
  346. if [[ "$CINDER_ISCSI_HELPER" == "tgtadm" ]]; then
  347. install_package tgt
  348. elif [[ "$CINDER_ISCSI_HELPER" == "lioadm" ]]; then
  349. if [[ ${DISTRO} == "bionic" ]]; then
  350. # TODO(frickler): Workaround for https://launchpad.net/bugs/1819819
  351. sudo mkdir -p /etc/target
  352. install_package targetcli-fb
  353. else
  354. install_package targetcli
  355. fi
  356. fi
  357. }
  358. # install_cinderclient() - Collect source and prepare
  359. function install_cinderclient {
  360. if use_library_from_git "python-brick-cinderclient-ext"; then
  361. git_clone_by_name "python-brick-cinderclient-ext"
  362. setup_dev_lib "python-brick-cinderclient-ext"
  363. fi
  364. if use_library_from_git "python-cinderclient"; then
  365. git_clone_by_name "python-cinderclient"
  366. setup_dev_lib "python-cinderclient"
  367. sudo install -D -m 0644 -o $STACK_USER {${GITDIR["python-cinderclient"]}/tools/,/etc/bash_completion.d/}cinder.bash_completion
  368. fi
  369. }
  370. # apply config.d approach for cinder volumes directory
  371. function _configure_tgt_for_config_d {
  372. if [[ ! -d /etc/tgt/stack.d/ ]]; then
  373. sudo ln -sf $CINDER_STATE_PATH/volumes /etc/tgt/stack.d
  374. fi
  375. if ! grep -q "include /etc/tgt/stack.d/*" /etc/tgt/targets.conf; then
  376. echo "include /etc/tgt/stack.d/*" | sudo tee -a /etc/tgt/targets.conf
  377. fi
  378. }
  379. # start_cinder() - Start running processes
  380. function start_cinder {
  381. local service_port=$CINDER_SERVICE_PORT
  382. local service_protocol=$CINDER_SERVICE_PROTOCOL
  383. local cinder_url
  384. if is_service_enabled tls-proxy && [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  385. service_port=$CINDER_SERVICE_PORT_INT
  386. service_protocol="http"
  387. fi
  388. if [ "$CINDER_ISCSI_HELPER" = "tgtadm" ]; then
  389. if is_service_enabled c-vol; then
  390. # Delete any old stack.conf
  391. sudo rm -f /etc/tgt/conf.d/stack.conf
  392. _configure_tgt_for_config_d
  393. if is_ubuntu; then
  394. sudo service tgt restart
  395. elif is_suse; then
  396. # NOTE(dmllr): workaround restart bug
  397. # https://bugzilla.suse.com/show_bug.cgi?id=934642
  398. stop_service tgtd
  399. start_service tgtd
  400. else
  401. restart_service tgtd
  402. fi
  403. # NOTE(gfidente): ensure tgtd is running in debug mode
  404. sudo tgtadm --mode system --op update --name debug --value on
  405. fi
  406. fi
  407. if [[ "$ENABLED_SERVICES" =~ "c-api" ]]; then
  408. if [ "$CINDER_USE_MOD_WSGI" == "False" ]; then
  409. run_process c-api "$CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF"
  410. cinder_url=$service_protocol://$SERVICE_HOST:$service_port
  411. # Start proxy if tls enabled
  412. if is_service_enabled tls-proxy; then
  413. start_tls_proxy cinder '*' $CINDER_SERVICE_PORT $CINDER_SERVICE_HOST $CINDER_SERVICE_PORT_INT
  414. fi
  415. else
  416. run_process "c-api" "$CINDER_BIN_DIR/uwsgi --procname-prefix cinder-api --ini $CINDER_UWSGI_CONF"
  417. cinder_url=$service_protocol://$SERVICE_HOST/volume/v3
  418. fi
  419. fi
  420. echo "Waiting for Cinder API to start..."
  421. if ! wait_for_service $SERVICE_TIMEOUT $cinder_url; then
  422. die $LINENO "c-api did not start"
  423. fi
  424. run_process c-sch "$CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF"
  425. run_process c-bak "$CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF"
  426. run_process c-vol "$CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF"
  427. # NOTE(jdg): For cinder, startup order matters. To ensure that repor_capabilities is received
  428. # by the scheduler start the cinder-volume service last (or restart it) after the scheduler
  429. # has started. This is a quick fix for lp bug/1189595
  430. }
  431. # stop_cinder() - Stop running processes
  432. function stop_cinder {
  433. stop_process c-api
  434. stop_process c-bak
  435. stop_process c-sch
  436. stop_process c-vol
  437. }
  438. # create_volume_types() - Create Cinder's configured volume types
  439. function create_volume_types {
  440. # Create volume types
  441. if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then
  442. local be be_name
  443. for be in ${CINDER_ENABLED_BACKENDS//,/ }; do
  444. be_name=${be##*:}
  445. # NOTE (e0ne): openstack client doesn't work with cinder in noauth mode
  446. if is_service_enabled keystone; then
  447. openstack --os-region-name="$REGION_NAME" volume type create --property volume_backend_name="${be_name}" ${be_name}
  448. else
  449. # TODO (e0ne): use openstack client once it will support cinder in noauth mode:
  450. # https://bugs.launchpad.net/python-cinderclient/+bug/1755279
  451. local cinder_url
  452. cinder_url=$CINDER_SERVICE_PROTOCOL://$SERVICE_HOST:$CINDER_SERVICE_PORT/v3
  453. OS_USER_ID=$OS_USERNAME OS_PROJECT_ID=$OS_PROJECT_NAME cinder --os-auth-type noauth --os-endpoint=$cinder_url type-create ${be_name}
  454. 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}
  455. fi
  456. done
  457. fi
  458. }
  459. # Compatibility for Grenade
  460. function create_cinder_volume_group {
  461. # During a transition period Grenade needs to have this function defined
  462. # It is effectively a no-op in the Grenade 'target' use case
  463. :
  464. }
  465. function configure_cinder_internal_tenant {
  466. # Re-use the Cinder service account for simplicity.
  467. iniset $CINDER_CONF DEFAULT cinder_internal_tenant_project_id $(get_or_create_project $SERVICE_PROJECT_NAME)
  468. iniset $CINDER_CONF DEFAULT cinder_internal_tenant_user_id $(get_or_create_user "cinder")
  469. }
  470. function configure_cinder_image_volume_cache {
  471. # Expect CINDER_CACHE_ENABLED_FOR_BACKENDS to be a list of backends
  472. # similar to CINDER_ENABLED_BACKENDS with NAME:TYPE where NAME will
  473. # be the backend specific configuration stanza in cinder.conf.
  474. for be in ${CINDER_CACHE_ENABLED_FOR_BACKENDS//,/ }; do
  475. local be_name=${be##*:}
  476. iniset $CINDER_CONF $be_name image_volume_cache_enabled $CINDER_IMG_CACHE_ENABLED
  477. if [[ -n $CINDER_IMG_CACHE_SIZE_GB ]]; then
  478. iniset $CINDER_CONF $be_name image_volume_cache_max_size_gb $CINDER_IMG_CACHE_SIZE_GB
  479. fi
  480. if [[ -n $CINDER_IMG_CACHE_SIZE_COUNT ]]; then
  481. iniset $CINDER_CONF $be_name image_volume_cache_max_count $CINDER_IMG_CACHE_SIZE_COUNT
  482. fi
  483. done
  484. }
  485. # Restore xtrace
  486. $_XTRACE_CINDER
  487. # Tell emacs to use shell-script-mode
  488. ## Local variables:
  489. ## mode: shell-script
  490. ## End: