~tribaal/charms/trusty/nova-cloud-controller/sync-charm-helpers

« back to all changes in this revision

Viewing changes to hooks/nova-cloud-controller-relations

  • Committer: Adam Gandelman
  • Date: 2013-10-16 18:29:21 UTC
  • mfrom: (51.1.78 nova-cloud-controller)
  • Revision ID: adamg@canonical.com-20131016182921-vc7omtmypcxgusfd
Merge of python-redux work for havana cycle

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash -e
2
 
 
3
 
HOOKS_DIR="$CHARM_DIR/hooks"
4
 
arg0=$(basename $0)
5
 
 
6
 
if [[ -e $HOOKS_DIR/nova-cloud-controller-common ]] ; then
7
 
  . $HOOKS_DIR/nova-cloud-controller-common
8
 
else
9
 
  juju-log "ERROR: Could not load nova-cloud-controller-common from $HOOKS_DIR"
10
 
fi
11
 
 
12
 
function install_hook {
13
 
  juju-log "$CHARM: Installing nova packages"
14
 
  apt-get -y install python-software-properties || exit 1
15
 
  configure_install_source "$(config-get openstack-origin)"
16
 
  apt-get update || exit 1
17
 
 
18
 
  determine_packages
19
 
  DEBIAN_FRONTEND=noninteractive apt-get -y \
20
 
    install --no-install-recommends $PACKAGES || exit 1
21
 
 
22
 
  if [[ "$NET_MANAGER" == "Quantum" ]] ; then
23
 
    determine_quantum_config
24
 
  fi
25
 
  configure_network_manager $NET_MANAGER
26
 
 
27
 
  # Configure any flags specified in deployment config
28
 
  set_config_flags
29
 
 
30
 
  # Open up the various API endpoints
31
 
  # EC2
32
 
  open-port 8773
33
 
  # osapi-compute
34
 
  open-port 8774
35
 
  # object-store / s3
36
 
  open-port 3333
37
 
  # Quantum API if configured
38
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
39
 
    open-port 9696
40
 
  fi
41
 
 
42
 
  # Helpers for creating external and tenant networks
43
 
  cp files/create_ext_net.py /usr/bin/quantum-ext-net
44
 
  cp files/create_tenant_net.py /usr/bin/quantum-tenant-net
45
 
 
46
 
  service_ctl all stop
47
 
  configure_https
48
 
}
49
 
 
50
 
function upgrade_charm {
51
 
  install_hook
52
 
  service_ctl all start
53
 
}
54
 
 
55
 
function config_changed {
56
 
 
57
 
  # Determine whether or not we should do an upgrade, based on whether or not
58
 
  # the version offered in openstack-origin is greater than what is installed.
59
 
 
60
 
  local install_src=$(config-get openstack-origin)
61
 
  local cur=$(get_os_codename_package "nova-common")
62
 
  local available=$(get_os_codename_install_source "$install_src")
63
 
 
64
 
  if dpkg --compare-versions $(get_os_version_codename "$cur") lt \
65
 
                             $(get_os_version_codename "$available") ; then
66
 
    juju-log "$CHARM: Upgrading OpenStack release: $cur -> $available."
67
 
    determine_packages
68
 
    do_openstack_upgrade "$install_src" $PACKAGES
69
 
  fi
70
 
 
71
 
  set_config_flags
72
 
 
73
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
74
 
    configure_quantum_networking
75
 
  fi
76
 
 
77
 
  determine_services
78
 
  service_ctl all restart
79
 
 
80
 
  # Save our scriptrc env variables for health checks
81
 
  declare -a env_vars=(
82
 
      "OPENSTACK_PORT_MCASTPORT=$(config-get ha-mcastport)"
83
 
      'OPENSTACK_SERVICE_API_EC2=nova-api-ec2'
84
 
      'OPENSTACK_SERVICE_API_OS_COMPUTE=nova-api-os-compute'
85
 
      'OPENSTACK_SERVICE_CERT=nova-cert'
86
 
      'OPENSTACK_SERVICE_CONDUCTOR=nova-conductor'
87
 
      'OPENSTACK_SERVICE_OBJECTSTORE=nova-objectstore'
88
 
      'OPENSTACK_SERVICE_SCHEDULER=nova-scheduler')
89
 
  save_script_rc ${env_vars[@]}
90
 
  configure_https
91
 
}
92
 
 
93
 
