Class: PuppetX::Voxpupuli::Corosync::Provider::Crmsh
- Inherits:
-
CibHelper
- Object
- Puppet::Provider
- CibHelper
- PuppetX::Voxpupuli::Corosync::Provider::Crmsh
show all
- Defined in:
- lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb
Constant Summary
collapse
- @@crmready =
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/crmsh.rb', line 55
def self.block_until_ready(timeout = 120, shadow_cib = false)
Timeout.timeout(timeout, shadow_cib) 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/crmsh.rb', line 61
def self.get_epoch(cib = nil)
cmd = [command(:cibadmin), '--query', '--xpath', '/cib', '-l', '-n']
_get_epoch(cmd, cib)
end
|
.prefetch(resources) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 66
def self.prefetch(resources)
instances.each do |prov|
if res = resources[prov.name.to_s]
res.provider = prov
end
end
end
|
.ready?(shadow_cib) ⇒ Boolean
rubocop:enable Style/ClassVars
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/crmsh.rb', line 25
def self.ready?(shadow_cib)
return true if @@crmready
cmd = [command(:crm_attribute), '--type', 'crm_config', '--query', '--name', 'dc-version']
raw, status = run_command_in_cib(cmd, nil, false)
if status.zero?
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
@@crmready = true
debug("Corosync is ready, CIB epoch is #{cib_epoch}.")
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
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 76
def self.run_command_in_cib(cmd, cib = nil, failonfail = true)
custom_environment = if cib.nil?
{ combine: true }
else
{ combine: true, custom_environment: { 'CIB_shadow' => cib } }
end
_run_command_in_cib(cmd, cib, failonfail, custom_environment)
end
|
.sync_shadow_cib(cib, failondeletefail = false) ⇒ Object
85
86
87
88
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 85
def self.sync_shadow_cib(cib, failondeletefail = false)
run_command_in_cib(['crm_shadow', '--force', '--delete', cib], nil, failondeletefail)
run_command_in_cib(['crm_shadow', '--batch', '--create', cib])
end
|
Instance Method Details
#exists? ⇒ Boolean
90
91
92
93
94
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 90
def exists?
self.class.block_until_ready
debug(@property_hash.inspect)
!(@property_hash[:ensure] == :absent || @property_hash.empty?)
end
|