~adam-collard/charms/trusty/rabbitmq-server/fix-le-ignore-min-cluster

« back to all changes in this revision

Viewing changes to hooks/rabbitmq_server_relations.py

  • Committer: billy.olsen at canonical
  • Date: 2015-09-01 04:53:33 UTC
  • Revision ID: billy.olsen@canonical.com-20150901045333-sstcvt6exd5b005d
[billy-olsen,r=trivial] Undo last 2 commits which has rabbit in a
bad state.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    UnregisteredHookError,
64
64
    is_leader,
65
65
    charm_dir,
66
 
    in_relation_hook,
67
66
)
68
67
from charmhelpers.core.host import (
69
68
    cmp_pkgrevno,
273
272
 
274
273
@hooks.hook('cluster-relation-joined')
275
274
def cluster_joined(relation_id=None):
276
 
    relation_settings = {
277
 
        'hostname': get_local_nodename(),
278
 
    }
279
 
 
280
275
    if config('prefer-ipv6'):
281
 
        relation_settings['private-address'] = get_ipv6_addr()[0]
282
 
    else:
283
 
        relation_settings['private-address'] = get_host_ip(
284
 
            unit_get('private-address'))
285
 
 
286
 
    relation_set(relation_id=relation_id,
287
 
                 relation_settings=relation_settings)
 
276
        relation_settings = {'hostname': socket.gethostname(),
 
277
                             'private-address': get_ipv6_addr()[0]}
 
278
        relation_set(relation_id=relation_id,
 
279
                     relation_settings=relation_settings)
288
280
 
289
281
    if is_relation_made('ha') and \
290
282
            config('ha-vip-only') is False:
318
310
 
319
311
@hooks.hook('cluster-relation-changed')
320
312
def cluster_changed():
321
 
    if relation_ids('cluster'):
322
 
        cookie = peer_retrieve('cookie')
323
 
    else:
324
 
        cookie = None
 
313
    cookie = peer_retrieve('cookie')
325
314
    if not cookie:
326
315
        log('cluster_joined: cookie not yet set.', level=INFO)
327
316
        return
328
317
 
329
318
    rdata = relation_get()
330
 
    hostname = rdata.get('hostname', None)
331
 
    private_address = rdata.get('private-address', None)
332
 
 
333
 
    # If called from leader-settings-changed we are not in a hook env
334
 
    if not in_relation_hook():
335
 
        rid = relation_ids('cluster')[0]
336
 
        for unit in related_units(rid):
337
 
            rdata = relation_get(rid=rid, unit=unit)
338
 
            if rdata:
339
 
                break;
340
 
    else:
341
 
        rdata = relation_get()
342
 
 
343
 
 
344
 
    if hostname and private_address:
345
 
        rabbit.update_hosts_file({private_address: hostname})
 
319
    if config('prefer-ipv6') and rdata.get('hostname'):
 
320
        private_address = rdata['private-address']
 
321
        hostname = rdata['hostname']
 
322
        if hostname:
 
323
            rabbit.update_hosts_file({private_address: hostname})
346
324
 
347
325
    # sync passwords
348
326
    blacklist = ['hostname', 'private-address', 'public-address']
351
329
 
352
330
    if not is_sufficient_peers():
353
331
        # Stop rabbit until leader has finished configuring
354
 
        log('Not enough peers, stopping until leader is configured',
355
 
            level=INFO)
356
332
        service_stop('rabbitmq-server')
357
333
        return
358
334
 
789
765
def leader_settings_changed():
790
766
    # If leader has changed and access credentials, ripple these
791
767
    # out from all units
792
 
    cluster_changed()
793
768
    for rid in relation_ids('amqp'):
794
769
        for unit in related_units(rid):
795
770
            amqp_changed(relation_id=rid, remote_unit=unit)