summaryrefslogtreecommitdiff
path: root/openstack-cinder.configure
blob: a971dc4c59fa08ff3960bd95c879ae411fed0845 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/sh

# Copyright (C) 2014-2015  Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e

ROOT="$1"

enable(){
    ln -sf "/usr/lib/systemd/system/$1.service" \
            "$ROOT/etc/systemd/system/multi-user.target.wants/$1.service"
}

##########################################################################
# Check variables
##########################################################################

if [ -z "$RABBITMQ_HOST" -a \
     -z "$RABBITMQ_PORT" -a \
     -z "$RABBITMQ_USER" -a \
     -z "$RABBITMQ_PASSWORD" -a \
     -z "$KEYSTONE_TEMPORARY_ADMIN_TOKEN" -a \
     -z "$CINDER_DB_USER" -a \
     -z "$CINDER_DB_PASSWORD" -a \
     -z "$CONTROLLER_HOST_ADDRESS" -a \
     -z "$CINDER_SERVICE_USER" -a \
     -z "$CINDER_SERVICE_PASSWORD" -a \
     -z "$CINDER_DEVICE" -a \
     -z "$MANAGEMENT_INTERFACE_IP_ADDRESS" ]; then
     # No Cinder options defined, do nothing.
     exit 0
fi

if [ -z "$RABBITMQ_HOST" -o \
     -z "$RABBITMQ_PORT" -o \
     -z "$RABBITMQ_USER" -o \
     -z "$RABBITMQ_PASSWORD" -o \
     -z "$KEYSTONE_TEMPORARY_ADMIN_TOKEN" -o \
     -z "$CINDER_DB_USER" -o \
     -z "$CINDER_DB_PASSWORD" -o \
     -z "$CONTROLLER_HOST_ADDRESS" -o \
     -z "$CINDER_SERVICE_USER" -o \
     -z "$CINDER_SERVICE_PASSWORD" -o \
     -z "$CINDER_DEVICE" -o \
     -z "$MANAGEMENT_INTERFACE_IP_ADDRESS" ]; then
    echo Some options required for Cinder were defined, but not all.
    exit 1
fi

# Check optional variables

unnaceptable(){
    eval echo Unexpected value \$$1 for $1 >&2
    exit 1
}

check_bool(){
    case "$(eval echo \"\$$1\")" in
    True|'')
        eval "$1=true"
        ;;
    False)
        eval "$1=false"
        ;;
    *)
        unnaceptable "$1"
        ;;
    esac
}

check_bool CINDER_ENABLE_CONTROLLER
check_bool CINDER_ENABLE_COMPUTE
check_bool CINDER_ENABLE_STORAGE

######################################
# Enable relevant openstack services #
######################################

if "$CINDER_ENABLE_COMPUTE" || "$CINDER_ENABLE_STORAGE"; then
    enable openstack-cinder-iscsi-setup
    enable target #target.service!
    enable iscsid
fi
if "$CINDER_ENABLE_COMPUTE" || "$CINDER_ENABLE_CONTROLLER"; then
    enable openstack-cinder-config-setup
fi
if "$CINDER_ENABLE_STORAGE"; then
    enable openstack-cinder-lv-setup
    enable lvm2-lvmetad
    enable openstack-cinder-volume
    enable openstack-cinder-backup
    enable openstack-cinder-scheduler
fi
if "$CINDER_ENABLE_CONTROLLER"; then
    enable openstack-cinder-db-setup
    enable openstack-cinder-api
fi

##########################################################################
# Generate configuration file
##########################################################################

OPENSTACK_DATA="$ROOT/etc/openstack"
mkdir -p "$OPENSTACK_DATA"

python <<'EOF' >"$OPENSTACK_DATA/cinder.conf"
import os, sys, yaml

cinder_configuration={
    'RABBITMQ_HOST':os.environ['RABBITMQ_HOST'],
    'RABBITMQ_PORT':os.environ['RABBITMQ_PORT'],
    'RABBITMQ_USER':os.environ['RABBITMQ_USER'],
    'RABBITMQ_PASSWORD':os.environ['RABBITMQ_PASSWORD'],
    'KEYSTONE_TEMPORARY_ADMIN_TOKEN':os.environ['KEYSTONE_TEMPORARY_ADMIN_TOKEN'],
    'CINDER_DB_USER':os.environ['CINDER_DB_USER'],
    'CINDER_DB_PASSWORD':os.environ['CINDER_DB_PASSWORD'],
    'CONTROLLER_HOST_ADDRESS':os.environ['CONTROLLER_HOST_ADDRESS'],
    'CINDER_SERVICE_USER':os.environ['CINDER_SERVICE_USER'],
    'CINDER_SERVICE_PASSWORD':os.environ['CINDER_SERVICE_PASSWORD'],
    'CINDER_DEVICE':os.environ['CINDER_DEVICE'],
    'MANAGEMENT_INTERFACE_IP_ADDRESS':os.environ['MANAGEMENT_INTERFACE_IP_ADDRESS'],
}

yaml.dump(cinder_configuration, sys.stdout, default_flow_style=False)
EOF