Add leader-settings-changed hook

This commit is contained in:
James Page 2015-03-13 11:08:28 +00:00
parent 16d8d2a75c
commit 8c25deb4bd
5 changed files with 27 additions and 0 deletions

View File

@ -352,6 +352,17 @@ def relation_set(relation_id=None, relation_settings=None, **kwargs):
flush(local_unit())
def relation_clear(r_id=None):
''' Clears any relation data already set on relation r_id '''
settings = relation_get(rid=r_id,
unit=local_unit())
for setting in settings:
if setting not in ['public-address', 'private-address']:
settings[setting] = None
relation_set(relation_id=r_id,
**settings)
@cached
def relation_ids(reltype=None):
"""A list of relation_ids"""

1
hooks/leader-deposed Symbolic link
View File

@ -0,0 +1 @@
rabbitmq_server_relations.py

1
hooks/leader-elected Symbolic link
View File

@ -0,0 +1 @@
rabbitmq_server_relations.py

View File

@ -0,0 +1 @@
rabbitmq_server_relations.py

View File

@ -41,6 +41,7 @@ from charmhelpers.core.hookenv import (
ERROR,
INFO,
relation_get,
relation_clear,
relation_set,
relation_ids,
related_units,
@ -146,6 +147,9 @@ def amqp_changed(relation_id=None, remote_unit=None):
host_addr = unit_get('private-address')
if not is_elected_leader('res_rabbitmq_vip'):
# NOTE(jamespage) clear relation to deal with data being
# removed from peer storage
relation_clear(relation_id)
# Each unit needs to set the db information otherwise if the unit
# with the info dies the settings die with it Bug# 1355848
exc_list = ['hostname', 'private-address']
@ -696,6 +700,15 @@ def config_changed():
amqp_changed(relation_id=rid, remote_unit=unit)
@hooks.hook('leader-settings-changed')
def leader_settings_changed():
# If cluster has changed peer db may have changed so run amqp_changed
# to sync any changes
for rid in relation_ids('amqp'):
for unit in related_units(rid):
amqp_changed(relation_id=rid, remote_unit=unit)
def pre_install_hooks():
for f in glob.glob('exec.d/*/charm-pre-install'):
if os.path.isfile(f) and os.access(f, os.X_OK):