Class: PuppetX::Voxpupuli::Corosync::Provider::Pcs
- Inherits:
-
CibHelper
- Object
- Puppet::Provider
- CibHelper
- PuppetX::Voxpupuli::Corosync::Provider::Pcs
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
59
60
61
62
63
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 59
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
65
66
67
68
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 65
def self.get_epoch(cib = nil)
cmd = [command(:pcs), 'cluster', 'cib']
_get_epoch(cmd, cib)
end
|
.prefetch(resources) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.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
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
54
55
56
57
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 27
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?
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
@@pcsready = true
debug("Corosync is ready, CIB epoch is #{cib_epoch}. Sleeping 5 seconds for safety.")
sleep 5
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
88
89
90
91
92
93
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 80
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
95
96
97
98
99
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 95
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
|
.syntax_010(old, new) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 112
def self.syntax_010(old, new)
if Puppet::Util::Package.versioncmp(version, '0.10.0') >= 0
new
else
old
end
end
|
.version ⇒ Object
107
108
109
110
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 107
def self.version
cmd = [command(:pcs), '--version']
Puppet::Util::Execution.execute(cmd, { failonfail: true })
end
|
Instance Method Details
#exists? ⇒ Boolean
101
102
103
104
105
|
# File 'lib/puppet_x/voxpupuli/corosync/provider/pcs.rb', line 101
def exists?
self.class.block_until_ready
debug(@property_hash.inspect)
!(@property_hash[:ensure] == :absent || @property_hash.empty?)
end
|