88
111
if singleset.issubset(queues[amqp]):
89
112
relation_settings[
90
113
'_'.join([amqp, 'password'])] = configure_amqp(
91
queues[amqp]['username'],
92
queues[amqp]['vhost'])
114
queues[amqp]['username'],
115
queues[amqp]['vhost'])
94
relation_settings['hostname'] = utils.unit_get('private-address')
117
relation_settings['hostname'] = unit_get('private-address')
95
118
configure_client_ssl(relation_settings)
97
if cluster.is_clustered():
98
121
relation_settings['clustered'] = 'true'
99
if utils.is_relation_made('ha'):
122
if is_relation_made('ha'):
100
123
# active/passive settings
101
relation_settings['vip'] = utils.config_get('vip')
102
relation_settings['ha-vip-only'] = utils.config_get('ha-vip-only')
124
relation_settings['vip'] = config('vip')
125
relation_settings['ha-vip-only'] = config('ha-vip-only')
105
128
relation_settings['rid'] = relation_id
107
130
# set if need HA queues or not
108
131
relation_settings['ha_queues'] = (rabbit.compare_version('3.0.1') >= 0)
109
utils.relation_set(**relation_settings)
132
relation_set(relation_settings=relation_settings)
135
@hooks.hook('cluster-relation-joined')
112
136
def cluster_joined():
113
if utils.is_relation_made('ha') and \
114
utils.config_get('ha-vip-only') is False:
115
utils.juju_log('INFO',
116
'hacluster relation is present, skipping native '
117
'rabbitmq cluster config.')
137
if is_relation_made('ha') and \
138
config('ha-vip-only') is False:
139
log('hacluster relation is present, skipping native '
140
'rabbitmq cluster config.')
121
utils.juju_log('INFO', 'cluster_joined: Relation greater.')
144
log('cluster_joined: Relation greater.')
124
147
rabbit.COOKIE_PATH = '/var/lib/rabbitmq/.erlang.cookie'
125
148
if not os.path.isfile(rabbit.COOKIE_PATH):
126
utils.juju_log('ERROR', 'erlang cookie missing from %s' %
149
log('erlang cookie missing from %s' % rabbit.COOKIE_PATH,
129
152
cookie = open(rabbit.COOKIE_PATH, 'r').read().strip()
130
153
rabbit.set_clustered_attribute('cookie', cookie)
156
@hooks.hook('cluster-relation-changed')
133
157
def cluster_changed():
135
rdata = hookenv.relation_get()
159
rdata = relation_get()
137
161
for attribute, value in rdata.iteritems():
138
162
if '.passwd' in attribute or attribute == 'cookie':
139
163
echo_data[attribute] = value
140
164
if len(echo_data) > 0:
141
hookenv.relation_set(relation_settings=echo_data)
165
relation_set(relation_settings=echo_data)
143
167
if 'cookie' not in echo_data:
144
utils.juju_log('INFO',
145
'cluster_joined: cookie not yet set.')
168
log('cluster_joined: cookie not yet set.')
149
172
cookie = echo_data['cookie']
150
173
if open(rabbit.COOKIE_PATH, 'r').read().strip() == cookie:
151
utils.juju_log('INFO', 'Cookie already synchronized with peer.')
174
log('Cookie already synchronized with peer.')
153
utils.juju_log('INFO', 'Synchronizing erlang cookie from peer.')
176
log('Synchronizing erlang cookie from peer.')
154
177
rabbit.service('stop')
155
178
with open(rabbit.COOKIE_PATH, 'wb') as out:
156
179
out.write(cookie)
157
180
rabbit.service('start')
159
if utils.is_relation_made('ha') and \
160
utils.config_get('ha-vip-only') is False:
161
utils.juju_log('INFO',
162
'hacluster relation is present, skipping native '
163
'rabbitmq cluster config.')
182
if is_relation_made('ha') and \
183
config('ha-vip-only') is False:
184
log('hacluster relation is present, skipping native '
185
'rabbitmq cluster config.')
166
188
# cluster with node
168
190
if rabbit.cluster_with():
169
191
# resync nrpe user after clustering
170
192
update_nrpe_checks()
195
@hooks.hook('cluster-relation-departed')
173
196
def cluster_departed():
174
if utils.is_relation_made('ha') and \
175
utils.config_get('ha-vip-only') is False:
176
utils.juju_log('INFO',
177
'hacluster relation is present, skipping native '
178
'rabbitmq cluster config.')
197
if is_relation_made('ha') and \
198
config('ha-vip-only') is False:
199
log('hacluster relation is present, skipping native '
200
'rabbitmq cluster config.')
180
if not utils.is_newer():
181
utils.juju_log('INFO', 'cluster_joined: Relation lesser.')
203
log('cluster_joined: Relation lesser.')
183
205
rabbit.break_cluster()
208
@hooks.hook('ha-relation-joined')
187
corosync_bindiface = utils.config_get('ha-bindiface')
188
corosync_mcastport = utils.config_get('ha-mcastport')
189
vip = utils.config_get('vip')
190
vip_iface = utils.config_get('vip_iface')
191
vip_cidr = utils.config_get('vip_cidr')
192
rbd_name = utils.config_get('rbd-name')
193
vip_only = utils.config_get('ha-vip-only')
210
corosync_bindiface = config('ha-bindiface')
211
corosync_mcastport = config('ha-mcastport')
213
vip_iface = config('vip_iface')
214
vip_cidr = config('vip_cidr')
215
rbd_name = config('rbd-name')
216
vip_only = config('ha-vip-only')
195
218
if None in [corosync_bindiface, corosync_mcastport, vip, vip_iface,
196
219
vip_cidr, rbd_name] and vip_only is False:
197
utils.juju_log('ERROR', 'Insufficient configuration data to '
198
'configure hacluster.')
220
log('Insufficient configuration data to configure hacluster.',
200
223
elif None in [corosync_bindiface, corosync_mcastport, vip, vip_iface,
201
224
vip_cidr] and vip_only is True:
202
utils.juju_log('ERROR', 'Insufficient configuration data to '
203
'configure VIP-only hacluster.')
225
log('Insufficient configuration data to configure VIP-only hacluster.',
206
if not utils.is_relation_made('ceph', 'auth') and vip_only is False:
207
utils.juju_log('INFO',
208
'ha_joined: No ceph relation yet, deferring.')
229
if not is_relation_made('ceph', 'auth') and vip_only is False:
230
log('ha_joined: No ceph relation yet, deferring.')
211
233
name = '%s@localhost' % SERVICE_NAME
212
234
if rabbit.get_node_name() != name and vip_only is False:
213
utils.juju_log('INFO', 'Stopping rabbitmq-server.')
214
utils.stop('rabbitmq-server')
235
log('Stopping rabbitmq-server.')
236
service_stop('rabbitmq-server')
215
237
rabbit.set_node_name('%s@localhost' % SERVICE_NAME)
217
utils.juju_log('INFO', 'Node name already set to %s.' % name)
239
log('Node name already set to %s.' % name)
219
241
relation_settings = {}
220
242
relation_settings['corosync_bindiface'] = corosync_bindiface
253
276
relation_settings['groups'] = {
254
'grp_rabbitmq': 'res_rabbitmq_rbd res_rabbitmq_fs res_rabbitmq_vip '
255
'res_rabbitmq-server',
278
'res_rabbitmq_rbd res_rabbitmq_fs res_rabbitmq_vip '
279
'res_rabbitmq-server',
258
for rel_id in utils.relation_ids('ha'):
259
utils.relation_set(rid=rel_id, **relation_settings)
282
for rel_id in relation_ids('ha'):
283
relation_set(relation_id=rel_id, relation_settings=relation_settings)
262
286
'OPENSTACK_PORT_EPMD': 4369,
263
'OPENSTACK_PORT_MCASTPORT': utils.config_get('ha-mcastport'),
287
'OPENSTACK_PORT_MCASTPORT': config('ha-mcastport'),
265
openstack.save_script_rc(**env_vars)
289
save_script_rc(**env_vars)
292
@hooks.hook('ha-relation-changed')
268
293
def ha_changed():
269
if not cluster.is_clustered():
294
if not is_clustered():
271
vip = utils.config_get('vip')
272
utils.juju_log('INFO', 'ha_changed(): We are now HA clustered. '
297
log('ha_changed(): We are now HA clustered. '
273
298
'Advertising our VIP (%s) to all AMQP clients.' %
275
300
# need to re-authenticate all clients since node-name changed.
276
for rid in utils.relation_ids('amqp'):
277
for unit in utils.relation_list(rid):
301
for rid in relation_ids('amqp'):
302
for unit in related_units(rid):
278
303
amqp_changed(relation_id=rid, remote_unit=unit)
306
@hooks.hook('ceph-relation-joined')
281
307
def ceph_joined():
282
utils.juju_log('INFO', 'Start Ceph Relation Joined')
283
utils.configure_source()
308
log('Start Ceph Relation Joined')
310
#utils.configure_source()
285
utils.juju_log('INFO', 'Finish Ceph Relation Joined')
312
log('Finish Ceph Relation Joined')
315
@hooks.hook('ceph-relation-changed')
288
316
def ceph_changed():
289
utils.juju_log('INFO', 'Start Ceph Relation Changed')
290
auth = utils.relation_get('auth')
291
key = utils.relation_get('key')
292
use_syslog = str(utils.config_get('use-syslog')).lower()
317
log('Start Ceph Relation Changed')
318
auth = relation_get('auth')
319
key = relation_get('key')
320
use_syslog = str(config('use-syslog')).lower()
293
321
if None in [auth, key]:
294
utils.juju_log('INFO', 'Missing key or auth in relation')
322
log('Missing key or auth in relation')
297
325
ceph.configure(service=SERVICE_NAME, key=key, auth=auth,
298
326
use_syslog=use_syslog)
300
if cluster.eligible_leader('res_rabbitmq_vip'):
301
rbd_img = utils.config_get('rbd-name')
302
rbd_size = utils.config_get('rbd-size')
328
if eligible_leader('res_rabbitmq_vip'):
329
rbd_img = config('rbd-name')
330
rbd_size = config('rbd-size')
303
331
sizemb = int(rbd_size.split('G')[0]) * 1024
304
332
blk_device = '/dev/rbd/%s/%s' % (POOL_NAME, rbd_img)
305
rbd_pool_rep_count = utils.config_get('ceph-osd-replication-count')
333
rbd_pool_rep_count = config('ceph-osd-replication-count')
306
334
ceph.ensure_ceph_storage(service=SERVICE_NAME, pool=POOL_NAME,
307
335
rbd_img=rbd_img, sizemb=sizemb,
308
336
fstype='ext4', mount_point=RABBIT_DIR,
310
338
system_services=['rabbitmq-server'],
311
339
rbd_pool_replicas=rbd_pool_rep_count)
313
utils.juju_log('INFO',
314
'This is not the peer leader. Not configuring RBD.')
315
utils.juju_log('INFO', 'Stopping rabbitmq-server.')
316
utils.stop('rabbitmq-server')
341
log('This is not the peer leader. Not configuring RBD.')
342
log('Stopping rabbitmq-server.')
343
service_stop('rabbitmq-server')
318
345
# If 'ha' relation has been made before the 'ceph' relation
319
346
# it is important to make sure the ha-relation data is being
321
if utils.is_relation_made('ha'):
322
utils.juju_log('INFO', '*ha* relation exists. Triggering ha_joined()')
348
if is_relation_made('ha'):
349
log('*ha* relation exists. Triggering ha_joined()')
325
utils.juju_log('INFO', '*ha* relation does not exist.')
326
utils.juju_log('INFO', 'Finish Ceph Relation Changed')
352
log('*ha* relation does not exist.')
353
log('Finish Ceph Relation Changed')
356
@hooks.hook('nrpe-external-master-relation-changed')
329
357
def update_nrpe_checks():
330
358
if os.path.isdir(NAGIOS_PLUGINS):
331
359
rsync(os.path.join(os.getenv('CHARM_DIR'), 'scripts',