function amqp_joined {
94
 
  # we request a username on the rabbit queue
95
 
  # and store it in nova.conf. our response is its IP + PASSWD
96
 
  # but we configure that in _changed
97
 
  local rabbit_user=$(config-get rabbit-user)
98
 
  local rabbit_vhost=$(config-get rabbit-vhost)
99
 
  juju-log "$CHARM - amqp_joined: requesting credentials for $rabbit_user"
100
 
  relation-set username=$rabbit_user
101
 
  relation-set vhost=$rabbit_vhost
102
 
}
103
 
 
104
 
function amqp_changed {
105
 
  # server creates our credentials and tells us where
106
 
  # to connect.  for now, using default vhost '/'
107
 
  local rabbit_host=$(relation-get private-address)
108
 
  local rabbit_password=$(relation-get password)
109
 
 
110
 
  if [[ -z $rabbit_host ]] || \
111
 
     [[ -z $rabbit_password ]] ; then
112
 
      juju-log "$CHARM - amqp_changed: rabbit_host||rabbit_password not set."
113
 
      exit 0
114
 
  fi
115
 
 
116
 
  # if the rabbitmq service is clustered among nodes with hacluster,
117
 
  # point to its vip instead of its private-address.
118
 
  local clustered=$(relation-get clustered)
119
 
  if [[ -n "$clustered" ]] ; then
120
 
    juju-log "$CHARM - ampq_changed: Configuring for "\
121
 
             "access to haclustered rabbitmq service."
122
 
    local vip=$(relation-get vip)
123
 
    [[ -z "$vip" ]] && juju-log "$CHARM - amqp_changed: Clustered but no vip."\
124
 
      && exit 0
125
 
    rabbit_host="$vip"
126
 
  fi
127
 
 
128
 
  local rabbit_user=$(config-get rabbit-user)
129
 
  local rabbit_vhost=$(config-get rabbit-vhost)
130
 
  juju-log "$CHARM - amqp_changed: Setting rabbit config in nova.conf: " \
131
 
           "$rabbit_user@$rabbit_host/$rabbit_vhost"
132
 
  set_or_update rabbit_host $rabbit_host
133
 
  set_or_update rabbit_userid $rabbit_user
134
 
  set_or_update rabbit_password $rabbit_password
135
 
  set_or_update rabbit_virtual_host $rabbit_vhost
136
 
 
137
 
  if [ "$(config-get network-manager)" == "Quantum" ]; then
138
 
    set_or_update rabbit_host "$rabbit_host" "$QUANTUM_CONF"
139
 
    set_or_update rabbit_userid "$rabbit_user" "$QUANTUM_CONF"
140
 
    set_or_update rabbit_password "$rabbit_password" "$QUANTUM_CONF"
141
 
    set_or_update rabbit_virtual_host "$rabbit_vhost" "$QUANTUM_CONF"
142
 
  fi
143
 
 
144
 
  determine_services && service_ctl all restart
145
 
 
146
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
147
 
    configure_quantum_networking
148
 
  fi
149
 
}
150
 
 
151
 
function db_joined {
152
 
  # tell mysql provider which database we want. it will create it and give us
153
 
  # credentials
154
 
  local nova_db=$(config-get nova-db)
155
 
  local db_user=$(config-get db-user)
156
 
  local hostname=$(unit-get private-address)
157
 
  juju-log "$CHARM - db_joined: requesting database access to $nova_db for "\
158
 
           "$db_user@$hostname"
159
 
  relation-set nova_database=$nova_db nova_username=$db_user nova_hostname=$hostname
160
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
161
 
    relation-set quantum_database=quantum quantum_username=quantum quantum_hostname=$hostname
162
 
  fi
163
 
}
164
 
 
165
 
