~gandelman-a/charms/precise/hacluster/ocf

« back to all changes in this revision

Viewing changes to hooks/pcmk.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:
52
52
    if opt:
53
53
        return True
54
54
    return False
 
55
 
 
56
 
 
57
def list_nodes():
 
58
    cmd = ['crm', 'node', 'list']
 
59
    out = subprocess.check_output(cmd)
 
60
    nodes = []
 
61
    for line in out.split('\n'):
 
62
        if line != '':
 
63
            nodes.append(line.split(':')[0])
 
64
    return nodes
 
65
 
 
66
 
 
67
def _maas_ipmi_stonith_resource(node, power_params):
 
68
    rsc_name = 'res_stonith_%s' % node
 
69
    rsc = 'primitive %s stonith:external/ipmi' % rsc_name
 
70
    rsc += ' params hostname=%s ipaddr=%s userid=%s passwd=%s interface=lan' %\
 
71
           (node, power_params['power_address'],
 
72
            power_params['power_user'], power_params['power_pass'])
 
73
 
 
74
    # ensure ipmi stonith agents are not running on the nodes that
 
75
    # they manage.
 
76
    constraint = 'location const_loc_stonith_avoid_%s %s -inf: %s' %\
 
77
                  (node, rsc_name, node)
 
78
 
 
79
    return rsc, constraint
 
80
 
 
81
 
 
82
def maas_stonith_primitive(maas_nodes, crm_node):
 
83
    power_type = power_params = None
 
84
    for node in maas_nodes:
 
85
        if node['hostname'].startswith(crm_node):
 
86
            power_type = node['power_type']
 
87
            power_params = node['power_parameters']
 
88
 
 
89
    if not power_type or not power_params:
 
90
        return False, False
 
91
 
 
92
    rsc = constraint = None
 
93
    # we can extend to support other power flavors in the future?
 
94
    if power_type == 'ipmi':
 
95
        rsc, constraint = _maas_ipmi_stonith_resource(crm_node, power_params)
 
96
    else:
 
97
        utils.juju_log('ERROR',
 
98
                       'Unsupported STONITH power_type: %s' % power_type)
 
99
        return False, False
 
100
 
 
101
    if not rsc or not constraint:
 
102
        return False, False
 
103
 
 
104
    return rsc, constraint