~gandelman-a/charms/precise/cinder/set_pg_number

« back to all changes in this revision

Viewing changes to hooks/cinder-hooks

  • Committer: Adam Gandelman
  • Date: 2013-06-03 17:34:04 UTC
  • mfrom: (16.2.32 cinder)
  • Revision ID: adamg@canonical.com-20130603173404-wg0uxudqi4f53ho2
Support for Grizzly. Support for HA.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash -e
2
2
 
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
6
6
else
7
 
  juju-log "ERROR: Could not source cinder-common from $CHARM_DIR."
 
7
  juju-log "ERROR: Could not source cinder-common from $HOOKS_DIR."
8
8
  exit 1
9
9
fi
10
10
 
11
11
install_hook() {
12
12
  install_source="$(config-get openstack-origin)"
13
13
 
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).
17
17
  . /etc/lsb-release
18
 
  [[ "$DISTRIB_CODENAME" == "precise" ]] &&
 
18
  [[ "$DISTRIB_CODENAME" == "precise" && "$install_source" == "distro" ]] &&
19
19
    install_source="cloud:precise-folsom"
20
20
 
21
21
  configure_install_source "$install_source"
35
35
      cinder_ctl cinder-volume restart
36
36
    fi
37
37
  fi
 
38
  configure_https
38
39
}
39
40
 
40
41
db_joined() {
44
45
}
45
46
 
46
47
db_changed() {
47
 
  db_host=$(relation-get private-address)
48
 
  db_password=$(relation-get password)
 
48
  local r_id="$1"
 
49
  local unit_id="$2"
 
50
  local r_arg=""
 
51
  [[ -n "$r_id" ]] && r_arg="-r $r_id"
 
52
  db_host=$(relation-get $r_arg db_host $unit_id)
 
53
  db_password=$(relation-get $r_arg password $unit_id)
49
54
 
50
55
  [[ -z "$db_host" ]] || [[ -z "$db_password" ]] &&
51
56
    juju-log "Missing DB_HOST|DB_PASSWORD, peer not ready? Will retry." &&
55
60
  cinder_db=$(config-get cinder-db)
56
61
  juju-log "cinder: Configuring cinder for database access to $cinder_db@$db_host"
57
62
  set_or_update sql_connection "mysql://$db_user:$db_password@$db_host/$cinder_db"
58
 
  cinder_ctl all stop
59
 
  /usr/bin/cinder-manage db sync
60
 
  cinder_ctl all start
 
63
  if eligible_leader 'res_cinder_vip'; then
 
64
      /usr/bin/cinder-manage db sync
 
65
  fi
 
66
  cinder_ctl all restart
61
67
}
62
68
 
63
69
amqp_joined() {
67
73
}
68
74
 
69
75
amqp_changed() {
70
 
  rabbit_host=$(relation-get private-address)
71
 
  rabbit_password=$(relation-get password)
 
76
  local r_id="$1"
 
77
  local unit_id="$2"
 
78
  local r_arg=""
 
79
  [[ -n "$r_id" ]] && r_arg="-r $r_id"
 
80
  rabbit_host=$(relation-get $r_arg private-address $unit_id)
 
81
  rabbit_password=$(relation-get $r_arg password $unit_id)
72
82
  [[ -z "$rabbit_host" ]] || [[ -z "$rabbit_password" ]] &&
73
83
    juju-log "Missing rabbit_host||rabbit_passwd, peer not ready? Will retry." && exit 0
 
84
  local clustered=$(relation-get $r_arg clustered $unit_id)
 
85
  if [[ -n "$clustered" ]] ; then
 
86
    juju-log "$CHARM - amqp_changed: Configuring for access to haclustered "\
 
87
             "rabbitmq service."
 
88
    local vip=$(relation-get $r_arg vip $unit_id)
 
89
    [[ -z "$vip" ]] && juju-log "$CHARM - amqp_changed: Clustered bu no vip."\
 
90
      && exit 0
 
91
    rabbit_host="$vip"
 
92
  fi
74
93
  juju-log "cinder: Configuring cinder for amqp access to $rabbit_host:$rabbit_vhost"
75
94
  rabbit_user=$(config-get rabbit-user)
76
95
  rabbit_vhost=$(config-get rabbit-vhost)
82
101
}
83
102
 
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
 
106
 
 
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)
 
111
 
 
112
  local url="$scheme://$host:$(config-get api-listening-port)/v1/\$(tenant_id)s"
 
