3
CHARM_DIR=$(dirname $0)
4
if [[ -e $CHARM_DIR/cinder-common ]] ; then
5
. $CHARM_DIR/cinder-common
3
HOOKS_DIR="$CHARM_DIR/hooks"
4
if [[ -e $HOOKS_DIR/cinder-common ]] ; then
5
. $HOOKS_DIR/cinder-common
7
juju-log "ERROR: Could not source cinder-common from $CHARM_DIR."
7
juju-log "ERROR: Could not source cinder-common from $HOOKS_DIR."
12
12
install_source="$(config-get openstack-origin)"
14
# Check if we are deploying to Precise. If so, we need to use
15
# the Cloud Archive instead of the Ubuntu Archive since Cinder
16
# does not exist there (for precise).
14
# Check if we are deploying to Precise from distro.
15
# If so, we need to use the Cloud Archive instead of the
16
# Ubuntu Archive since Cinder does not exist there (for precise).
18
[[ "$DISTRIB_CODENAME" == "precise" ]] &&
18
[[ "$DISTRIB_CODENAME" == "precise" && "$install_source" == "distro" ]] &&
19
19
install_source="cloud:precise-folsom"
21
21
configure_install_source "$install_source"
84
103
keystone_joined() {
85
port=$(config-get api-listening-port)
86
url="http://$(unit-get private-address):$port/v1/\$(tenant_id)s"
87
relation-set service="cinder" \
88
region="RegionOne" public_url="$url" admin_url="$url" internal_url="$url"
104
# Exit hook execution if unit is not leader of cluster/service
105
eligible_leader 'res_cinder_vip' || return 0
107
# determine correct endpoint URL
108
https && scheme="https" || scheme="http"
109
is_clustered && local host=$(config-get vip) ||
110
local host=$(unit-get private-address)
112
local url="$scheme://$host:$(config-get api-listening-port)/v1/\$(tenant_id)s"
114
if [[ -n "$1" ]] ; then
117
relation-set $r_id service="cinder" \
118
region="$(config-get region)" public_url="$url" admin_url="$url" internal_url="$url"
91
121
keystone_changed() {
92
service_port=$(relation-get service_port)
93
auth_port=$(relation-get auth_port)
94
service_username=$(relation-get service_username)
95
service_password=$(relation-get service_password)
96
service_tenant=$(relation-get service_tenant)
125
[[ -n "$r_id" ]] && r_arg="-r $r_id"
126
service_port=$(relation-get $r_arg service_port $unit_id)
127
auth_port=$(relation-get $r_arg auth_port $unit_id)
128
service_username=$(relation-get $r_arg service_username $unit_id)
129
service_password=$(relation-get $r_arg service_password $unit_id)
130
service_tenant=$(relation-get $r_arg service_tenant $unit_id)
131
service_host=$(relation-get $r_arg service_host $unit_id)
132
auth_host=$(relation-get $r_arg auth_host $unit_id)
98
134
[[ -z "$service_port" ]] || [[ -z "$auth_port" ]] ||
99
135
[[ -z "$service_username" ]] || [[ -z "$service_password" ]] ||
100
136
[[ -z "$service_tenant" ]] && juju-log "keystone_changed: Peer not ready" &&
103
keystone_host=$(relation-get private-address)
105
138
# update keystone authtoken settings accordingly
106
set_or_update "service_host" "$keystone_host" "$API_CONF"
139
set_or_update "service_host" "$service_host" "$API_CONF"
107
140
set_or_update "service_port" "$service_port" "$API_CONF"
108
set_or_update "auth_host" "$keystone_host" "$API_CONF"
141
set_or_update "auth_host" "$auth_host" "$API_CONF"
109
142
set_or_update "auth_port" "$auth_port" "$API_CONF"
110
143
set_or_update "admin_tenant_name" "$service_tenant" "$API_CONF"
111
144
set_or_update "admin_user" "$service_username" "$API_CONF"
179
MONS=`relation-list $r_arg`
143
181
for mon in $MONS; do
144
mon_hosts="$mon_hosts $(get_ip $(relation-get private-address $mon)):6789"
182
mon_hosts="$mon_hosts $(get_ip $(relation-get $r_arg private-address $mon)):6789"
146
184
cat > /etc/ceph/ceph.conf << EOF
148
auth supported = $(relation-get auth)
186
auth supported = $(relation-get $r_id auth $unit_id)
149
187
keyring = /etc/ceph/\$cluster.\$name.keyring
150
188
mon host = $mon_hosts
153
191
# XXX: Horrid kludge to make cinder-volume use
154
192
# a different ceph username than admin
155
echo "CEPH_ARGS=--id $SERVICE_NAME" >> /etc/environment
193
if [ -z "`grep CEPH_ARGS /etc/environment`" ]; then
194
# Only insert environment var if we don't already have it
195
echo "CEPH_ARGS=\"--id $SERVICE_NAME\"" >> /etc/environment
156
197
# Also add it to the overrides for cinder volume
157
198
# in preparation for move to start-stop-daemon.
158
199
echo "env CEPH_ARGS=\"--id $SERVICE_NAME\"" > /etc/init/cinder-volume.override
160
# Create the cinder pool if it does not already exist
161
if ! rados --id $SERVICE_NAME lspools | grep -q cinder; then
162
rados --id $SERVICE_NAME mkpool cinder
201
# Only the leader should try to create pools
202
if eligible_leader 'res_cinder_vip'; then
203
# Create the cinder pool if it does not already exist
204
if ! rados --id $SERVICE_NAME lspools | grep -q cinder; then
205
rados --id $SERVICE_NAME mkpool cinder
165
209
# Reconfigure cinder-volume
166
210
set_or_update volume_driver cinder.volume.driver.RBDDriver
167
211
set_or_update rbd_pool cinder
212
# Set host to service name to ensure that requests get
213
# distributed across all cinder servers in a cluster
214
# as they can all service ceph requests.
215
set_or_update host "$SERVICE_NAME"
168
216
cinder_ctl "cinder-volume" restart
219
function cluster_changed() {
220
service_enabled "api" || return 0
221
[[ -z "$(peer_units)" ]] &&
222
juju-log "cluster_changed() with no peers." && exit 0
223
local cfg_api_port="$(config-get api-listening-port)"
224
local haproxy_port="$(determine_haproxy_port $cfg_api_port)"
225
local backend_port="$(determine_api_port $cfg_api_port)"
226
service cinder-api stop || :
227
configure_haproxy "cinder_api:$haproxy_port:$backend_port"
228
set_or_update osapi_volume_listen_port "$backend_port"
229
service cinder-api start
232
function upgrade_charm() {
236
function ha_relation_joined() {
237
local corosync_bindiface=`config-get ha-bindiface`
238
local corosync_mcastport=`config-get ha-mcastport`
239
local vip=`config-get vip`
240
local vip_iface=`config-get vip_iface`
241
local vip_cidr=`config-get vip_cidr`
242
if [ -n "$vip" ] && [ -n "$vip_iface" ] && \
243
[ -n "$vip_cidr" ] && [ -n "$corosync_bindiface" ] && \
244
[ -n "$corosync_mcastport" ]; then
245
# TODO: This feels horrible but the data required by the hacluster
246
# charm is quite complex and is python ast parsed.
248
'res_cinder_vip':'ocf:heartbeat:IPaddr2',
249
'res_cinder_haproxy':'lsb:haproxy'
252
'res_cinder_vip': 'params ip=\"$vip\" cidr_netmask=\"$vip_cidr\" nic=\"$vip_iface\"',
253
'res_cinder_haproxy': 'op monitor interval=\"5s\"'
256
'res_cinder_haproxy':'haproxy'
259
'cl_cinder_haproxy': 'res_cinder_haproxy'
261
relation-set corosync_bindiface=$corosync_bindiface \
262
corosync_mcastport=$corosync_mcastport \
263
resources="$resources" resource_params="$resource_params" \
264
init_services="$init_services" clones="$clones"
266
juju-log "Insufficient configuration data to configure hacluster"
271
function ha_relation_changed() {
272
local clustered=`relation-get clustered`
273
if [ -n "$clustered" ] && is_leader 'res_cinder_vip'; then
274
juju-log "Cluster leader, reconfiguring keystone endpoint"
275
https && local scheme="https" || local scheme="http"
276
local url="$scheme://$(config-get vip):$(config-get api-listening-port)/v1/\$(tenant_id)s"
278
for r_id in `relation-ids identity-service`; do
279
relation-set -r $r_id service="cinder" \
280
region="$(config-get region)" \
281
public_url="$url" admin_url="$url" internal_url="$url"
286
function config_changed() {
287
# possibly upgrade if openstack-origin has been bumped
288
local install_src=$(config-get openstack-origin)
289
local cur=$(get_os_codename_package "cinder-common")
290
local available=$(get_os_codename_install_source "$install_src")
291
if dpkg --compare-versions $(get_os_version_codename "$cur") lt \
292
$(get_os_version_codename "$available") ; then
293
juju-log "$CHARM: Upgrading OpenStack release: $cur -> $available."
294
# need to explicitly upgrade ksc b/c (LP: 1182689)
295
do_openstack_upgrade "$install_src" $(determine_packages) python-keystoneclient
299
# Save our scriptrc env variables for health checks
300
declare -a env_vars=(
301
"OPENSTACK_PORT_MCASTPORT=$(config-get ha-mcastport)"
302
'OPENSTACK_SERVICE_API=cinder-api'
303
'OPENSTACK_SERVICE_SCHEDULER=cinder-scheduler'
304
'OPENSTACK_SERVICE_VOLUME=cinder-volume')
305
save_script_rc ${env_vars[@]}
308
function image-service_changed {
309
GLANCE_API_SERVER=`relation-get glance-api-server`
310
if [[ -z $GLANCE_API_SERVER ]] ; then
311
echo "image-service_changed: GLANCE_API_SERVER not yet set. Exit 0 and retry"
314
set_or_update glance_api_servers $GLANCE_API_SERVER
315
apt-get -y install qemu-utils
316
cinder_ctl all restart
171
319
arg0=$(basename $0)
172
320
juju-log "cinder: Attempting to fire hook for: $arg0"