This is the first step in supporting multiple Cinder backend types at
once. It initially converts the existing hard-coded multi-lvm support
to a new cinder_backends driver form. Eventually the cinder_plugins
will be converted to this form so they can be enabled more than just
one at a time using CINDER_ENABLED_BACKENDS.
The default configuration should be identical to the previous defaults,
including for both True and False values of CINDER_MULTI_LVM_BACKEND.
The existing cinder_plugins are expected to be removed when this is
complete. They should continue to work until they have been converted.
Add wait for c-api to ensure it is started before continuing.
Change-Id: I93b8ef32832269d730c76a6dc24ddb4f20c6d9df
... | ... |
@@ -28,6 +28,7 @@ set +o xtrace |
28 | 28 |
# set up default driver |
29 | 29 |
CINDER_DRIVER=${CINDER_DRIVER:-default} |
30 | 30 |
CINDER_PLUGINS=$TOP_DIR/lib/cinder_plugins |
31 |
+CINDER_BACKENDS=$TOP_DIR/lib/cinder_backends |
|
31 | 32 |
|
32 | 33 |
# grab plugin config if specified via cinder_driver |
33 | 34 |
if [[ -r $CINDER_PLUGINS/$CINDER_DRIVER ]]; then |
... | ... |
@@ -57,9 +58,24 @@ else |
57 | 57 |
CINDER_BIN_DIR=$(get_python_exec_prefix) |
58 | 58 |
fi |
59 | 59 |
|
60 |
+ |
|
61 |
+# Maintain this here for backward-compatibility with the old configuration |
|
62 |
+# DEPRECATED: Use CINDER_ENABLED_BACKENDS instead |
|
60 | 63 |
# Support for multi lvm backend configuration (default is no support) |
61 | 64 |
CINDER_MULTI_LVM_BACKEND=$(trueorfalse False $CINDER_MULTI_LVM_BACKEND) |
62 | 65 |
|
66 |
+# Default backends |
|
67 |
+# The backend format is type:name where type is one of the supported backend |
|
68 |
+# types (lvm, nfs, etc) and name is the identifier used in the Cinder |
|
69 |
+# configuration and for the volume type name. Multiple backends are |
|
70 |
+# comma-separated. |
|
71 |
+if [[ $CINDER_MULTI_LVM_BACKEND == "False" ]]; then |
|
72 |
+ CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1} |
|
73 |
+else |
|
74 |
+ CINDER_ENABLED_BACKENDS=${CINDER_ENABLED_BACKENDS:-lvm:lvmdriver-1,lvm:lvmdriver-2} |
|
75 |
+fi |
|
76 |
+ |
|
77 |
+ |
|
63 | 78 |
# Should cinder perform secure deletion of volumes? |
64 | 79 |
# Defaults to true, can be set to False to avoid this bug when testing: |
65 | 80 |
# https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1023755 |
... | ... |
@@ -73,22 +89,22 @@ CINDER_SECURE_DELETE=`trueorfalse True $CINDER_SECURE_DELETE` |
73 | 73 |
# https://bugs.launchpad.net/cinder/+bug/1180976 |
74 | 74 |
CINDER_PERIODIC_INTERVAL=${CINDER_PERIODIC_INTERVAL:-60} |
75 | 75 |
|
76 |
-# Name of the lvm volume groups to use/create for iscsi volumes |
|
77 |
-VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes} |
|
78 |
-VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DATA_DIR/${VOLUME_GROUP}-backing-file} |
|
79 |
-VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-} |
|
80 |
- |
|
81 |
-# VOLUME_GROUP2 is used only if CINDER_MULTI_LVM_BACKEND = True |
|
82 |
-VOLUME_GROUP2=${VOLUME_GROUP2:-stack-volumes2} |
|
83 |
-VOLUME_BACKING_FILE2=${VOLUME_BACKING_FILE2:-$DATA_DIR/${VOLUME_GROUP2}-backing-file} |
|
84 |
-VOLUME_BACKING_DEVICE2=${VOLUME_BACKING_DEVICE2:-} |
|
85 |
- |
|
86 |
-VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-} |
|
87 |
- |
|
88 | 76 |
# Tell Tempest this project is present |
89 | 77 |
TEMPEST_SERVICES+=,cinder |
90 | 78 |
|
91 | 79 |
|
80 |
+# Source the enabled backends |
|
81 |
+if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then |
|
82 |
+ for be in ${CINDER_ENABLED_BACKENDS//,/ }; do |
|
83 |
+ BE_TYPE=${be%%:*} |
|
84 |
+ BE_NAME=${be##*:} |
|
85 |
+ if [[ -r $CINDER_BACKENDS/${BE_TYPE} ]]; then |
|
86 |
+ source $CINDER_BACKENDS/${BE_TYPE} |
|
87 |
+ fi |
|
88 |
+ done |
|
89 |
+fi |
|
90 |
+ |
|
91 |
+ |
|
92 | 92 |
# Functions |
93 | 93 |
# --------- |
94 | 94 |
|
... | ... |
@@ -99,41 +115,6 @@ function is_cinder_enabled { |
99 | 99 |
return 1 |
100 | 100 |
} |
101 | 101 |
|
102 |
-# _clean_lvm_lv removes all cinder LVM volumes |
|
103 |
-# |
|
104 |
-# Usage: _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX |
|
105 |
-function _clean_lvm_lv { |
|
106 |
- local vg=$1 |
|
107 |
- local lv_prefix=$2 |
|
108 |
- |
|
109 |
- # Clean out existing volumes |
|
110 |
- for lv in `sudo lvs --noheadings -o lv_name $vg`; do |
|
111 |
- # lv_prefix prefixes the LVs we want |
|
112 |
- if [[ "${lv#$lv_prefix}" != "$lv" ]]; then |
|
113 |
- sudo lvremove -f $vg/$lv |
|
114 |
- fi |
|
115 |
- done |
|
116 |
-} |
|
117 |
- |
|
118 |
-# _clean_lvm_backing_file() removes the backing file of the |
|
119 |
-# volume group used by cinder |
|
120 |
-# |
|
121 |
-# Usage: _clean_lvm_backing_file() $VOLUME_GROUP |
|
122 |
-function _clean_lvm_backing_file { |
|
123 |
- local vg=$1 |
|
124 |
- |
|
125 |
- # if there is no logical volume left, it's safe to attempt a cleanup |
|
126 |
- # of the backing file |
|
127 |
- if [ -z "`sudo lvs --noheadings -o lv_name $vg`" ]; then |
|
128 |
- # if the backing physical device is a loop device, it was probably setup by devstack |
|
129 |
- if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then |
|
130 |
- VG_DEV=$(sudo losetup -j $DATA_DIR/${vg}-backing-file | awk -F':' '/backing-file/ { print $1}') |
|
131 |
- sudo losetup -d $VG_DEV |
|
132 |
- rm -f $DATA_DIR/${vg}-backing-file |
|
133 |
- fi |
|
134 |
- fi |
|
135 |
-} |
|
136 |
- |
|
137 | 102 |
# cleanup_cinder() - Remove residual data files, anything left over from previous |
138 | 103 |
# runs that a clean run would need to clean up |
139 | 104 |
function cleanup_cinder { |
... | ... |
@@ -160,23 +141,20 @@ function cleanup_cinder { |
160 | 160 |
done |
161 | 161 |
fi |
162 | 162 |
|
163 |
- if is_service_enabled cinder; then |
|
164 |
- sudo rm -rf $CINDER_STATE_PATH/volumes/* |
|
165 |
- fi |
|
166 |
- |
|
167 | 163 |
if is_ubuntu; then |
168 | 164 |
stop_service tgt |
169 | 165 |
else |
170 | 166 |
stop_service tgtd |
171 | 167 |
fi |
172 | 168 |
|
173 |
- # Campsite rule: leave behind a volume group at least as clean as we found it |
|
174 |
- _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX |
|
175 |
- _clean_lvm_backing_file $VOLUME_GROUP |
|
176 |
- |
|
177 |
- if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then |
|
178 |
- _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX |
|
179 |
- _clean_lvm_backing_file $VOLUME_GROUP2 |
|
169 |
+ if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then |
|
170 |
+ for be in ${CINDER_ENABLED_BACKENDS//,/ }; do |
|
171 |
+ BE_TYPE=${be%%:*} |
|
172 |
+ BE_NAME=${be##*:} |
|
173 |
+ if type cleanup_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then |
|
174 |
+ cleanup_cinder_backend_${BE_TYPE} ${BE_NAME} |
|
175 |
+ fi |
|
176 |
+ done |
|
180 | 177 |
fi |
181 | 178 |
} |
182 | 179 |
|
... | ... |
@@ -243,23 +221,7 @@ function configure_cinder { |
243 | 243 |
iniset $CINDER_CONF DEFAULT auth_strategy keystone |
244 | 244 |
iniset $CINDER_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL |
245 | 245 |
iniset $CINDER_CONF DEFAULT verbose True |
246 |
- if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then |
|
247 |
- iniset $CINDER_CONF DEFAULT enabled_backends lvmdriver-1,lvmdriver-2 |
|
248 |
- iniset $CINDER_CONF lvmdriver-1 volume_group $VOLUME_GROUP |
|
249 |
- iniset $CINDER_CONF lvmdriver-1 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver |
|
250 |
- iniset $CINDER_CONF lvmdriver-1 volume_backend_name LVM_iSCSI |
|
251 |
- iniset $CINDER_CONF lvmdriver-2 volume_group $VOLUME_GROUP2 |
|
252 |
- iniset $CINDER_CONF lvmdriver-2 volume_driver cinder.volume.drivers.lvm.LVMISCSIDriver |
|
253 |
- iniset $CINDER_CONF lvmdriver-2 volume_backend_name LVM_iSCSI_2 |
|
254 |
- # NOTE(mriedem): Work around Cinder "wishlist" bug 1255593 |
|
255 |
- if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then |
|
256 |
- iniset $CINDER_CONF lvmdriver-1 volume_clear none |
|
257 |
- iniset $CINDER_CONF lvmdriver-2 volume_clear none |
|
258 |
- fi |
|
259 |
- else |
|
260 |
- iniset $CINDER_CONF DEFAULT volume_group $VOLUME_GROUP |
|
261 |
- iniset $CINDER_CONF DEFAULT volume_name_template ${VOLUME_NAME_PREFIX}%s |
|
262 |
- fi |
|
246 |
+ |
|
263 | 247 |
iniset $CINDER_CONF DEFAULT my_ip "$CINDER_SERVICE_HOST" |
264 | 248 |
iniset $CINDER_CONF DEFAULT iscsi_helper tgtadm |
265 | 249 |
iniset $CINDER_CONF DEFAULT sql_connection `database_connection_url cinder` |
... | ... |
@@ -274,6 +236,26 @@ function configure_cinder { |
274 | 274 |
# supported. |
275 | 275 |
iniset $CINDER_CONF DEFAULT enable_v1_api true |
276 | 276 |
|
277 |
+ if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then |
|
278 |
+ enabled_backends="" |
|
279 |
+ default_type="" |
|
280 |
+ for be in ${CINDER_ENABLED_BACKENDS//,/ }; do |
|
281 |
+ BE_TYPE=${be%%:*} |
|
282 |
+ BE_NAME=${be##*:} |
|
283 |
+ if type configure_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then |
|
284 |
+ configure_cinder_backend_${BE_TYPE} ${BE_NAME} |
|
285 |
+ fi |
|
286 |
+ if [[ -z "$default_type" ]]; then |
|
287 |
+ default_type=$BE_TYPE} |
|
288 |
+ fi |
|
289 |
+ enabled_backends+=$BE_NAME, |
|
290 |
+ done |
|
291 |
+ iniset $CINDER_CONF DEFAULT enabled_backends ${enabled_backends%,*} |
|
292 |
+ if [[ -n "$default_type" ]]; then |
|
293 |
+ iniset $CINDER_CONF DEFAULT default_volume_type ${enabled_backends%,*} |
|
294 |
+ fi |
|
295 |
+ fi |
|
296 |
+ |
|
277 | 297 |
if is_service_enabled swift; then |
278 | 298 |
iniset $CINDER_CONF DEFAULT backup_swift_url "http://$SERVICE_HOST:8080/v1/AUTH_" |
279 | 299 |
fi |
... | ... |
@@ -371,53 +353,6 @@ function create_cinder_cache_dir { |
371 | 371 |
rm -f $CINDER_AUTH_CACHE_DIR/* |
372 | 372 |
} |
373 | 373 |
|
374 |
-function create_cinder_volume_group { |
|
375 |
- # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes |
|
376 |
- # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume |
|
377 |
- # service if it (they) does (do) not yet exist. If you don't wish to use a |
|
378 |
- # file backed volume group, create your own volume group called ``stack-volumes`` |
|
379 |
- # and ``stack-volumes2`` before invoking ``stack.sh``. |
|
380 |
- # |
|
381 |
- # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in |
|
382 |
- # the ``DATA_DIR``. |
|
383 |
- |
|
384 |
- if ! sudo vgs $VOLUME_GROUP; then |
|
385 |
- if [ -z "$VOLUME_BACKING_DEVICE" ]; then |
|
386 |
- # Only create if the file doesn't already exists |
|
387 |
- [[ -f $VOLUME_BACKING_FILE ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE |
|
388 |
- DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE` |
|
389 |
- |
|
390 |
- # Only create if the loopback device doesn't contain $VOLUME_GROUP |
|
391 |
- if ! sudo vgs $VOLUME_GROUP; then |
|
392 |
- sudo vgcreate $VOLUME_GROUP $DEV |
|
393 |
- fi |
|
394 |
- else |
|
395 |
- sudo vgcreate $VOLUME_GROUP $VOLUME_BACKING_DEVICE |
|
396 |
- fi |
|
397 |
- fi |
|
398 |
- if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then |
|
399 |
- #set up the second volume if CINDER_MULTI_LVM_BACKEND is enabled |
|
400 |
- |
|
401 |
- if ! sudo vgs $VOLUME_GROUP2; then |
|
402 |
- if [ -z "$VOLUME_BACKING_DEVICE2" ]; then |
|
403 |
- # Only create if the file doesn't already exists |
|
404 |
- [[ -f $VOLUME_BACKING_FILE2 ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $VOLUME_BACKING_FILE2 |
|
405 |
- |
|
406 |
- DEV=`sudo losetup -f --show $VOLUME_BACKING_FILE2` |
|
407 |
- |
|
408 |
- # Only create if the loopback device doesn't contain $VOLUME_GROUP |
|
409 |
- if ! sudo vgs $VOLUME_GROUP2; then |
|
410 |
- sudo vgcreate $VOLUME_GROUP2 $DEV |
|
411 |
- fi |
|
412 |
- else |
|
413 |
- sudo vgcreate $VOLUME_GROUP2 $VOLUME_BACKING_DEVICE2 |
|
414 |
- fi |
|
415 |
- fi |
|
416 |
- fi |
|
417 |
- |
|
418 |
- mkdir -p $CINDER_STATE_PATH/volumes |
|
419 |
-} |
|
420 |
- |
|
421 | 374 |
# init_cinder() - Initialize database and volume group |
422 | 375 |
function init_cinder { |
423 | 376 |
# Force nova volumes off |
... | ... |
@@ -431,26 +366,17 @@ function init_cinder { |
431 | 431 |
$CINDER_BIN_DIR/cinder-manage db sync |
432 | 432 |
fi |
433 | 433 |
|
434 |
- if is_service_enabled c-vol; then |
|
435 |
- |
|
436 |
- create_cinder_volume_group |
|
437 |
- |
|
438 |
- if sudo vgs $VOLUME_GROUP; then |
|
439 |
- if is_fedora || is_suse; then |
|
440 |
- # service is not started by default |
|
441 |
- start_service tgtd |
|
434 |
+ if is_service_enabled c-vol && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then |
|
435 |
+ for be in ${CINDER_ENABLED_BACKENDS//,/ }; do |
|
436 |
+ BE_TYPE=${be%%:*} |
|
437 |
+ BE_NAME=${be##*:} |
|
438 |
+ if type init_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then |
|
439 |
+ init_cinder_backend_${BE_TYPE} ${BE_NAME} |
|
442 | 440 |
fi |
443 |
- |
|
444 |
- # Remove iscsi targets |
|
445 |
- sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true |
|
446 |
- # Start with a clean volume group |
|
447 |
- _clean_lvm_lv $VOLUME_GROUP $VOLUME_NAME_PREFIX |
|
448 |
- if [ "$CINDER_MULTI_LVM_BACKEND" = "True" ]; then |
|
449 |
- _clean_lvm_lv $VOLUME_GROUP2 $VOLUME_NAME_PREFIX |
|
450 |
- fi |
|
451 |
- fi |
|
441 |
+ done |
|
452 | 442 |
fi |
453 | 443 |
|
444 |
+ mkdir -p $CINDER_STATE_PATH/volumes |
|
454 | 445 |
create_cinder_cache_dir |
455 | 446 |
} |
456 | 447 |
|
... | ... |
@@ -502,6 +428,11 @@ function start_cinder { |
502 | 502 |
fi |
503 | 503 |
|
504 | 504 |
screen_it c-api "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-api --config-file $CINDER_CONF" |
505 |
+ echo "Waiting for Cinder API to start..." |
|
506 |
+ if ! wait_for_service $SERVICE_TIMEOUT $CINDER_SERVICE_PROTOCOL://$CINDER_SERVICE_HOST:$CINDER_SERVICE_PORT; then |
|
507 |
+ die $LINENO "c-api did not start" |
|
508 |
+ fi |
|
509 |
+ |
|
505 | 510 |
screen_it c-sch "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-scheduler --config-file $CINDER_CONF" |
506 | 511 |
screen_it c-bak "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-backup --config-file $CINDER_CONF" |
507 | 512 |
screen_it c-vol "cd $CINDER_DIR && $CINDER_BIN_DIR/cinder-volume --config-file $CINDER_CONF" |
... | ... |
@@ -532,6 +463,30 @@ function stop_cinder { |
532 | 532 |
fi |
533 | 533 |
} |
534 | 534 |
|
535 |
+# create_volume_types() - Create Cinder's configured volume types |
|
536 |
+function create_volume_types { |
|
537 |
+ # Create volume types |
|
538 |
+ if is_service_enabled c-api && [[ -n "$CINDER_ENABLED_BACKENDS" ]]; then |
|
539 |
+ for be in ${CINDER_ENABLED_BACKENDS//,/ }; do |
|
540 |
+ BE_TYPE=${be%%:*} |
|
541 |
+ BE_NAME=${be##*:} |
|
542 |
+ if type configure_cinder_backend_${BE_TYPE} >/dev/null 2>&1; then |
|
543 |
+ # openstack volume type create --property volume_backend_name="${BE_TYPE}" ${BE_NAME} |
|
544 |
+ cinder type-create ${BE_NAME} && \ |
|
545 |
+ cinder type-key ${BE_NAME} set volume_backend_name="${BE_NAME}" |
|
546 |
+ fi |
|
547 |
+ done |
|
548 |
+ fi |
|
549 |
+} |
|
550 |
+ |
|
551 |
+# Compatibility for Grenade |
|
552 |
+ |
|
553 |
+function create_cinder_volume_group { |
|
554 |
+ # During a transition period Grenade needs to have this function defined |
|
555 |
+ # It is effectively a no-op in the Grenade 'target' use case |
|
556 |
+ : |
|
557 |
+} |
|
558 |
+ |
|
535 | 559 |
|
536 | 560 |
# Restore xtrace |
537 | 561 |
$XTRACE |
538 | 562 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,179 @@ |
0 |
+# lib/cinder_backends/lvm |
|
1 |
+# Configure the LVM backend |
|
2 |
+ |
|
3 |
+# Enable with: |
|
4 |
+# |
|
5 |
+# CINDER_ENABLED_BACKENDS+=,lvm:lvmname |
|
6 |
+ |
|
7 |
+# Dependencies: |
|
8 |
+# |
|
9 |
+# - ``functions`` file |
|
10 |
+# - ``cinder`` configurations |
|
11 |
+ |
|
12 |
+# CINDER_CONF |
|
13 |
+# DATA_DIR |
|
14 |
+ |
|
15 |
+# clean_cinder_backend_lvm - called from clean_cinder() |
|
16 |
+# configure_cinder_backend_lvm - called from configure_cinder() |
|
17 |
+# init_cinder_backend_lvm - called from init_cinder() |
|
18 |
+ |
|
19 |
+ |
|
20 |
+# Save trace setting |
|
21 |
+MY_XTRACE=$(set +o | grep xtrace) |
|
22 |
+set +o xtrace |
|
23 |
+ |
|
24 |
+ |
|
25 |
+# Defaults |
|
26 |
+# -------- |
|
27 |
+ |
|
28 |
+# Name of the lvm volume groups to use/create for iscsi volumes |
|
29 |
+# This monkey-motion is for compatibility with icehouse-generation Grenade |
|
30 |
+# If ``VOLUME_GROUP`` is set, use it, otherwise we'll build a VG name based |
|
31 |
+# on ``VOLUME_GROUP_NAME`` that includes the backend name |
|
32 |
+# Grenade doesn't use ``VOLUME_GROUP2`` so it is left out |
|
33 |
+VOLUME_GROUP_NAME=${VOLUME_GROUP:-${VOLUME_GROUP_NAME:-stack-volumes}} |
|
34 |
+ |
|
35 |
+# TODO: resurrect backing device...need to know how to set values |
|
36 |
+#VOLUME_BACKING_DEVICE=${VOLUME_BACKING_DEVICE:-} |
|
37 |
+ |
|
38 |
+VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-} |
|
39 |
+ |
|
40 |
+ |
|
41 |
+# Entry Points |
|
42 |
+# ------------ |
|
43 |
+ |
|
44 |
+# Compatibility for getting a volume group name from either ``VOLUME_GROUP`` |
|
45 |
+# or from ``VOLUME_GROUP_NAME`` plus the backend name |
|
46 |
+function get_volume_group_name { |
|
47 |
+ local be_name=$1 |
|
48 |
+ |
|
49 |
+ # Again with the icehouse-generation compatibility |
|
50 |
+ local volume_group_name=$VOLUME_GROUP_NAME |
|
51 |
+ if [[ -z $VOLUME_GROUP ]]; then |
|
52 |
+ volume_group_name+="-$be_name" |
|
53 |
+ fi |
|
54 |
+ echo $volume_group_name |
|
55 |
+} |
|
56 |
+ |
|
57 |
+function cleanup_cinder_backend_lvm { |
|
58 |
+ local be_name=$1 |
|
59 |
+ |
|
60 |
+ # Again with the icehouse-generation compatibility |
|
61 |
+ local volume_group_name=$(get_volume_group_name $be_name) |
|
62 |
+ |
|
63 |
+ # Campsite rule: leave behind a volume group at least as clean as we found it |
|
64 |
+ _clean_lvm_lv ${volume_group_name} $VOLUME_NAME_PREFIX |
|
65 |
+ _clean_lvm_backing_file ${volume_group_name} $DATA_DIR/${volume_group_name}-backing-file |
|
66 |
+} |
|
67 |
+ |
|
68 |
+# configure_cinder_backend_lvm - Set config files, create data dirs, etc |
|
69 |
+# configure_cinder_backend_lvm $name |
|
70 |
+function configure_cinder_backend_lvm { |
|
71 |
+ local be_name=$1 |
|
72 |
+ |
|
73 |
+ # Again with the icehouse-generation compatibility |
|
74 |
+ local volume_group_name=$(get_volume_group_name $be_name) |
|
75 |
+ |
|
76 |
+ iniset $CINDER_CONF $be_name volume_backend_name $be_name |
|
77 |
+ iniset $CINDER_CONF $be_name volume_driver "cinder.volume.drivers.lvm.LVMISCSIDriver" |
|
78 |
+ iniset $CINDER_CONF $be_name volume_group $volume_group_name |
|
79 |
+ |
|
80 |
+ if [[ "$CINDER_SECURE_DELETE" == "False" ]]; then |
|
81 |
+ iniset $CINDER_CONF $be_name volume_clear none |
|
82 |
+ fi |
|
83 |
+} |
|
84 |
+ |
|
85 |
+ |
|
86 |
+function init_cinder_backend_lvm { |
|
87 |
+ local be_name=$1 |
|
88 |
+ |
|
89 |
+ # Again with the icehouse-generation compatibility |
|
90 |
+ local volume_group_name=$(get_volume_group_name $be_name) |
|
91 |
+ |
|
92 |
+ # Start with a clean volume group |
|
93 |
+ _create_cinder_volume_group ${volume_group_name} $DATA_DIR/${volume_group_name}-backing-file |
|
94 |
+ |
|
95 |
+ if is_fedora || is_suse; then |
|
96 |
+ # service is not started by default |
|
97 |
+ start_service tgtd |
|
98 |
+ fi |
|
99 |
+ |
|
100 |
+ # Remove iscsi targets |
|
101 |
+ sudo tgtadm --op show --mode target | grep $VOLUME_NAME_PREFIX | grep Target | cut -f3 -d ' ' | sudo xargs -n1 tgt-admin --delete || true |
|
102 |
+ _clean_lvm_lv ${volume_group_name} $VOLUME_NAME_PREFIX |
|
103 |
+} |
|
104 |
+ |
|
105 |
+ |
|
106 |
+# _clean_lvm_lv removes all cinder LVM volumes |
|
107 |
+# |
|
108 |
+# Usage: _clean_lvm_lv volume-group-name $VOLUME_NAME_PREFIX |
|
109 |
+function _clean_lvm_lv { |
|
110 |
+ local vg=$1 |
|
111 |
+ local lv_prefix=$2 |
|
112 |
+ |
|
113 |
+ # Clean out existing volumes |
|
114 |
+ for lv in $(sudo lvs --noheadings -o lv_name $vg 2>/dev/null); do |
|
115 |
+ # lv_prefix prefixes the LVs we want |
|
116 |
+ if [[ "${lv#$lv_prefix}" != "$lv" ]]; then |
|
117 |
+ sudo lvremove -f $vg/$lv |
|
118 |
+ fi |
|
119 |
+ done |
|
120 |
+} |
|
121 |
+ |
|
122 |
+# _clean_lvm_backing_file() removes the backing file of the |
|
123 |
+# volume group used by cinder |
|
124 |
+# |
|
125 |
+# Usage: _clean_lvm_backing_file() volume-group-name backing-file-name |
|
126 |
+function _clean_lvm_backing_file { |
|
127 |
+ local vg=$1 |
|
128 |
+ local backing_file=$2 |
|
129 |
+ |
|
130 |
+ # if there is no logical volume left, it's safe to attempt a cleanup |
|
131 |
+ # of the backing file |
|
132 |
+ if [[ -z "$(sudo lvs --noheadings -o lv_name $vg 2>/dev/null)" ]]; then |
|
133 |
+ # if the backing physical device is a loop device, it was probably setup by devstack |
|
134 |
+ VG_DEV=$(sudo losetup -j $backing_file | awk -F':' '/backing-file/ { print $1}') |
|
135 |
+ if [[ -n "$VG_DEV" ]] && [[ -e "$VG_DEV" ]]; then |
|
136 |
+ sudo losetup -d $VG_DEV |
|
137 |
+ rm -f $backing_file |
|
138 |
+ fi |
|
139 |
+ fi |
|
140 |
+} |
|
141 |
+ |
|
142 |
+# _create_cinder_volume_group volume-group-name backing-file-name |
|
143 |
+function _create_cinder_volume_group { |
|
144 |
+ # According to the ``CINDER_MULTI_LVM_BACKEND`` value, configure one or two default volumes |
|
145 |
+ # group called ``stack-volumes`` (and ``stack-volumes2``) for the volume |
|
146 |
+ # service if it (they) does (do) not yet exist. If you don't wish to use a |
|
147 |
+ # file backed volume group, create your own volume group called ``stack-volumes`` |
|
148 |
+ # and ``stack-volumes2`` before invoking ``stack.sh``. |
|
149 |
+ # |
|
150 |
+ # The two backing files are ``VOLUME_BACKING_FILE_SIZE`` in size, and they are stored in |
|
151 |
+ # the ``DATA_DIR``. |
|
152 |
+ |
|
153 |
+ local vg_name=$1 |
|
154 |
+ local backing_file=$2 |
|
155 |
+ |
|
156 |
+ if ! sudo vgs $vg_name; then |
|
157 |
+ # TODO: fix device handling |
|
158 |
+ if [ -z "$VOLUME_BACKING_DEVICE" ]; then |
|
159 |
+ # Only create if the file doesn't already exists |
|
160 |
+ [[ -f $backing_file ]] || truncate -s $VOLUME_BACKING_FILE_SIZE $backing_file |
|
161 |
+ DEV=`sudo losetup -f --show $backing_file` |
|
162 |
+ |
|
163 |
+ # Only create if the loopback device doesn't contain $VOLUME_GROUP |
|
164 |
+ if ! sudo vgs $vg_name; then |
|
165 |
+ sudo vgcreate $vg_name $DEV |
|
166 |
+ fi |
|
167 |
+ else |
|
168 |
+ sudo vgcreate $vg_name $VOLUME_BACKING_DEVICE |
|
169 |
+ fi |
|
170 |
+ fi |
|
171 |
+} |
|
172 |
+ |
|
173 |
+ |
|
174 |
+# Restore xtrace |
|
175 |
+$MY_XTRACE |
|
176 |
+ |
|
177 |
+# mode: shell-script |
|
178 |
+# End: |
0 | 179 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,43 @@ |
0 |
+# lib/cinder_backends/nfs |
|
1 |
+# Configure the nfs backend |
|
2 |
+ |
|
3 |
+# Enable with: |
|
4 |
+# |
|
5 |
+# CINDER_ENABLED_BACKENDS+=,nfs:<volume-type-name> |
|
6 |
+ |
|
7 |
+# Dependencies: |
|
8 |
+# |
|
9 |
+# - ``functions`` file |
|
10 |
+# - ``cinder`` configurations |
|
11 |
+ |
|
12 |
+# CINDER_CONF |
|
13 |
+# CINDER_CONF_DIR |
|
14 |
+# CINDER_NFS_SERVERPATH - contents of nfs shares config file |
|
15 |
+ |
|
16 |
+# configure_cinder_backend_nfs - Configure Cinder for NFS backends |
|
17 |
+ |
|
18 |
+# Save trace setting |
|
19 |
+NFS_XTRACE=$(set +o | grep xtrace) |
|
20 |
+set +o xtrace |
|
21 |
+ |
|
22 |
+ |
|
23 |
+# Entry Points |
|
24 |
+# ------------ |
|
25 |
+ |
|
26 |
+# configure_cinder_backend_nfs - Set config files, create data dirs, etc |
|
27 |
+function configure_cinder_backend_nfs { |
|
28 |
+ local be_name=$1 |
|
29 |
+ iniset $CINDER_CONF $be_name volume_backend_name $be_name |
|
30 |
+ iniset $CINDER_CONF $be_name volume_driver "cinder.volume.drivers.nfs.NfsDriver" |
|
31 |
+ iniset $CINDER_CONF $be_name nfs_shares_config "$CINDER_CONF_DIR/nfs-shares-$be_name.conf" |
|
32 |
+ |
|
33 |
+ echo "$CINDER_NFS_SERVERPATH" | tee "$CINDER_CONF_DIR/nfs-shares-$be_name.conf" |
|
34 |
+} |
|
35 |
+ |
|
36 |
+ |
|
37 |
+# Restore xtrace |
|
38 |
+$NFS_XTRACE |
|
39 |
+ |
|
40 |
+# Local variables: |
|
41 |
+# mode: shell-script |
|
42 |
+# End: |
... | ... |
@@ -1245,6 +1245,7 @@ fi |
1245 | 1245 |
if is_service_enabled cinder; then |
1246 | 1246 |
echo_summary "Starting Cinder" |
1247 | 1247 |
start_cinder |
1248 |
+ create_volume_types |
|
1248 | 1249 |
fi |
1249 | 1250 |
if is_service_enabled ceilometer; then |
1250 | 1251 |
echo_summary "Starting Ceilometer" |
... | ... |
@@ -1501,6 +1502,19 @@ if [[ -n "$Q_SRV_EXTRA_DEFAULT_OPTS" ]]; then |
1501 | 1501 |
done |
1502 | 1502 |
fi |
1503 | 1503 |
|
1504 |
+# TODO(dtroyer): Remove CINDER_MULTI_LVM_BACKEND after stable/juno branch is cut |
|
1505 |
+if [[ "$CINDER_MULTI_LVM_BACKEND" = "True" ]]; then |
|
1506 |
+ echo "" |
|
1507 |
+ echo_summary "WARNING: CINDER_MULTI_LVM_BACKEND is used" |
|
1508 |
+ echo "You are using CINDER_MULTI_LVM_BACKEND to configure Cinder's multiple LVM backends" |
|
1509 |
+ echo "Please convert that configuration in local.conf to use CINDER_ENABLED_BACKENDS." |
|
1510 |
+ echo "CINDER_ENABLED_BACKENDS will be removed early in the 'K' development cycle" |
|
1511 |
+ echo " |
|
1512 |
+[[local|localrc]] |
|
1513 |
+CINDER_ENABLED_BACKENDS=lvm:lvmdriver-1,lvm:lvmdriver-2 |
|
1514 |
+" |
|
1515 |
+fi |
|
1516 |
+ |
|
1504 | 1517 |
# Indicate how long this took to run (bash maintained variable ``SECONDS``) |
1505 | 1518 |
echo_summary "stack.sh completed in $SECONDS seconds." |
1506 | 1519 |
|
... | ... |
@@ -407,8 +407,7 @@ fi |
407 | 407 |
# 10Gb default volume backing file size |
408 | 408 |
VOLUME_BACKING_FILE_SIZE=${VOLUME_BACKING_FILE_SIZE:-10250M} |
409 | 409 |
|
410 |
-# Name of the LVM volume group to use/create for iscsi volumes |
|
411 |
-VOLUME_GROUP=${VOLUME_GROUP:-stack-volumes} |
|
410 |
+# Prefixes for volume and instance names |
|
412 | 411 |
VOLUME_NAME_PREFIX=${VOLUME_NAME_PREFIX:-volume-} |
413 | 412 |
INSTANCE_NAME_PREFIX=${INSTANCE_NAME_PREFIX:-instance-} |
414 | 413 |
|