113
  r_id=""
 
114
  if [[ -n "$1" ]] ; then
 
115
    r_id="-r $1"
 
116
  fi
 
117
  relation-set $r_id service="cinder" \
 
118
    region="$(config-get region)" public_url="$url" admin_url="$url" internal_url="$url"
89
119
}
90
120
 
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)
 
122
  local r_id="$1"
 
123
  local unit_id="$2"
 
124
  local r_arg=""
 
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)
97
133
 
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" &&
101
137
      exit 0
102
 
 
103
 
  keystone_host=$(relation-get private-address)
104
 
 
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"
114
147
  set_or_update "auth_strategy" "keystone" "$CINDER_CONF"
115
148
 
116
149
  cinder_ctl all restart
 
150
  configure_https
117
151
}
118
152
 
119
153
function ceph_joined {
122
156
}
123
157
 
124
158
function ceph_changed {
 
159
  local r_id="$1"
 
160
  local unit_id="$2"
 
161
  local r_arg=""
 
162
  [[ -n "$r_id" ]] && r_arg="-r $r_id"
125
163
  SERVICE_NAME=`echo $JUJU_UNIT_NAME | cut -d / -f 1`
126
164
  KEYRING=/etc/ceph/ceph.client.$SERVICE_NAME.keyring
127
 
  KEY=`relation-get key`
 
165
  KEY=`relation-get $r_arg key $unit_id`
128
166
  if [ -n "$KEY" ]; then
129
167
    # But only once
130
168
    if [ ! -f $KEYRING ]; then
138
176
    exit 0
139
177
  fi
140
178
 
141
 
  MONS=`relation-list`
 
179
  MONS=`relation-list $r_arg`
142
180
  mon_hosts=""
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"
145
183
  done
146
184
  cat > /etc/ceph/ceph.conf << EOF
147
185
[global]
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
151
189
EOF
152
190
 
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
 
196
  fi
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
159
200
 
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
 
206
    fi
163
207
  fi
164
208
 
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
169
217
}
170
218
 
 
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
 
230
}
 
231
 
 
232
function upgrade_charm() {
 
233
  cluster_changed
 
234
}
 
235
 
 
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.
 
247
    resources="{
 
248
'res_cinder_vip':'ocf:heartbeat:IPaddr2',
 
249
'res_cinder_haproxy':'lsb:haproxy'
 
250
}"
 
251
    resource_params="{
 
252
'res_cinder_vip': 'params ip=\"$vip\" cidr_netmask=\"$vip_cidr\" nic=\"$vip_iface\"',
 
253
'res_cinder_haproxy': 'op monitor interval=\"5s\"'
 
254
}"
 
255
    init_services="{
 
256
'res_cinder_haproxy':'haproxy'
 
257
}"
 
258
    clones="{
 
259
'cl_cinder_haproxy': 'res_cinder_haproxy'
 
260
}"
 
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"
 
265
  else
 
266
    juju-log "Insufficient configuration data to configure hacluster"
 
267
    exit 1
 
268
  fi
 
269
}
 
270
 
 
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"
 
277
    local r_id=""
 
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"
 
282
    done
 
283
  fi
 
284
}
 
285
 
 
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
 
296
  fi
 
297
 
 
298
  configure_https
 
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[@]}
 
306
}
 
307
 
 
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"
 
312
    exit 0
 
313
  fi
 
314
  set_or_update glance_api_servers $GLANCE_API_SERVER
 
315
  apt-get -y install qemu-utils
 
316
  cinder_ctl all restart
 
317
}
 
318
 
171
319
arg0=$(basename $0)
172
320
juju-log "cinder: Attempting to fire hook for: $arg0"
173
321
case $arg0 in
184
332
  "ceph-relation-changed") ceph_changed;;
185
333
  "cinder-volume-service-relation-joined") exit 0 ;;
186
334
  "cinder-volume-service-relation-changed") exit 0 ;;
 
335
  "cluster-relation-changed") cluster_changed ;;
 
336
  "cluster-relation-departed") cluster_changed ;;
 
337
  "image-service-relation-changed") image-service_changed ;;
 
338
  "ha-relation-joined") ha_relation_joined ;;
 
339
  "ha-relation-changed") ha_relation_changed ;;
 
340
  "upgrade-charm") upgrade_charm ;;
 
341
  "config-changed") config_changed ;;
187
342
  *) exit 0
188
343
esac