def cluster_setup(name, nodes, pcsclustername='pcscluster', extra_args=None):
 ret = {'name': name, 'result': True, 'comment': '', 'changes': {}}
 setup_required = False
 config_show = __salt__['pcs.config_show']()
 log.trace(('Output of pcs.config_show: ' + str(config_show)))
 for line in config_show['stdout'].splitlines():
  if (len(line.split(':')) in [2]):
   key = line.split(':')[0].strip()
   value = line.split(':')[1].strip()
   if (key in ['Cluster Name']):
    if (value in [pcsclustername]):
     ret['comment'] += 'Cluster {0} is already set up\n'.format(str(pcsclustername))
    else:
     setup_required = True
     if __opts__['test']:
      ret['comment'] += 'Cluster {0} is set to set up\n'.format(str(pcsclustername))
 if (not setup_required):
  return ret
 if __opts__['test']:
  ret['result'] = None
  return ret
 if (not isinstance(extra_args, (list, tuple))):
  extra_args = []
 setup = __salt__['pcs.cluster_setup'](nodes=nodes, pcsclustername=pcsclustername, extra_args=extra_args)
 log.trace(('Output of pcs.cluster_setup: ' + str(setup)))
 setup_dict = {}
 for line in setup['stdout'].splitlines():
  log.trace(('line: ' + line))
  log.trace(('line.split(:).len: ' + str(len(line.split(':')))))
  if (len(line.split(':')) in [2]):
   node = line.split(':')[0].strip()
   setup_state = line.split(':')[1].strip()
   if (node in nodes):
    setup_dict.update({node: setup_state})
 log.trace(('setup_dict: ' + str(setup_dict)))
 for node in nodes:
  if ((node in setup_dict) and (setup_dict[node] in ['Succeeded', 'Success'])):
   ret['comment'] += 'Set up {0}\n'.format(node)
   ret['changes'].update({node: {'old': '', 'new': 'Setup'}})
  else:
   ret['result'] = False
   ret['comment'] += 'Failed to setup {0}\n'.format(node)
   if (node in setup_dict):
    ret['comment'] += '{0}: setup_dict: {1}\n'.format(node, setup_dict[node])
   ret['comment'] += str(setup)
 log.trace(('ret: ' + str(ret)))
 return ret

def cluster_setup ( name , nodes , pcsclustername = 'pcscluster' , extra_args = None ) : ret = { 'name' : name , 'result' : True , 'comment' : '' , 'changes' : { } } setup_required = False config_show = __salt__ [ 'pcs.config_show' ] ( ) log . trace ( ( 'Output of pcs.config_show: ' + str ( config_show ) ) ) for line in config_show [ 'stdout' ] . splitlines ( ) : if ( len ( line . split ( ':' ) ) in [ 2 ] ) : key = line . split ( ':' ) [ 0 ] . strip ( ) value = line . split ( ':' ) [ 1 ] . strip ( ) if ( key in [ 'Cluster Name' ] ) : if ( value in [ pcsclustername ] ) : ret [ 'comment' ] += 'Cluster {0} is already set up\n' . format ( str ( pcsclustername ) ) else : setup_required = True if __opts__ [ 'test' ] : ret [ 'comment' ] += 'Cluster {0} is set to set up\n' . format ( str ( pcsclustername ) ) if ( not setup_required ) : return ret if __opts__ [ 'test' ] : ret [ 'result' ] = None return ret if ( not isinstance ( extra_args , ( list , tuple ) ) ) : extra_args = [ ] setup = __salt__ [ 'pcs.cluster_setup' ] ( nodes = nodes , pcsclustername = pcsclustername , extra_args = extra_args ) log . trace ( ( 'Output of pcs.cluster_setup: ' + str ( setup ) ) ) setup_dict = { } for line in setup [ 'stdout' ] . splitlines ( ) : log . trace ( ( 'line: ' + line ) ) log . trace ( ( 'line.split(:).len: ' + str ( len ( line . split ( ':' ) ) ) ) ) if ( len ( line . split ( ':' ) ) in [ 2 ] ) : node = line . split ( ':' ) [ 0 ] . strip ( ) setup_state = line . split ( ':' ) [ 1 ] . strip ( ) if ( node in nodes ) : setup_dict . update ( { node : setup_state } ) log . trace ( ( 'setup_dict: ' + str ( setup_dict ) ) ) for node in nodes : if ( ( node in setup_dict ) and ( setup_dict [ node ] in [ 'Succeeded' , 'Success' ] ) ) : ret [ 'comment' ] += 'Set up {0}\n' . format ( node ) ret [ 'changes' ] . update ( { node : { 'old' : '' , 'new' : 'Setup' } } ) else : ret [ 'result' ] = False ret [ 'comment' ] += 'Failed to setup {0}\n' . format ( node ) if ( node in setup_dict ) : ret [ 'comment' ] += '{0}: setup_dict: {1}\n' . format ( node , setup_dict [ node ] ) ret [ 'comment' ] += str ( setup ) log . trace ( ( 'ret: ' + str ( ret ) ) ) return ret
setup pacemaker cluster via pcs command nodes a list of nodes which should be set up pcsclustername name of the pacemaker cluster extra_args list of extra option for the pcs cluster setup command cli example: .