39
39
for unit in utils.relation_list(relid):
41
41
'corosync_bindnetaddr':
42
hacluster.get_network_address(
43
utils.relation_get('corosync_bindiface',
42
hacluster.get_network_address(
43
utils.relation_get('corosync_bindiface',
46
46
'corosync_mcastport': utils.relation_get('corosync_mcastport',
48
48
'corosync_mcastaddr': utils.config_get('corosync_mcastaddr'),
50
50
if None not in conf.itervalues():
52
missing = [k for k, v in conf.iteritems() if v == None]
52
missing = [k for k, v in conf.iteritems() if v is None]
53
53
utils.juju_log('INFO',
54
54
'Missing required principle configuration: %s' % missing)
75
75
# write the authkey
76
76
with open('/etc/corosync/authkey', 'w') as corosync_key_file:
77
77
corosync_key_file.write(b64decode(corosync_key))
78
os.chmod = ('/etc/corosync/authkey', 0400)
78
os.chmod = ('/etc/corosync/authkey', 0o400)
81
81
def config_changed():
138
138
# Check that there's enough nodes in order to perform the
139
139
# configuration of the HA cluster
140
140
if (len(get_cluster_nodes()) <
141
int(utils.config_get('cluster_count'))):
141
int(utils.config_get('cluster_count'))):
142
142
utils.juju_log('WARNING', 'Not enough nodes in cluster, bailing')
154
154
{} if utils.relation_get("resources",
155
155
unit, relid) is None \
156
else ast.literal_eval(utils.relation_get("resources",
156
else ast.literal_eval(utils.relation_get("resources",
158
158
resource_params = \
159
159
{} if utils.relation_get("resource_params",
160
160
unit, relid) is None \
161
else ast.literal_eval(utils.relation_get("resource_params",
161
else ast.literal_eval(utils.relation_get("resource_params",
164
164
{} if utils.relation_get("groups",
165
165
unit, relid) is None \
166
else ast.literal_eval(utils.relation_get("groups",
166
else ast.literal_eval(utils.relation_get("groups",
169
169
{} if utils.relation_get("ms",
170
170
unit, relid) is None \
171
else ast.literal_eval(utils.relation_get("ms",
171
else ast.literal_eval(utils.relation_get("ms",
174
174
{} if utils.relation_get("orders",
175
175
unit, relid) is None \
176
else ast.literal_eval(utils.relation_get("orders",
176
else ast.literal_eval(utils.relation_get("orders",
179
179
{} if utils.relation_get("colocations",
180
180
unit, relid) is None \
181
else ast.literal_eval(utils.relation_get("colocations",
181
else ast.literal_eval(utils.relation_get("colocations",
184
184
{} if utils.relation_get("clones",
185
185
unit, relid) is None \
186
else ast.literal_eval(utils.relation_get("clones",
186
else ast.literal_eval(utils.relation_get("clones",
188
188
init_services = \
189
189
{} if utils.relation_get("init_services",
190
190
unit, relid) is None \
191
else ast.literal_eval(utils.relation_get("init_services",
191
else ast.literal_eval(utils.relation_get("init_services",
195
195
utils.juju_log('WARNING',
219
219
' resource-stickiness="100"'
222
# Configure Ping service
223
monitor_host = utils.config_get('monitor_host')
225
if not pcmk.crm_opt_exists('ping'):
226
monitor_interval = utils.config_get('monitor_interval')
227
cmd = 'crm -w -F configure primitive ping' \
228
' ocf:pacemaker:ping params host_list="%s"' \
229
' multiplier="100" op monitor interval="%s"' %\
230
(monitor_host, monitor_interval)
231
cmd2 = 'crm -w -F configure clone cl_ping ping' \
232
' meta interleave="true"'
222
236
# Only configure the cluster resources
223
237
# from the oldest peer unit.
224
238
if cluster.oldest_peer(cluster.peer_units()):
237
251
if utils.running(init_services[res_name]):
238
252
utils.stop(init_services[res_name])
239
253
# Put the services in HA, if not already done so
240
#if not pcmk.is_resource_present(res_name):
254
# if not pcmk.is_resource_present(res_name):
241
255
if not pcmk.crm_opt_exists(res_name):
242
256
if not res_name in resource_params:
243
257
cmd = 'crm -w -F configure primitive %s %s' % (res_name,
246
260
cmd = 'crm -w -F configure primitive %s %s %s' % \
249
resource_params[res_name])
263
resource_params[res_name])
251
265
utils.juju_log('INFO', '%s' % cmd)
267
cmd = 'crm -F configure location Ping-%s %s rule' \
268
' -inf: pingd lte 0' % (res_name, res_name)
253
271
utils.juju_log('INFO', 'Configuring Groups')
254
272
utils.juju_log('INFO', str(groups))
303
321
# than as individual resources.
304
322
if (res_name not in clones.values() and
305
323
res_name not in groups.values() and
306
not pcmk.crm_res_running(res_name)):
324
not pcmk.crm_res_running(res_name)):
307
325
# Just in case, cleanup the resources to ensure they get
308
326
# started in case they failed for some unrelated reason.
309
327
cmd = 'crm resource cleanup %s' % res_name
346
364
url = utils.config_get('maas_url')
347
365
creds = utils.config_get('maas_credentials')
348
366
if None in [url, creds]:
349
utils.juju_log('ERROR', 'maas_url and maas_credentials must be set'\
367
utils.juju_log('ERROR', 'maas_url and maas_credentials must be set'
350
368
' in config to enable STONITH.')
353
371
maas = MAAS.MAASHelper(url, creds)
354
372
nodes = maas.list_nodes()
356
utils.juju_log('ERROR', 'Could not obtain node inventory from '\
374
utils.juju_log('ERROR', 'Could not obtain node inventory from '
357
375
'MAAS @ %s.' % url)
362
380
rsc, constraint = pcmk.maas_stonith_primitive(nodes, node)
364
382
utils.juju_log('ERROR',
365
'Failed to determine STONITH primitive for node'\
383
'Failed to determine STONITH primitive for node'
369
387
rsc_name = str(rsc).split(' ')[1]
370
388
if not pcmk.is_resource_present(rsc_name):
371
utils.juju_log('INFO', 'Creating new STONITH primitive %s.' %\
389
utils.juju_log('INFO', 'Creating new STONITH primitive %s.' %
373
391
cmd = 'crm -F configure %s' % rsc
376
394
cmd = 'crm -F configure %s' % constraint
379
utils.juju_log('INFO', 'STONITH primitive already exists '\
397
utils.juju_log('INFO', 'STONITH primitive already exists '
382
400
cmd = "crm configure property stonith-enabled=true"
405
423
'ha-relation-changed': configure_cluster,
406
424
'hanode-relation-joined': configure_cluster,
407
425
'hanode-relation-changed': configure_cluster,
410
428
utils.do_hooks(hooks)