def ha_relation_joined(relation_id=None):
    sstpsswd = sst_password()
    _relation_data = {
        'resources': {
            'res_mysql_monitor': 'ocf:percona:mysql_monitor'},
        'resource_params': {
            'res_mysql_monitor': RES_MONITOR_PARAMS % {'sstpass': sstpsswd}},
        'clones': {
            'cl_mysql_monitor': 'res_mysql_monitor meta interleave=true'},
        'delete_resources': ['loc_percona_cluster', 'grp_percona_cluster',
                             'res_mysql_vip']
    }

    if config('dns-ha'):
        update_hacluster_dns_ha('mysql', _relation_data)
        group_name = DNSHA_GROUP_NAME.format(service='mysql')
    else:
        update_hacluster_vip('mysql', _relation_data)
        group_name = VIP_GROUP_NAME.format(service='mysql')

    _relation_data['locations'] = {
        'loc_mysql': '{} rule inf: writable eq 1'.format(group_name)}
    _relation_data['colocations'] = {
        'colo_mysql': 'inf: {} cl_mysql_monitor'.format(group_name)}
    settings = {
        'json_{}'.format(k): json.dumps(v, **JSON_ENCODE_OPTIONS)
        for k, v in _relation_data.items() if v
    }

    for rel_id in relation_ids('ha'):
        relation_set(relation_id=rel_id, **settings)
def ha_relation_joined(relation_id=None):
    sstpsswd = sst_password()
    _relation_data = {
        'resources': {
            'res_mysql_monitor': 'ocf:percona:mysql_monitor'},
        'resource_params': {
            'res_mysql_monitor': RES_MONITOR_PARAMS % {'sstpass': sstpsswd}},
        'clones': {
            'cl_mysql_monitor': 'res_mysql_monitor meta interleave=true'},
        'delete_resources': ['loc_percona_cluster', 'grp_percona_cluster',
                             'res_mysql_vip']
    }

    if config('dns-ha'):
        update_hacluster_dns_ha('mysql', _relation_data)
        group_name = DNSHA_GROUP_NAME.format(service='mysql')
    else:
        update_hacluster_vip('mysql', _relation_data)
        group_name = VIP_GROUP_NAME.format(service='mysql')

    _relation_data['locations'] = {
        'loc_mysql': '{} rule inf: writable eq 1'.format(group_name)}
    _relation_data['colocations'] = {
        'colo_mysql': 'inf: {} cl_mysql_monitor'.format(group_name)}
    settings = {
        'json_{}'.format(k): json.dumps(v, **JSON_ENCODE_OPTIONS)
        for k, v in _relation_data.items() if v
    }

    for rel_id in relation_ids('ha'):
        relation_set(relation_id=rel_id, **settings)