function db_changed {
166
 
  local db_host=`relation-get db_host`
167
 
  local db_password=`relation-get nova_password`
168
 
 
169
 
  if [[ -z $db_host ]] || [[ -z $db_password ]] ; then
170
 
    juju-log "$CHARM - db_changed: db_host||db_password set, will retry."
171
 
    exit 0
172
 
  fi
173
 
 
174
 
  local nova_db=$(config-get nova-db)
175
 
  local db_user=$(config-get db-user)
176
 
  juju-log "$CHARM - db_changed: Configuring nova.conf for access to $nova_db"
177
 
 
178
 
  set_or_update sql_connection "mysql://$db_user:$db_password@$db_host/$nova_db"
179
 
 
180
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
181
 
    local quantum_db_password=`relation-get quantum_password`
182
 
    determine_quantum_config
183
 
    set_or_update sql_connection "mysql://quantum:$quantum_db_password@$db_host/quantum?charset=utf8" \
184
 
      $QUANTUM_PLUGIN_CONF "DATABASE"
185
 
  fi
186
 
 
187
 
  eligible_leader 'res_nova_vip' && /usr/bin/nova-manage db sync
188
 
 
189
 
  determine_services
190
 
  service_ctl all restart
191
 
 
192
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
193
 
    configure_quantum_networking
194
 
  fi
195
 
 
196
 
  trigger_remote_service_restarts
197
 
}
198
 
 
199
 
function image-service_changed {
200
 
  local api_server=$(relation-get glance-api-server)
201
 
  [[ -z $api_server ]] &&
202
 
    juju-log "$CHARM - image-service_changed: Peer not ready?" && exit 0
203
 
 
204
 
  if [[ "$(get_os_codename_package nova-common)" == "essex" ]] ; then
205
 
    # essex needs glance_api_servers urls stripped of protocol.
206
 
    api_server="$(echo $api_server | awk '{gsub(/http:\/\/|https:\/\//,"")}1')"
207
 
  fi
208
 
 
209
 
  set_or_update glance_api_servers $api_server
210
 
  set_or_update image_service "nova.image.glance.GlanceImageService"
211
 
  determine_services && service_ctl all restart
212
 
}
213
 
 
214
 
function keystone_joined {
215
 
  # we need to get two entries into keystone's catalog, nova + ec2
216
 
  # group, them by prepending $service_ to each setting. the keystone
217
 
  # charm will assemble settings into corresponding catalog entries
218
 
  eligible_leader 'res_nova_vip' || return 0
219
 
 
220
 
  is_clustered && local host=$(config-get vip) ||
221
 
    local host=$(unit-get private-address)
222
 
 
223
 
  if [[ "$arg0" == "identity-service-relation-joined" ]] ; then
224
 
    # determine https status based only on config at this point,
225
 
    # insepcting KS relation is not reliable.  if KS has mulitple
226
 
    # units, multiple relation-joineds are fired, resulting in the
227
 
    # endpoint being configured in catalog as https before https
228
 
    # is actually setup on this end. ends with failure to configure
229
 
    # quantum network, if its enabled.
230
 
    # if specified in config, https will have already been setup in
231
 
    # install or config-changed.
232
 
    if [[ -n "$(config-get ssl_cert)" ]] &&
233
 
       [[ -n "$(config-get ssl_key)" ]] ; then
234
 
      local scheme="https"
235
 
    else
236
 
      local scheme="http"
237
 
    fi
238
 
  else
239
 
    # this function is called from other hook contexts, use normal method
240
 
    # for determining https
241
 
    https && scheme="https" || scheme="http"
242
 
  fi
243
 
 
244
 
  local nova_url="$scheme://$host:8774/v1.1/\$(tenant_id)s"
245
 
  local ec2_url="$scheme://$host:8773/services/Cloud"
246
 
  local s3_url="$scheme://$host:3333"
247
 
  local region="$(config-get region)"
248
 
  local quantum_url="$scheme://$host:9696"
249
 
 
250
 
  # these are the default endpoints
251
 
  relation-set nova_service="nova" \
252
 
    nova_region="$region" \
253
 
    nova_public_url="$nova_url" \
254
 
    nova_admin_url="$nova_url" \
255
 
    nova_internal_url="$nova_url" \
256
 
    ec2_service="ec2" \
257
 
    ec2_region="$region" \
258
 
    ec2_public_url="$ec2_url" \
259
 
    ec2_admin_url="$ec2_url" \
260
 
    ec2_internal_url="$ec2_url" \
261
 
    s3_service="s3" \
262
 
    s3_region="$region" \
263
 
    s3_public_url="$s3_url" \
264
 
    s3_admin_url="$s3_url" \
265
 
    s3_internal_url="$s3_url"
266
 
 
267
 
  if [ "$(config-get network-manager)" == "Quantum" ]; then
268
 
    relation-set quantum_service="quantum" \
269
 
        quantum_region="$region" \
270
 
        quantum_public_url="$quantum_url" \
271
 
        quantum_admin_url="$quantum_url" \
272
 
        quantum_internal_url="$quantum_url"
273
 
  fi
274
 
 
275
 
  # tack on an endpoint for nova-volume a relation exists.
276
 
  if [[ -n "$(relation-ids nova-volume-service)" ]] ; then
277
 
    nova_vol_url="$scheme://$host:8776/v1/\$(tenant_id)s"
278
 
    relation-set nova-volume_service="nova-volume" \
279
 
      nova-volume_region="$region" \
280
 
      nova-volume_public_url="$nova_vol_url" \
281
 
      nova-volume_admin_url="$nova_vol_url" \
282
 
      nova-volume_internal_url="$nova_vol_url"
283
 
  fi
284
 
}
285
 
 
286
 
