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 amqp_changed(relation_id=None, remote_unit=None): if not cluster.eligible_leader('res_rabbitmq_vip'): msg = 'amqp_changed(): Deferring amqp_changed to eligible_leader.' utils.juju_log('INFO', msg) return relation_settings = {} settings = hookenv.relation_get(rid=relation_id, unit=remote_unit) singleset = set([ 'username', 'vhost' ]) if singleset.issubset(settings): if None in [settings['username'], settings['vhost']]: utils.juju_log('INFO', 'amqp_changed(): Relation not ready.') return relation_settings['password'] = configure_amqp(username=settings['username'], vhost=settings['vhost']) else: queues = {} for k, v in settings.iteritems(): amqp = k.split('_')[0] x = '_'.join(k.split('_')[1:]) if amqp not in queues: queues[amqp] = {} queues[amqp][x] = v relation_settings = {} for amqp in queues: if singleset.issubset(queues[amqp]): relation_settings['_'.join([amqp, 'password'])] = configure_amqp(queues[amqp]['username'], queues[amqp]['vhost']) relation_settings['hostname'] = utils.unit_get('private-address') if cluster.is_clustered(): relation_settings['clustered'] = 'true' if utils.is_relation_made('ha'): # active/passive settings relation_settings['vip'] = utils.config_get('vip') if relation_id: relation_settings['rid'] = relation_id utils.relation_set(**relation_settings) # sync new creds to all peers rabbit.synchronize_service_credentials()
def amqp_changed(relation_id=None, remote_unit=None): if not cluster.eligible_leader('res_rabbitmq_vip'): msg = 'amqp_changed(): Deferring amqp_changed to eligible_leader.' utils.juju_log('INFO', msg) return relation_settings = {} settings = hookenv.relation_get(rid=relation_id, unit=remote_unit) singleset = set(['username', 'vhost']) if singleset.issubset(settings): if None in [settings['username'], settings['vhost']]: utils.juju_log('INFO', 'amqp_changed(): Relation not ready.') return relation_settings['password'] = configure_amqp( username=settings['username'], vhost=settings['vhost']) else: queues = {} for k, v in settings.iteritems(): amqp = k.split('_')[0] x = '_'.join(k.split('_')[1:]) if amqp not in queues: queues[amqp] = {} queues[amqp][x] = v relation_settings = {} for amqp in queues: if singleset.issubset(queues[amqp]): relation_settings['_'.join([amqp, 'password'])] = configure_amqp( queues[amqp]['username'], queues[amqp]['vhost']) relation_settings['hostname'] = utils.unit_get('private-address') if cluster.is_clustered(): relation_settings['clustered'] = 'true' if utils.is_relation_made('ha'): # active/passive settings relation_settings['vip'] = utils.config_get('vip') if relation_id: relation_settings['rid'] = relation_id utils.relation_set(**relation_settings) # sync new creds to all peers rabbit.synchronize_service_credentials()