58
cmd = ['crm', 'node', 'list']
59
out = subprocess.check_output(cmd)
61
for line in out.split('\n'):
63
nodes.append(line.split(':')[0])
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'])
74
# ensure ipmi stonith agents are not running on the nodes that
76
constraint = 'location const_loc_stonith_avoid_%s %s -inf: %s' %\
77
(node, rsc_name, node)
79
return rsc, constraint
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']
89
if not power_type or not power_params:
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)
97
utils.juju_log('ERROR',
98
'Unsupported STONITH power_type: %s' % power_type)
101
if not rsc or not constraint:
104
return rsc, constraint