~1chb1n/charms/trusty/ceph/next1507-amulet-cleanup

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Liam Young
  • Date: 2015-01-09 16:19:00 UTC
  • mfrom: (92 ceph)
  • mto: This revision was merged to the branch mainline in revision 93.
  • Revision ID: liam.young@canonical.com-20150109161900-osk2cinqq7caubsg
Merged next in and resolved conflicts

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,
27
29
    service_name,
28
30
    relations_of_type
29
31
)
30
 
 
31
32
from charmhelpers.core.host import (
32
33
    service_restart,
33
34
    umount,
48
49
    get_ipv6_addr,
49
50
    format_ipv6_addr
50
51
)
 
52
from charmhelpers.core.sysctl import create as create_sysctl
51
53
 
52
54
from utils import (
53
55
    render_template,
54
56
    get_public_addr,
55
57
    assert_charm_supports_ipv6
56
58
)
 
59
from ceph_broker import (
 
60
    process_requests
 
61
)
57
62
 
58
63
from charmhelpers.contrib.charmsupport.nrpe import NRPE
59
64
 
130
135
        log('Invalid OSD disk format configuration specified', level=ERROR)
131
136
        sys.exit(1)
132
137
 
 
138
    sysctl_dict = config('sysctl')
 
139
    if sysctl_dict:
 
140
        create_sysctl(sysctl_dict, '/etc/sysctl.d/50-ceph-charm.conf')
 
141
 
133
142
    emit_cephconf()
134
143
 
135
144
    e_mountpoint = config('ephemeral-unmount')
229
238
 
230
239
def notify_client():
231
240
    for relid in relation_ids('client'):
232
 
        client_relation(relid)
 
241
        client_relation_joined(relid)
233
242
 
234
243
 
235
244
def upgrade_keys():
280
289
 
281
290
 
282
291
@hooks.hook('client-relation-joined')
283
 
def client_relation(relid=None):
 
292
def client_relation_joined(relid=None):
284
293
    if ceph.is_quorum():
285
294
        log('mon cluster in quorum - providing client with keys')
286
295
        service_name = None
287
296
        if relid is None:
288
 
            service_name = remote_unit().split('/')[0]
 
297
            units = [remote_unit()]
 
298
            service_name = units[0].split('/')[0]
289
299
        else:
290
300
            units = related_units(relid)
291
301
            if len(units) > 0:
292
302
                service_name = units[0].split('/')[0]
 
303
 
293
304
        if service_name is not None:
294
 
            data = {
295
 
                'key': ceph.get_named_key(service_name),
296
 
                'auth': config('auth-supported'),
297
 
                'ceph-public-address': get_public_addr(),
298
 
            }
 
305
            data = {'key': ceph.get_named_key(service_name),
 
306
                    'auth': config('auth-supported'),
 
307
                    'ceph-public-address': get_public_addr()}
299
308
            relation_set(relation_id=relid,
300
309
                         relation_settings=data)
 
310
 
 
311
        client_relation_changed(relid=relid)
301
312
    else:
302
313
        log('mon cluster not in quorum - deferring key provision')
303
314
 
304
315
 
 
316
@hooks.hook('client-relation-changed')
 
317
def client_relation_changed(relid=None):
 
318
    """Process broker requests from ceph client relations."""
 
319
    if ceph.is_quorum():
 
320
        settings = relation_get(rid=relid)
 
321
        if 'broker_req' in settings:
 
322
            if not ceph.is_leader():
 
323
                log("Not leader - ignoring broker request", level=DEBUG)
 
324
            else:
 
325
                rsp = process_requests(settings['broker_req'])
 
326
                relation_set(relation_id=relid,
 
327
                             relation_settings={'broker_rsp': rsp})
 
328
    else:
 
329
        log('mon cluster not in quorum', level=DEBUG)
 
330
 
 
331
 
305
332
@hooks.hook('upgrade-charm')
306
333
def upgrade_charm():
307
334
    emit_cephconf()