Class: PuppetX::Voxpupuli::Corosync::Provider::Pcs

Inherits:
CibHelper
  • Object
show all
Defined in:
lib/puppet_x/voxpupuli/corosync/provider/pcs.rb

Constant Summary collapse

@@pcsready =

Corosync takes a while to build the initial CIB configuration once the service is started for the first time. This provides us a way to wait until we’re up so we can make changes that don’t disappear in to a black hole. rubocop:disable Style/ClassVars

nil

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CibHelper

_get_epoch, _run_command_in_cib, node2hash, nvpairs_to_hash, rule_expression, wait_for_nonzero_epoch

Class Method Details

.block_until_ready(timeout = 120, shadow_cib = false) ⇒ Object



55
56
57
58
59
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 55

def self.block_until_ready(timeout = 120, shadow_cib = false)
  Timeout.timeout(timeout) do
    sleep 2 until ready?(shadow_cib)
  end
end

.get_epoch(cib = nil) ⇒ Object



61
62
63
64
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 61

def self.get_epoch(cib = nil)
  cmd = [command(:pcs), 'cluster', 'cib']
  _get_epoch(cmd, cib)
end

.prefetch(resources) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 66

def self.prefetch(resources)
  instances.each do |prov|
    # rubocop:disable Lint/AssignmentInCondition
    if res = resources[prov.name.to_s]
      # rubocop:enable Lint/AssignmentInCondition
      res.provider = prov
    end
  end
end

.ready?(shadow_cib) ⇒ Boolean

rubocop:enable Style/ClassVars

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 24

def self.ready?(shadow_cib)
  return true if @@pcsready
  cmd = [command(:pcs), 'property', 'show', 'dc-version']
  raw, status = run_command_in_cib(cmd, nil, false)
  if status.zero?
    # Wait until epoch is not 0.0.
    # On empty cluster it will stay 0.0 so there you wait the 60 seconds.
    # On new nodes you wait just enough time to allow the node to join the cluster.
    # That should not happen often, so it is acceptable to sleep up to 60 seconds here.
    cib_epoch = wait_for_nonzero_epoch(shadow_cib)

    warn("Pacemaker: CIB epoch is #{cib_epoch}. You can ignore this message if you are bootstrapping a new cluster.") if cib_epoch == '0.0'

    if cib_epoch == :absent
      debug('Corosync is not ready (no CIB available)')
      return false
    end

    # rubocop:disable Style/ClassVars
    @@pcsready = true
    # rubocop:enable Style/ClassVars

    debug("Corosync is ready, CIB epoch is #{cib_epoch}. Sleeping 5 seconds for safety.")
    sleep 5
    return true
  else
    debug("Corosync not ready, retrying: #{raw}")
    return false
  end
end

.run_command_in_cib(cmd, cib = nil, failonfail = true) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 76

def self.run_command_in_cib(cmd, cib = nil, failonfail = true)
  custom_environment = { combine: true }

  unless cib.nil?
    if cmd.first == command(:pcs)
      cib_path = File.join(Puppet[:vardir], 'shadow.' + cib)
      cmd.push('-f', cib_path)
    else
      custom_environment[:custom_environment] = { 'CIB_shadow_dir' => Puppet[:vardir], 'CIB_shadow' => cib }
    end
  end

  _run_command_in_cib(cmd, cib, failonfail, custom_environment)
end

.sync_shadow_cib(cib, failondeletefail = false) ⇒ Object



91
92
93
94
95
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 91

def self.sync_shadow_cib(cib, failondeletefail = false)
  cib_path = File.join(Puppet[:vardir], 'shadow.' + cib)
  run_command_in_cib([command(:pcs), 'cluster', 'cib', cib_path], nil, failondeletefail)
  FileUtils.cp cib_path, cib_path + '.ori'
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


97
98
99
100
101
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 97

def exists?
  self.class.block_until_ready
  debug(@property_hash.inspect)
  !(@property_hash[:ensure] == :absent || @property_hash.empty?)
end