~chris.macnaughton/charms/trusty/ceph-mon/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: james.page at ubuntu
  • Date: 2014-11-19 22:12:04 UTC
  • mfrom: (86.1.9 ceph)
  • Revision ID: james.page@ubuntu.com-20141119221204-tqm4c180rij1obrq
[dosaboy,r=james-page] Add broker functionality

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
import ceph
17
17
from charmhelpers.core.hookenv import (
18
 
    log, ERROR,
 
18
    log,
 
19
    DEBUG,
 
20
    ERROR,
19
21
    config,
20
22
    relation_ids,
21
23
    related_units,
25
27
    Hooks, UnregisteredHookError,
26
28
    service_name
27
29
)
28
 
 
29
30
from charmhelpers.core.host import (
30
31
    service_restart,
31
32
    umount,
44
45
    get_ipv6_addr,
45
46
    format_ipv6_addr
46
47
)
47
 
 
48
48
from utils import (
49
49
    render_template,
50
50
    get_public_addr,
51
51
    assert_charm_supports_ipv6
52
52
)
 
53
from ceph_broker import (
 
54
    process_requests
 
55
)
53
56
 
54
57
hooks = Hooks()
55
58
 
215
218
 
216
219
def notify_client():
217
220
    for relid in relation_ids('client'):
218
 
        client_relation(relid)
 
221
        client_relation_joined(relid)
219
222
 
220
223
 
221
224
def upgrade_keys():
266
269
 
267
270
 
268
271
@hooks.hook('client-relation-joined')
269
 
def client_relation(relid=None):
 
272
def client_relation_joined(relid=None):
270
273
    if ceph.is_quorum():
271
274
        log('mon cluster in quorum - providing client with keys')
272
275
        service_name = None
273
276
        if relid is None:
274
 
            service_name = remote_unit().split('/')[0]
 
277
            units = [remote_unit()]
 
278
            service_name = units[0].split('/')[0]
275
279
        else:
276
280
            units = related_units(relid)
277
281
            if len(units) > 0:
278
282
                service_name = units[0].split('/')[0]
 
283
 
279
284
        if service_name is not None:
280
 
            data = {
281
 
                'key': ceph.get_named_key(service_name),
282
 
                'auth': config('auth-supported'),
283
 
                'ceph-public-address': get_public_addr(),
284
 
            }
 
285
            data = {'key': ceph.get_named_key(service_name),
 
286
                    'auth': config('auth-supported'),
 
287
                    'ceph-public-address': get_public_addr()}
285
288
            relation_set(relation_id=relid,
286
289
                         relation_settings=data)
 
290
 
 
291
        client_relation_changed(relid=relid)
287
292
    else:
288
293
        log('mon cluster not in quorum - deferring key provision')
289
294
 
290
295
 
 
296
@hooks.hook('client-relation-changed')
 
297
def client_relation_changed(relid=None):
 
298
    """Process broker requests from ceph client relations."""
 
299
    if ceph.is_quorum():
 
300
        settings = relation_get(rid=relid)
 
301
        if 'broker_req' in settings:
 
302
            if not ceph.is_leader():
 
303
                log("Not leader - ignoring broker request", level=DEBUG)
 
304
            else:
 
305
                rsp = process_requests(settings['broker_req'])
 
306
                relation_set(relation_id=relid,
 
307
                             relation_settings={'broker_rsp': rsp})
 
308
    else:
 
309
        log('mon cluster not in quorum', level=DEBUG)
 
310
 
 
311
 
291
312
@hooks.hook('upgrade-charm')
292
313
def upgrade_charm():
293
314
    emit_cephconf()