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
59
60
61
62
63
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 59
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
65
66
67
68
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 65
def self.get_epoch(cib = nil)
cmd = [command(:cibadmin), '--query', '--xpath', '/cib', '-l', '-n']
_get_epoch(cmd, cib)
end
|
.prefetch(resources) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 70
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
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
54
55
56
57
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 28
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}.")
true
else
debug("Corosync not ready, retrying: #{raw}")
false
end
end
|
.run_command_in_cib(cmd, cib = nil, failonfail = true) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 80
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
89
90
91
92
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 89
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
94
95
96
97
98
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/crmsh.rb', line 94
def exists?
self.class.block_until_ready
debug(@property_hash.inspect)
!(@property_hash[:ensure] == :absent || @property_hash.empty?)
end
|