function keystone_changed {
287
 
  token=$(relation-get admin_token)
288
 
  service_port=$(relation-get service_port)
289
 
  auth_port=$(relation-get auth_port)
290
 
  service_username=$(relation-get service_username)
291
 
  service_password=$(relation-get service_password)
292
 
  service_tenant=$(relation-get service_tenant)
293
 
  region=$(config-get region)
294
 
 
295
 
  [[ -z "$token" ]] || [[ -z "$service_port" ]] || [[ -z "$auth_port" ]] ||
296
 
    [[ -z "$service_username" ]] || [[ -z "$service_password" ]] ||
297
 
    [[ -z "$service_tenant" ]] &&
298
 
      juju-log "$CHARM - keystone_changed: Peer not ready" && exit 0
299
 
 
300
 
  [[ "$token" == "-1" ]] &&
301
 
    juju-log "$CHARM - keystone_changed: admin token error" && exit 1
302
 
 
303
 
  # No need to update paste deploy pipelines, just set a flag in nova.conf
304
 
  set_or_update "auth_strategy" "keystone"
305
 
 
306
 
  # Update keystone authentication configuration
307
 
  service_host=$(relation-get service_host)
308
 
  auth_host=$(relation-get auth_host)
309
 
  set_or_update "keystone_ec2_url" "http://$service_host:$service_port/v2.0/ec2tokens"
310
 
 
311
 
  if grep -q use_deprecated_auth $NOVA_CONF ; then
312
 
    juju-log "$CHARM - keystone_changed: Disabling '--use_deprecated_auth"
313
 
    sed -i '/--use_deprecated_auth/d' $NOVA_CONF
314
 
  fi
315
 
 
316
 
  local clustered=""
317
 
  is_clustered && clustered="1"
318
 
 
319
 
  [[ -n "$clustered" ]]  && local host=$(config-get vip) ||
320
 
    local host=$(unit-get private-address)
321
 
  https && local scheme="https" || local scheme="http"
322
 
 
323
 
  # update keystone authtoken settings accordingly
324
 
  set_or_update "service_host" "$service_host" "$API_CONF"
325
 
  set_or_update "service_port" "$service_port" "$API_CONF"
326
 
  set_or_update "auth_host" "$auth_host" "$API_CONF"
327
 
  set_or_update "auth_port" "$auth_port" "$API_CONF"
328
 
  # XXX http hard-coded
329
 
  set_or_update "auth_uri" "http://$service_host:$service_port/" "$API_CONF"
330
 
  set_or_update "admin_token" "$token" "$API_CONF"
331
 
  set_or_update "admin_tenant_name" "$service_tenant" "$API_CONF"
332
 
  set_or_update "admin_user" "$service_username" "$API_CONF"
333
 
  set_or_update "admin_password" "$service_password" "$API_CONF"
334
 
 
335
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
336
 
    # Configure Nova for quantum
337
 
    keystone_url="http://${auth_host}:${auth_port}/v2.0"
338
 
    set_or_update "quantum_url" "$scheme://$host:9696"
339
 
    set_or_update "quantum_admin_tenant_name" "${service_tenant}"
340
 
    set_or_update "quantum_admin_username" "${service_username}"
341
 
    set_or_update "quantum_admin_password" "${service_password}"
342
 
    set_or_update "quantum_admin_auth_url" "${keystone_url}"
343
 
    # Configure API server for quantum
344
 
    set_or_update "admin_tenant_name" "$service_tenant" "$QUANTUM_API_CONF" "filter:authtoken"
345
 
    set_or_update "admin_user" "$service_username" "$QUANTUM_API_CONF" "filter:authtoken"
346
 
    set_or_update "admin_password" "$service_password" "$QUANTUM_API_CONF" "filter:authtoken"
347
 
    set_or_update "auth_host" "$auth_host" "$QUANTUM_API_CONF" "filter:authtoken"
348
 
    set_or_update "auth_port" "$auth_port" "$QUANTUM_API_CONF" "filter:authtoken"
349
 
    # Save a local copy of the credentials for later use
350
 
    cat > /etc/quantum/novarc << EOF
351
 
export OS_USERNAME=${service_username}
352
 
export OS_PASSWORD=${service_password}
353
 
export OS_TENANT_NAME=${service_tenant}
354
 
export OS_AUTH_URL=${keystone_url}
355
 
export OS_REGION_NAME=$region
356
 
EOF
357
 
  fi
358
 
 
359
 
  determine_services && service_ctl all restart
360
 
 
361
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
362
 
    # if first time here, config quantum before setting up
363
 
    # https.
364
 
    configure_quantum_networking
365
 
    # ripple out changes to identity to connected services
366
 
    # which use cloud-controller as source of information for
367
 
    # keystone
368
 
    local r_ids="$(relation-ids cloud-compute) $(relation-ids quantum-network-service)"
369
 
    for id in $r_ids ; do
370
 
      relation-set -r $id \
371
 
        keystone_host=$auth_host \
372
 
        auth_port=$auth_port \
373
 
        service_port=$service_port \
374
 
        service_username=$service_username \
375
 
        service_password=$service_password \
376
 
        service_tenant=$service_tenant \
377
 
        region=$region \
378
 
        # XXX http hard-coded
379
 
        auth_uri="http://$service_host:$service_port/"
380
 
 
381
 
    done
382
 
  fi
383
 
  configure_https
384
 
 
385
 
  # if this changed event happens as a result of clustered VIP
386
 
  # reconfigure, configure_https needs to update VIP certificate
387
 
  # before quantumclient is used.
388
 
  if [[ "$NET_MANAGER" == "Quantum" ]]; then
389
 
      configure_quantum_networking
390
 
  fi
391
 
}
392
 
 
393
 
