Module: Pacemaker::PcsPcsdAuth

Included in:
Puppet::Provider::PacemakerPCS
Defined in:
lib/pacemaker/pcs/pcsd_auth.rb

Overview

this submodule contains “pcs” based function for cluster property provider

Instance Method Summary collapse

Instance Method Details

#pcs_auth_command(nodes, username, password, force = false, local = false) ⇒ String?

run the ‘pcs cluster auth’ command and capture the debug output, returned by the pcsd.cli ruby tool returns nil if could not get the data

Parameters:

  • nodes (Array<String>)

    the list of cluster nodes top auth

  • username (String)
  • password (String)
  • force (String) (defaults to: false)

    auth even if already have been auth’ed

  • local (String) (defaults to: false)

    auth only the local node

Returns:

  • (String, nil)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pacemaker/pcs/pcsd_auth.rb', line 13

def pcs_auth_command(nodes, username, password, force=false, local=false)
  command = %w(cluster auth --debug)
  command << '--force' if force
  command << '--local' if local
  command += [ '-u', username ]
  command += [ '-p', password ]
  command += [nodes]
  command.flatten!

  begin
    output = pcs *command
  rescue Puppet::ExecutionFailure => e
    output = e.to_s
  end

  return unless output
  inside_debug_block = false
  result = []
  output.split("\n").each do |line|
    inside_debug_block = false if line =~ /--Debug (Output|Stdout) End--/
    result << line if inside_debug_block
    inside_debug_block = true if line =~ /--Debug (Output|Stdout) Start--/
  end
  return unless result.any?
  result.join("\n")
end

#pcs_auth_parse(result) ⇒ Hash<String => String>?

parse the debug output of the pcs auth command to a hash of nodes and their statuses returns nil on error

Parameters:

  • result (String)

Returns:

  • (Hash<String => String>, nil)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pacemaker/pcs/pcsd_auth.rb', line 45

def pcs_auth_parse(result)
  result_structure = begin
    JSON.load result
  rescue StandardError
    nil
  end
  return unless result_structure.is_a? Hash
  responses = result_structure.fetch('data', {}).fetch('auth_responses', {})
  status_hash = {}
  responses.each do |node, response|
    next unless response.is_a? Hash
    node_status = response['status']
    next unless node_status
    status_hash.store node, node_status
  end
  status_hash
end