summaryrefslogtreecommitdiff
path: root/openstack-cinder.configure
blob: 0c15bd23afb5c8db709b323dd7a6b03451a9f474 (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
#!/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"

##########################################################################

ln -sf "/usr/lib/systemd/system/openstack-cinder-setup.service" \
    "$ROOT/etc/systemd/system/multi-user.target.wants/openstack-cinder-setup.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

##########################################################################
# 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