~hopem/charms/trusty/keystone/reloads

« back to all changes in this revision

Viewing changes to hooks/keystone_hooks.py

  • Committer: Edward Hope-Morley
  • Date: 2014-12-17 17:54:26 UTC
  • mfrom: (89.1.21 keystone.notifications)
  • Revision ID: edward.hope-morley@canonical.com-20141217175426-li6c8kzkjrcyrwd6
[hopem,r=wolsen,jamespage]
 
Adds keystone identity-notifications interface
  
This allows related units to receive broadcasts when
resources e.g. endpoints, change.

Closes-Bug: 1401861

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
 
3
import hashlib
3
4
import os
4
5
import sys
5
6
import time
54
55
    KEYSTONE_CONF,
55
56
    SSH_USER,
56
57
    STORED_PASSWD,
57
 
    setup_ipv6
 
58
    setup_ipv6,
 
59
    send_notifications,
58
60
)
59
61
 
60
62
from charmhelpers.contrib.hahelpers.cluster import (
198
200
 
199
201
@hooks.hook('identity-service-relation-changed')
200
202
def identity_changed(relation_id=None, remote_unit=None):
 
203
    notifications = {}
201
204
    if eligible_leader(CLUSTER_RES):
202
205
        add_service_to_keystone(relation_id, remote_unit)
203
206
        synchronize_ca()
 
207
 
 
208
        settings = relation_get(rid=relation_id, unit=remote_unit)
 
209
        service = settings.get('service', None)
 
210
        if service:
 
211
            # If service is known and endpoint has changed, notify service if
 
212
            # it is related with notifications interface.
 
213
            csum = hashlib.sha256()
 
214
            # We base the decision to notify on whether these parameters have
 
215
            # changed (if csum is unchanged from previous notify, relation will
 
216
            # not fire).
 
217
            csum.update(settings.get('public_url', None))
 
218
            csum.update(settings.get('admin_url', None))
 
219
            csum.update(settings.get('internal_url', None))
 
220
            notifications['%s-endpoint-changed' % (service)] = csum.hexdigest()
204
221
    else:
205
222
        # Each unit needs to set the db information otherwise if the unit
206
223
        # with the info dies the settings die with it Bug# 1355848
210
227
                relation_set(relation_id=rel_id, **peerdb_settings)
211
228
        log('Deferring identity_changed() to service leader.')
212
229
 
 
230
    if notifications:
 
231
        send_notifications(notifications)
 
232
 
213
233
 
214
234
@hooks.hook('cluster-relation-joined')
215
235
def cluster_joined(relation_id=None):