volume_joined() {
394
 
  local svc=""
395
 
  case "$arg0" in
396
 
    "cinder-volume-service-relation-joined") svc="cinder" ;;
397
 
    "nova-volume-service-relation-joined") svc="nova-volume" ;;
398
 
    *) svc="nova-volume" ;;
399
 
  esac
400
 
 
401
 
  local cur_vers=$(get_os_codename_package "nova-common")
402
 
  if [[ "$cur_vers" != "essex" ]] && [[ "$cur_vers" != "folsom" ]] &&
403
 
     [[ "$svc" == "nova-volume" ]] ; then
404
 
    juju-log "$CHARM: WARNING nova-volume is only supported on Essex "\
405
 
             "and Folsom.  Ignoring new relation to nova-volume service."
406
 
    exit 0
407
 
  fi
408
 
 
409
 
  configure_volume_service "$svc"
410
 
  determine_services && service_ctl all restart
411
 
 
412
 
  # The nova-volume API can be hosted here alongside the other
413
 
  # nova API services, but there needs to be a new endpoint
414
 
  # configured in keystone.
415
 
  if [[ "$svc" == "nova-volume" ]] ; then
416
 
    apt-get -y install nova-api-os-volume
417
 
    local nova_vol_url="http://$(unit-get private-address):8776/v1/\$(tenant_id)s"
418
 
    local r_ids=$(relation-ids identity-service)
419
 
    for id in $r_ids ; do
420
 
      juju-log "$CHARM: Registering new endpoint for nova-volume API on "\
421
 
               "existing identity-service relation: $id"
422
 
      nova_vol_url="http://$(unit-get private-address):8776/v1/\$(tenant_id)s"
423
 
      relation-set -r $id nova-volume_service="nova-volume" \
424
 
        nova-volume_region="$(config-get region)" \
425
 
        nova-volume_public_url="$nova_vol_url" \
426
 
        nova-volume_admin_url="$nova_vol_url" \
427
 
        nova-volume_internal_url="$nova_vol_url"
428
 
    done
429
 
  fi
430
 
 
431
 
  if [[ "$svc" == "cinder" ]] ; then
432
 
    # Compute nodes need to be notified to set their volume
433
 
    # driver accordingly.
434
 
    r_ids=$(relation-ids cloud-compute)
435
 
    for id in $r_ids ; do
436
 
      relation-set -r $id volume_service="cinder"
437
 
    done
438
 
  fi
