~andreserl/charms/quantal/hacluster/ceph-ra-installation

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Andres Rodriguez
  • Date: 2013-01-28 15:11:19 UTC
  • mfrom: (7.1.14 hacluster)
  • Revision ID: andreserl@ubuntu.com-20130128151119-z0657kks4idfqa0r
STONITH support thanks to Adam

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import time
12
12
import os
13
13
 
 
14
import maas as MAAS
14
15
import utils
15
16
import pcmk
16
17
 
17
 
 
18
18
def install():
19
19
    utils.juju_log('INFO', 'Begin install hook.')
20
20
    utils.configure_source()
21
 
    utils.install('corosync', 'pacemaker', 'python-netaddr')
 
21
    utils.install('corosync', 'pacemaker', 'python-netaddr', 'ipmitool')
22
22
    utils.juju_log('INFO', 'End install hook.')
23
23
 
24
24
 
84
84
    # Reconfigure the cluster if required
85
85
    configure_cluster()
86
86
 
 
87
    # Setup fencing.
 
88
    configure_stonith()
 
89
 
87
90
    utils.juju_log('INFO', 'End config-changed hook.')
88
91
 
89
92
 
294
297
            cmd = 'crm resource cleanup %s' % res_name
295
298
            pcmk.commit(cmd)
296
299
 
 
300
    configure_stonith()
 
301
 
297
302
    for rel_id in utils.relation_ids('ha'):
298
303
        utils.relation_set(rid=rel_id,
299
304
                           clustered="yes")
301
306
    with open(HAMARKER, 'w') as marker:
302
307
        marker.write('done')
303
308
 
 
309
def configure_stonith():
 
310
    if utils.config_get('stonith_enabled') not in ['true', 'True']:
 
311
        return
 
312
 
 
313
    if not os.path.exists(HAMARKER):
 
314
        utils.juju_log('INFO',
 
315
                       'HA not yet configured, skipping STONITH config.')
 
316
        return
 
317
 
 
318
    utils.juju_log('INFO', 'Configuring STONITH for all nodes in cluster.')
 
319
    # configure stontih resources for all nodes in cluster.
 
320
    # note: this is totally provider dependent and requires
 
321
    # access to the MAAS API endpoint, using endpoint and credentials
 
322
    # set in config.
 
323
    url = utils.config_get('maas_url')
 
324
    creds = utils.config_get('maas_credentials')
 
325
    if None in [url, creds]:
 
326
        utils.juju_log('ERROR', 'maas_url and maas_credentials must be set'\
 
327
                       ' in config to enable STONITH.')
 
328
        sys.exit(1)
 
329
 
 
330
    maas = MAAS.MAASHelper(url, creds)
 
331
    nodes = maas.list_nodes()
 
332
    if not nodes:
 
333
        utils.juju_log('ERROR', 'Could not obtain node inventory from '\
 
334
                       'MAAS @ %s.' % url)
 
335
        sys.exit(1)
 
336
 
 
337
    cluster_nodes = pcmk.list_nodes()
 
338
    for node in cluster_nodes:
 
339
        rsc, constraint = pcmk.maas_stonith_primitive(nodes, node)
 
340
        if not rsc:
 
341
            utils.juju_log('ERROR',
 
342
                           'Failed to determine STONITH primitive for node'\
 
343
                           ' %s' % node)
 
344
            sys.exit(1)
 
345
 
 
346
        rsc_name = rsc.split(' ')[1]
 
347
        if not pcmk.is_resource_present(rsc_name):
 
348
            utils.juju_log('INFO', 'Creating new STONITH primitive %s.' %\
 
349
                           rsc_name)
 
350
            cmd = 'crm -F configure %s' % rsc
 
351
            pcmk.commit(cmd)
 
352
            if constraint:
 
353
                cmd = 'crm -F configure %s' % constraint
 
354
                pcmk.commit(cmd)
 
355
        else:
 
356
            utils.juju_log('INFO', 'STONITH primitive already exists '\
 
357
                           'for node.')
 
358
 
 
359
    cmd = "crm configure property stonith-enabled=true"
 
360
    pcmk.commit(cmd)
 
361
 
304
362
 
305
363
def ha_relation_departed():
306
364
    # TODO: Fin out which node is departing and put it in standby mode.