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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#!/bin/bash -e
CHARM_DIR=$(dirname $0)
if [[ -e $CHARM_DIR/cinder-common ]] ; then
. $CHARM_DIR/cinder-common
else
juju-log "ERROR: Could not source cinder-common from $CHARM_DIR."
exit 1
fi
install_hook() {
install_source="$(config-get openstack-origin)"
# Check if we are deploying to Precise. If so, we need to use
# the Cloud Archive instead of the Ubuntu Archive since Cinder
# does not exist there (for precise).
. /etc/lsb-release
[[ "$DISTRIB_CODENAME" == "precise" ]] &&
install_source="cloud:precise-folsom"
configure_install_source "$install_source"
apt-get update || true # ignore transient archive errors
pkgs=$(determine_packages)
juju-log "cinder: Installing following packages: $pkgs"
DEBIAN_FRONTEND=noninteractive apt-get -y install $pkgs
if service_enabled "volume" ; then
# prepare local storage if volume service is being installed.
block_dev=$(config-get block-device)
if [[ "$block_dev" != "None" && "$block_dev" != "none" ]] ; then
vol_group=$(config-get volume-group)
overwrite=$(config-get overwrite)
prepare_storage "$block_dev" "$vol_group" "$overwrite"
set_or_update "volume_group" "$vol_group"
cinder_ctl cinder-volume restart
fi
fi
}
db_joined() {
juju-log "cinder: Requesting database access to cinder database."
relation-set database=$(config-get cinder-db) username=$(config-get db-user)
relation-set hostname=$(unit-get private-address)
}
db_changed() {
db_host=$(relation-get private-address)
db_password=$(relation-get password)
[[ -z "$db_host" ]] || [[ -z "$db_password" ]] &&
juju-log "Missing DB_HOST|DB_PASSWORD, peer not ready? Will retry." &&
exit 0
db_user=$(config-get db-user)
cinder_db=$(config-get cinder-db)
juju-log "cinder: Configuring cinder for database access to $cinder_db@$db_host"
set_or_update sql_connection "mysql://$db_user:$db_password@$db_host/$cinder_db"
cinder_ctl all stop
/usr/bin/cinder-manage db sync
cinder_ctl all start
}
amqp_joined() {
juju-log "cinder: Requesting amqp access to vhost $rabbit_vhost."
relation-set username=$(config-get rabbit-user)
relation-set vhost=$(config-get rabbit-vhost)
}
amqp_changed() {
rabbit_host=$(relation-get private-address)
rabbit_password=$(relation-get password)
[[ -z "$rabbit_host" ]] || [[ -z "$rabbit_password" ]] &&
juju-log "Missing rabbit_host||rabbit_passwd, peer not ready? Will retry." && exit 0
juju-log "cinder: Configuring cinder for amqp access to $rabbit_host:$rabbit_vhost"
rabbit_user=$(config-get rabbit-user)
rabbit_vhost=$(config-get rabbit-vhost)
set_or_update rabbit_host $rabbit_host
set_or_update rabbit_userid $rabbit_user
set_or_update rabbit_password $rabbit_password
set_or_update rabbit_virtual_host $rabbit_vhost
cinder_ctl all restart
}
keystone_joined() {
port=$(config-get api-listening-port)
url="http://$(unit-get private-address):$port/v1/\$(tenant_id)s"
relation-set service="cinder" \
region="RegionOne" public_url="$url" admin_url="$url" internal_url="$url"
}
keystone_changed() {
service_port=$(relation-get service_port)
auth_port=$(relation-get auth_port)
service_username=$(relation-get service_username)
service_password=$(relation-get service_password)
service_tenant=$(relation-get service_tenant)
[[ -z "$service_port" ]] || [[ -z "$auth_port" ]] ||
[[ -z "$service_username" ]] || [[ -z "$service_password" ]] ||
[[ -z "$service_tenant" ]] && juju-log "keystone_changed: Peer not ready" &&
exit 0
keystone_host=$(relation-get private-address)
# update keystone authtoken settings accordingly
set_or_update "service_host" "$keystone_host" "$API_CONF"
set_or_update "service_port" "$service_port" "$API_CONF"
set_or_update "auth_host" "$keystone_host" "$API_CONF"
set_or_update "auth_port" "$auth_port" "$API_CONF"
set_or_update "admin_tenant_name" "$service_tenant" "$API_CONF"
set_or_update "admin_user" "$service_username" "$API_CONF"
set_or_update "admin_password" "$service_password" "$API_CONF"
set_or_update "auth_protocol" "http" "$API_CONF"
set_or_update "auth_strategy" "keystone" "$CINDER_CONF"
cinder_ctl all restart
}
function ceph_joined {
mkdir -p /etc/ceph
apt-get -y install ceph-common || exit 1
}
function ceph_changed {
SERVICE_NAME=`echo $JUJU_UNIT_NAME | cut -d / -f 1`
KEYRING=/etc/ceph/ceph.client.$SERVICE_NAME.keyring
KEY=`relation-get key`
if [ -n "$KEY" ]; then
# But only once
if [ ! -f $KEYRING ]; then
ceph-authtool $KEYRING \
--create-keyring --name=client.$SERVICE_NAME \
--add-key="$KEY"
chmod +r $KEYRING
fi
else
# No key - bail for the time being
exit 0
fi
MONS=`relation-list`
mon_hosts=""
for mon in $MONS; do
mon_hosts="$mon_hosts `relation-get private-address $mon`:6789"
done
cat > /etc/ceph/ceph.conf << EOF
[global]
auth supported = $(relation-get auth)
keyring = /etc/ceph/\$cluster.\$name.keyring
mon host = $mon_hosts
EOF
# XXX: Horrid kludge to make cinder-volume use
# a different ceph username than admin
echo "CEPH_ARGS=--id $SERVICE_NAME" >> /etc/environment
# Create the cinder pool if it does not already exist
if ! rados --id $SERVICE_NAME lspools | grep -q cinder; then
rados --id $SERVICE_NAME mkpool cinder
fi
# Reconfigure cinder-volume
set_or_update volume_driver cinder.volume.driver.RBDDriver
set_or_update rbd_pool cinder
cinder_ctl "cinder-volume" restart
}
arg0=$(basename $0)
juju-log "cinder: Attempting to fire hook for: $arg0"
case $arg0 in
"install") install_hook ;;
"start") cinder_ctl all start
"stop") cinder_ctl all stop
"shared-db-relation-joined") db_joined ;;
"shared-db-relation-changed") db_changed ;;
"amqp-relation-joined") amqp_joined ;;
"amqp-relation-changed") amqp_changed ;;
"identity-service-relation-joined") keystone_joined ;;
"identity-service-relation-changed") keystone_changed ;;
"ceph-relation-joined") ceph_joined;;
"ceph-relation-changed") ceph_changed;;
"cinder-volume-service-relation-joined") exit 0 ;;
"cinder-volume-service-relation-changed") exit 0 ;;
*) exit 0
esac
|