439
 
}
440
 
 
441
 
compute_joined() {
442
 
  local r_id="$1"
443
 
  [[ -n "$r_id" ]] && r_id="-r $r_id"
444
 
  eligible_leader 'res_nova_vip' || return 0
445
 
  relation-set $r_id network_manager=$(config-get network-manager)
446
 
  # XXX Should point to VIP if clustered, or this may not even be needed.
447
 
  relation-set $r_id ec2_host=$(unit-get private-address)
448
 
 
449
 
  local sect="filter:authtoken"
450
 
  keystone_host=$(local_config_get $API_CONF auth_host $sect)
451
 
 
452
 
  if [ "$NET_MANAGER" == "Quantum" ]; then
453
 
    if [[ -n "$keystone_host" ]]; then
454
 
      relation-set $r_id \
455
 
        keystone_host=$keystone_host \
456
 
        auth_port=$(local_config_get $API_CONF auth_port $sect) \
457
 
        service_port=$(local_config_get $API_CONF service_port $sect) \
458
 
        service_username=$(local_config_get $API_CONF admin_user $sect) \
459
 
        service_password=$(local_config_get $API_CONF admin_password $sect) \
460
 
        service_tenant=$(local_config_get $API_CONF admin_tenant_name $sect) \
461
 
        auth_uri=$(local_config_get $API_CONF auth_uri $sect)
462
 
    fi
463
 
    is_clustered && local host=$(config-get vip) ||
464
 
      local host=$(unit-get private-address)
465
 
    https && local scheme="https" || local scheme="http"
466
 
    local quantum_url="$scheme://$host:9696"
467
 
 
468
 
    relation-set $r_id quantum_url=$quantum_url \
469
 
                       quantum_plugin=$(config-get quantum-plugin) \
470
 
                       region=$(config-get region) \
471
 
                       quantum_security_groups=$(config-get quantum-security-groups)
472
 
 
473
 
  fi
474
 
 
475
 
  # must pass on the keystone CA certficiate, if it exists.
476
 
  cert="/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt"
477
 
  if [[ -n "$keystone_host" ]] && [[ -e $cert ]] ; then
478
 
    cert=$(cat $cert | base64)
479
 
    relation-set $r_id ca_cert="$cert"
480
 
  fi
481
 
 
482
 
  # volume driver is dependent on os version, or presence
483
 
  # of cinder (on folsom, at least)
484
 
  local cur_vers=$(get_os_codename_package "nova-common")
485
 
  local vol_drv="cinder"
486
 
  case "$cur_vers" in
487
 
    "essex")
488
 
      vol_drv="nova-volume"
489
 
      ;;
490
 
    "folsom")
491
 
      [[ -z "$(relation-ids cinder-volume-service)" ]] && vol_drv="nova-volume"
492
 
      ;;
493
 
  esac
494
 
  relation-set $r_id volume_service="$vol_drv"
495
 
}
496
 
 
497
 
compute_changed() {
498
 
  local migration_auth="$(relation-get migration_auth_type)"
499
 
  [[ -z "$migration_auth" ]] &&
500
 
    juju-log "$CHARM: compute_changed - Peer not ready or "\
501
 
             "no migration auth. configured." && exit 0
502
 
 
503
 
  case "$migration_auth" in
504
 
    "ssh") ssh_compute add ;;
505
 
  esac
506
 
}
507
 
 
508
 
compute_departed() {
509
 
  ssh_compute remove
510
 
}
511
 
 
512
 
