def cluster_changed(): unison.ssh_authorized_peers(user=rabbit.SSH_USER, group='rabbit', peer_interface='cluster', ensure_local_user=True) rabbit.synchronize_service_credentials() if utils.is_relation_made('ha'): utils.juju_log('INFO', 'hacluster relation is present, skipping native ' 'rabbitmq cluster config.') return l_unit_no = os.getenv('JUJU_UNIT_NAME').split('/')[1] r_unit_no = os.getenv('JUJU_REMOTE_UNIT').split('/')[1] if l_unit_no < r_unit_no: utils.juju_log('INFO', 'cluster_joined: Relation lesser.') return cookie = utils.relation_get('cookie') if cookie is None: utils.juju_log('INFO', 'cluster_joined: cookie not yet set.') return if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie: utils.juju_log('INFO', 'Cookie already synchronized with peer.') else: utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.') rabbit.service('stop') with open(rabbit.COOKIE_PATH, 'wb') as out: out.write(cookie) rabbit.service('start') # cluster with other nodes rabbit.cluster_with()
def cluster_changed(): unison.ssh_authorized_peers(user=rabbit.SSH_USER, group='rabbit', peer_interface='cluster', ensure_local_user=True) rabbit.synchronize_service_credentials() if utils.is_relation_made('ha'): utils.juju_log( 'INFO', 'hacluster relation is present, skipping native ' 'rabbitmq cluster config.') return l_unit_no = os.getenv('JUJU_UNIT_NAME').split('/')[1] r_unit_no = os.getenv('JUJU_REMOTE_UNIT').split('/')[1] if l_unit_no < r_unit_no: utils.juju_log('INFO', 'cluster_joined: Relation lesser.') return cookie = utils.relation_get('cookie') if cookie is None: utils.juju_log('INFO', 'cluster_joined: cookie not yet set.') return if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie: utils.juju_log('INFO', 'Cookie already synchronized with peer.') else: utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.') rabbit.service('stop') with open(rabbit.COOKIE_PATH, 'wb') as out: out.write(cookie) rabbit.service('start') # cluster with other nodes rabbit.cluster_with()
def cluster_changed(): if utils.is_relation_made('ha'): utils.juju_log('INFO', 'hacluster relation is present, skipping native '\ 'rabbitmq cluster config.') return l_unit_no = os.getenv('JUJU_UNIT_NAME').split('/')[1] r_unit_no = os.getenv('JUJU_REMOTE_UNIT').split('/')[1] if l_unit_no < r_unit_no: utils.juju_log('INFO', 'cluster_joined: Relation lesser.') return remote_host = utils.relation_get('host') cookie = utils.relation_get('cookie') if None in [remote_host, cookie]: utils.juju_log('INFO', 'cluster_joined: remote_host|cookie not yet set.') return if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie: utils.juju_log('INFO', 'Cookie already synchronized with peer.') return utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.') rabbit.service('stop') with open(rabbit.COOKIE_PATH, 'wb') as out: out.write(cookie) rabbit.service('start') rabbit.cluster_with(remote_host)