Add leader-settings-changed hook
This commit is contained in:
parent
16d8d2a75c
commit
8c25deb4bd
@ -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
1
hooks/leader-deposed
Symbolic link
@ -0,0 +1 @@
|
||||
rabbitmq_server_relations.py
|
1
hooks/leader-elected
Symbolic link
1
hooks/leader-elected
Symbolic link
@ -0,0 +1 @@
|
||||
rabbitmq_server_relations.py
|
1
hooks/leader-settings-changed
Symbolic link
1
hooks/leader-settings-changed
Symbolic link
@ -0,0 +1 @@
|
||||
rabbitmq_server_relations.py
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user