function quantum_joined() {
513
 
  # Tell quantum service about keystone
514
 
  eligible_leader || return 0
515
 
  local r_id="$1"
516
 
  [[ -n "$r_id" ]] && r_id="-r $r_id"
517
 
 
518
 
  local sect="filter:authtoken"
519
 
  keystone_host=$(local_config_get $API_CONF auth_host $sect)
520
 
  if [ -n "$keystone_host" ]; then
521
 
    relation-set $r_id \
522
 
      keystone_host=$keystone_host \
523
 
      auth_port=$(local_config_get $API_CONF auth_port $sect) \
524
 
      service_port=$(local_config_get $API_CONF service_port $sect) \
525
 
      service_username=$(local_config_get $API_CONF admin_user $sect) \
526
 
      service_password=$(local_config_get $API_CONF admin_password $sect) \
527
 
      service_tenant=$(local_config_get $API_CONF admin_tenant_name $sect) \
528
 
      auth_uri=$(local_config_get $API_CONF auth_uri $sect)
529
 
  fi
530
 
 
531
 
  # must pass on the keystone CA certficiate, if it exists.
532
 
  cert="/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt"
533
 
  if [[ -n "$keystone_host" ]] && [[ -e $cert ]] ; then
534
 
    cert=$(cat $cert | base64)
535
 
    relation-set $r_id ca_cert="$cert"
536
 
  fi
537
 
 
538
 
  is_clustered && local host=$(config-get vip) ||
539
 
    local host=$(unit-get private-address)
540
 
  https && local scheme="https" || local scheme="http"
541
 
  local quantum_url="$scheme://$host:9696"
542
 
 
543
 
  relation-set $r_id quantum_host="$host" quantum_port="9696" \
544
 
                     quantum_url=$quantum_url \
545
 
                     quantum_plugin=$(config-get quantum-plugin) \
546
 
                     region=$(config-get region)
547
 
 
548
 
}
549
 
 
550
 
function cluster_changed() {
551
 
  [[ -z "$(peer_units)" ]] &&
552
 
    juju-log "cluster_changed() with no peers." && exit 0
553
 
  # upstartService:defaultPort:configOption
554
 
  local svcs="nova-api-ec2:8773:ec2_listen_port
555
 
              nova-api-os-compute:8774:osapi_compute_listen_port
556
 
              nova-objectstore:3333:s3_listen_port"
557
 
  [[ "$NET_MANAGER" == "Quantum" ]] &&
558
 
    svcs="$svcs quantum-server:9696:bind_port"
559
 
 
560
 
  for s in $svcs ; do
561
 
    local service=$(echo $s | cut -d: -f1)
562
 
    local port=$(echo $s | cut -d: -f2)
563
 
    local opt=$(echo $s | cut -d: -f3)
564
 
    local next_server="$(determine_haproxy_port $port)"
565
 
    local api_port="$(determine_api_port $port)"
566
 
    local haproxy_port_maps="$haproxy_port_maps $service:$next_server:$api_port:http"
567
 
    if [[ "$service" == "quantum-server" ]] ; then
568
 
      set_or_update "$opt" "$api_port" "$QUANTUM_CONF"
569
 
    else
570
 
      set_or_update "$opt" "$api_port"
571
 
    fi
572
 
 
573
 
    service_ctl $service restart
574
 
  done
575
 
  configure_haproxy $haproxy_port_maps
576
 
}
577
 
 
578
 
function ha_relation_joined() {
579
 
  local corosync_bindiface=`config-get ha-bindiface`
580
 
  local corosync_mcastport=`config-get ha-mcastport`
581
 
  local vip=`config-get vip`
582
 
  local vip_iface=`config-get vip_iface`
583
 
  local vip_cidr=`config-get vip_cidr`
584
 
  if [ -n "$vip" ] && [ -n "$vip_iface" ] && \
585
 
     [ -n "$vip_cidr" ] && [ -n "$corosync_bindiface" ] && \
586
 
     [ -n "$corosync_mcastport" ]; then
587
 
    # TODO: This feels horrible but the data required by the hacluster
588
 
    # charm is quite complex and is python ast parsed.
589
 
    resources="{
590
 
'res_nova_vip':'ocf:heartbeat:IPaddr2',
591
 
'res_nova_haproxy':'lsb:haproxy'
592
 
}"
593
 
    resource_params="{
594
 
'res_nova_vip': 'params ip=\"$vip\" cidr_netmask=\"$vip_cidr\" nic=\"$vip_iface\"',
595
 
'res_nova_haproxy': 'op monitor interval=\"5s\"'
596
 
}"
597
 
    init_services="{
598
 
'res_nova_haproxy':'haproxy'
599
 
}"
600
 
    clones="{
601
 
'cl_nova_haproxy':'res_nova_haproxy'
602
 
}"
603
 
    relation-set corosync_bindiface=$corosync_bindiface \
604
 
      corosync_mcastport=$corosync_mcastport \
605
 
      resources="$resources" resource_params="$resource_params" \
606
 
      init_services="$init_services" clones="$clones"
607
 
  else
608
 
    juju-log "Insufficient configuration data to configure hacluster"
609
 
    exit 1
610
 
  fi
611
 
}
612
 
 
613
 
