diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index a6772da6..6b129cff 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -50,7 +50,9 @@ from quantum_utils import ( cache_env_data, get_dns_host, get_external_agent_f, - update_legacy_ha_files + update_legacy_ha_files, + remove_legacy_ha_files, + delete_legacy_resources ) hooks = Hooks() @@ -232,23 +234,23 @@ def ha_relation_joined(): cluster_config = get_hacluster_config(excludes_key=['vip']) resources = { - 'res_PingCheck': 'ocf:pacemaker:ping', 'res_ClusterMon': 'ocf:pacemaker:ClusterMon', + 'res_PingCheck': 'ocf:pacemaker:ping', } resource_params = { + 'res_ClusterMon': 'params user="root" update="30" ' + 'extra_options="-E {external_agent}" ' + 'op monitor on-fail="restart" interval="10s"' + .format(external_agent=external_agent), 'res_PingCheck': 'params host_list="{host}" dampen="5s" ' 'debug={debug} multiplier="1000" ' 'op monitor on-fail="restart" interval="10s" ' 'timeout="60s" '.format(host=dns_hosts, debug=debug), - 'res_ClusterMon': 'params user="root" update="30" ' - 'extra_options="-E {external_agent}" ' - 'op monitor on-fail="restart" interval="10s"' - .format(external_agent=external_agent), } clones = { + 'cl_ClusterMon': 'res_ClusterMon meta interleave="true"', 'cl_PingCheck': 'res_PingCheck meta interleave="true"', - 'cl_ClusterMon': 'res_ClusterMon meta interleave="true"' } relation_set(corosync_bindiface=cluster_config['ha-bindiface'], @@ -258,6 +260,13 @@ def ha_relation_joined(): clones=clones) +@hooks.hook('ha-relation-departed') +def ha_relation_destroyed(): + if config('ha-legacy-mode'): + delete_legacy_resources() + remove_legacy_ha_files() + + if __name__ == '__main__': try: hooks.execute(sys.argv) diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index ceb51493..d6fb617c 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -713,3 +713,14 @@ def cache_env_data(): with open(envrc_f, 'w') as f: for k, v in env.items(): f.write(''.join([k, '=', v, '\n'])) + + +def delete_legacy_resources(): + def crm_op(op, res): + cmd = 'crm -w -F %s %s' % (op, res) + subprocess.call(cmd.split()) + + crm_op('resource stop', 'res_PingCheck') + crm_op('resource stop', 'res_ClusterMon') + crm_op('configure delete', 'res_PingCheck') + crm_op('configure delete', 'res_ClusterMon')