function ha_relation_changed() {
614
 
  local clustered=`relation-get clustered`
615
 
  if [ -n "$clustered" ] && is_leader 'res_nova_vip'; then
616
 
    https && local scheme="https" || local scheme="http"
617
 
    for r_id in `relation-ids identity-service`; do
618
 
      local address=$(config-get vip)
619
 
      local region=$(config-get region)
620
 
      local nova_url="$scheme://$address:8774/v1.1/\$(tenant_id)s"
621
 
      local ec2_url="$scheme://$address:8773/services/Cloud"
622
 
      local s3_url="$scheme://$address:3333"
623
 
      local quantum_url="$scheme://$address:9696"
624
 
      local nova_vol_url="$scheme://$address:8776/v1/\$(tenant_id)s"
625
 
 
626
 
      relation-set -r $r_id \
627
 
        nova_service="nova" \
628
 
        nova_region="$region" \
629
 
        nova_public_url="$nova_url" \
630
 
        nova_admin_url="$nova_url" \
631
 
        nova_internal_url="$nova_url" \
632
 
        ec2_service="ec2" \
633
 
        ec2_region="$region" \
634
 
        ec2_public_url="$ec2_url" \
635
 
        ec2_admin_url="$ec2_url" \
636
 
        ec2_internal_url="$ec2_url" \
637
 
        s3_service="s3" \
638
 
        s3_region="$region" \
639
 
        s3_public_url="$s3_url" \
640
 
        s3_admin_url="$s3_url" \
641
 
        s3_internal_url="$s3_url"
642
 
 
643
 
      if [ "$(config-get network-manager)" == "Quantum" ]; then
644
 
        relation-set -r $r_id \
645
 
          quantum_service="quantum" \
646
 
          quantum_region="$region" \
647
 
          quantum_public_url="$quantum_url" \
648
 
          quantum_admin_url="$quantum_url" \
649
 
          quantum_internal_url="$quantum_url"
650
 
      fi
651
 
 
652
 
      if [[ -n "$(relation-ids nova-volume-service)" ]] ; then
653
 
        relation-set -r $r_id \
654
 
          nova-volume_service="nova-volume" \
655
 
          nova-volume_region="$region" \
656
 
          nova-volume_public_url="$nova_vol_url" \
657
 
          nova-volume_admin_url="$nova_vol_url" \
658
 
          nova-volume_internal_url="$nova_vol_url"
659
 
      fi
660
 
    done
661
 
    if [ "$(config-get network-manager)" == "Quantum" ]; then
662
 
      # Let gateway nodes use the new HA address for the
663
 
      # quantum API server
664
 
      for r_id in `relation-ids quantum-network-service`; do
665
 
        relation-set -r $r_id \
666
 
          quantum_host="$address" quantum_port="9696" \
667
 
          quantum_url="$quantum_url" region="$region"
668
 
      done
669
 
    fi
670
 
  fi
671
 
}
672
 
 
673
 
arg0=$(basename $0)
674
 
case $arg0 in
675
 
  "start"|"stop") determine_services ; service_ctl all $arg0 ;;
676
 
  "install") install_hook ;;
677
 
  "config-changed") config_changed ;;
678
 
  "upgrade-charm") upgrade_charm ;;
679
 
  "amqp-relation-joined") amqp_joined ;;
680
 
  "amqp-relation-changed") amqp_changed ;;
681
 
  "shared-db-relation-joined") db_joined ;;
682
 
  "shared-db-relation-changed") db_changed ;;
683
 
  "image-service-relation-joined") exit 0 ;;
684
 
  "image-service-relation-changed") image-service_changed ;;
685
 
  "identity-service-relation-joined") keystone_joined ;;
686
 
  "identity-service-relation-changed") keystone_changed ;;
687
 
  "cinder-volume-service-relation-joined") volume_joined ;;
688
 
  "nova-volume-service-relation-joined") volume_joined ;;
689
 
  "cloud-compute-relation-joined") compute_joined ;;
690
 
  "cloud-compute-relation-changed") compute_changed ;;
691
 
  "cloud-compute-relation-departed") compute_departed ;;
692
 
  "quantum-network-service-relation-joined") quantum_joined ;;
693
 
  "cluster-relation-changed") cluster_changed ;;
694
 
  "cluster-relation-departed") cluster_changed ;;
695
 
  "ha-relation-joined") ha_relation_joined ;;
696
 
  "ha-relation-changed") ha_relation_changed ;;
697
 
  *) exit 0 ;;
698
 
esac