Class: Puppet::Provider::Pacemaker_common
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Pacemaker_common
- Defined in:
- lib/puppet/provider/pacemaker_common.rb
Constant Summary collapse
- RETRY_COUNT =
100
- RETRY_STEP =
6
Instance Method Summary collapse
-
#attributes_to_hash(element) ⇒ Hash<String => String>
convert elements’s attributes to hash.
-
#ban_primitive(primitive, node = '') ⇒ Object
ban this primitive.
-
#cib ⇒ REXML::Document
create a new REXML CIB document.
-
#cib_reset ⇒ Object
reset all saved variables to obtain new data.
-
#cib_section_lrm_resources(lrm) ⇒ REXML::Element
get lrm_rsc_ops section from lrm_resource section CIB section at /cib/status/node_state/lrm/lrm_resources/lrm_resource.
-
#cib_section_lrm_rsc_ops(lrm_resource) ⇒ REXML::Element
get lrm_rsc_ops section from lrm_resource section CIB section at /cib/status/node_state/lrm/lrm_resources/lrm_resource/lrm_rsc_op.
-
#cib_section_nodes_state ⇒ REXML::Element
get node_state CIB section.
-
#cib_section_primitives ⇒ Array<REXML::Element>
get primitives CIB section.
-
#cleanup_primitive(primitive, node = nil) ⇒ Object
cleanup this primitive.
-
#constraint_location_add(primitive, node, score = 100) ⇒ Object
add a location constraint.
-
#constraint_location_remove(primitive, node) ⇒ Object
remove a location constraint.
-
#decode_lrm_resources(lrm_resources) ⇒ Hash<String => Hash>
decode lrm_resources section of CIB.
-
#decode_lrm_rsc_ops(lrm_rsc_ops) ⇒ Array<Hash>
decode lrm_rsc_ops section of the resource’s CIB.
-
#determine_primitive_status(ops) ⇒ 'start', ...
determine resource status by parsing last operations nil means that status is unknown.
-
#disable_primitive(primitive) ⇒ Object
(also: #stop_primitive)
disable this primitive.
-
#elements_to_hash(element, key, tag = nil) ⇒ Hash<String => String>
convert element’s children to hash of their attributes using key and hash key.
-
#enable_primitive(primitive) ⇒ Object
(also: #start_primitive)
enable this primitive.
-
#failed_operations_found?(ops) ⇒ TrueClass, FalseClass
check if operations have same failed operations that should be cleaned up later.
-
#get_cluster_debug_report ⇒ String
form a cluster status report for debugging.
-
#get_primitive_puppet_enable(primitive) ⇒ :true, :false
return service enabled status value expected by Puppet puppet wants :true or :false symbols.
-
#get_primitive_puppet_status(primitive, node = nil) ⇒ :running, :stopped
return service status value expected by Puppet puppet wants :running or :stopped symbol.
-
#is_online? ⇒ TrueClass, FalseClass
check if pacemaker is online and we can work with it.
-
#maintenance_mode(primitive) ⇒ Object
set maintenance_mode of the cluster.
-
#manage_primitive(primitive) ⇒ Object
manage this primitive.
-
#move_primitive(primitive, node = '') ⇒ Object
move this primitive.
-
#no_quorum_policy(primitive) ⇒ Object
set quorum_policy of the cluster.
-
#nodes ⇒ Hash<String => Hash>
get nodes structure with resources and their statuses.
-
#operation_status(op) ⇒ 'start', ...
determine the status of a single operation.
-
#primitive_class(primitive) ⇒ String
return primitive class.
-
#primitive_exists?(primitive) ⇒ Boolean
check if primitive exists in the confiuguration.
-
#primitive_has_failures?(primitive, node = nil) ⇒ TrueClass, FalseClass
does this primitive have failed operations?.
-
#primitive_has_master_running?(primitive, node = nil) ⇒ TrueClass, FalseClass
check if primitive is running as a master either anywhere or on the give node.
-
#primitive_is_clone?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone.
-
#primitive_is_complex?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone or multistate.
-
#primitive_is_managed?(primitive) ⇒ TrueClass, FalseClass
determine if primitive is managed TODO: will not work correctly if cluster is in management mode.
-
#primitive_is_multistate?(primitive) ⇒ TrueClass, FalseClass
check if primitive is multistate.
-
#primitive_is_running?(primitive, node = nil) ⇒ TrueClass, FalseClass
determine if a primitive is running on the entire cluster of on a node if node name param given.
-
#primitive_is_started?(primitive) ⇒ TrueClass, FalseClass
determine if primitive has target-state started TODO: will not work correctly if target state is set globally to stopped.
-
#primitive_status(primitive, node = nil) ⇒ String
get a status of a primitive on the entire cluster of on a node if node name param given.
-
#primitives ⇒ Hash<String => Hash>
get primitives configuration structure with primitives and their attributes.
-
#primitives_status_by_node ⇒ Hash
generate report of primitive statuses by node mostly for debugging.
-
#raw_cib ⇒ String
get a raw CIB from cibadmin or from a debug file if raw_cib_file is set.
-
#retry_block_until_true ⇒ Object
retry the given block until it returns true or for RETRY_COUNT times with RETRY_STEP sec step print cluster status report on fail.
-
#retry_command ⇒ String
retry the given command until it runs without errors or for RETRY_COUNT times with RETRY_STEP sec step print cluster status report on fail returns normal command output on success.
-
#unban_primitive(primitive, node = '') ⇒ Object
(also: #clear_primitive, #unmove_primitive)
unban/unmove this primitive.
-
#unmanage_primitive(primitive) ⇒ Object
unamanage this primitive.
-
#wait_for_master(primitive, node = nil) ⇒ Object
wait for primitive to start as a master if node is given then start as a master on this node.
-
#wait_for_online ⇒ Object
wait for pacemaker to become online.
-
#wait_for_start(primitive, node = nil) ⇒ Object
wait for primitive to start if node is given then start on this node.
-
#wait_for_status(primitive, node = nil) ⇒ Object
wait until we can get a known status of the primitive.
-
#wait_for_stop(primitive, node = nil) ⇒ Object
wait for primitive to stop if node is given then start on this node.
Instance Method Details
#attributes_to_hash(element) ⇒ Hash<String => String>
convert elements’s attributes to hash
148 149 150 151 152 153 154 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 148 def attributes_to_hash(element) hash = {} element.attributes.each do |a, v| hash.store a.to_s, v.to_s end hash end |
#ban_primitive(primitive, node = '') ⇒ Object
ban this primitive
327 328 329 330 331 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 327 def ban_primitive(primitive, node = '') retry_command { pcs 'resource', 'ban', primitive, node } end |
#cib ⇒ REXML::Document
create a new REXML CIB document
26 27 28 29 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 26 def cib return @cib if @cib @cib = REXML::Document.new(raw_cib) end |
#cib_reset ⇒ Object
reset all saved variables to obtain new data
32 33 34 35 36 37 38 39 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 32 def cib_reset # Puppet.debug 'Reset CIB memoization' @raw_cib = nil @cib = nil @primitives = nil @primitives_structure = nil @nodes_structure = nil end |
#cib_section_lrm_resources(lrm) ⇒ REXML::Element
get lrm_rsc_ops section from lrm_resource section CIB section at /cib/status/node_state/lrm/lrm_resources/lrm_resource
66 67 68 69 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 66 def cib_section_lrm_resources(lrm) return unless lrm.is_a? REXML::Element REXML::XPath.match lrm, 'lrm_resources/lrm_resource' end |
#cib_section_lrm_rsc_ops(lrm_resource) ⇒ REXML::Element
get lrm_rsc_ops section from lrm_resource section CIB section at /cib/status/node_state/lrm/lrm_resources/lrm_resource/lrm_rsc_op
45 46 47 48 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 45 def cib_section_lrm_rsc_ops(lrm_resource) return unless lrm_resource.is_a? REXML::Element REXML::XPath.match lrm_resource, 'lrm_rsc_op' end |
#cib_section_nodes_state ⇒ REXML::Element
get node_state CIB section
52 53 54 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 52 def cib_section_nodes_state REXML::XPath.match cib, '//node_state' end |
#cib_section_primitives ⇒ Array<REXML::Element>
get primitives CIB section
58 59 60 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 58 def cib_section_primitives REXML::XPath.match cib, '//primitive' end |
#cleanup_primitive(primitive, node = nil) ⇒ Object
cleanup this primitive
353 354 355 356 357 358 359 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 353 def cleanup_primitive(primitive, node = nil) opts = ['--cleanup', "--resource=#{primitive}"] opts << "--node=#{node}" if node retry_command { crm_resource opts } end |
#constraint_location_add(primitive, node, score = 100) ⇒ Object
add a location constraint
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 397 def constraint_location_add(primitive, node, score = 100) id = "#{primitive}-on-#{node}" xml = <<-EOF <diff> <diff-added> <cib> <configuration> <constraints> <rsc_location id="#{id}" node="#{node}" rsc="#{primitive}" score="#{score}" __crm_diff_marker__="added:top"/> </constraints> </configuration> </cib> </diff-added> </diff> EOF retry_command { cibadmin '--patch', '--sync-call', '--xml-text', xml } end |
#constraint_location_remove(primitive, node) ⇒ Object
remove a location constraint
420 421 422 423 424 425 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 420 def constraint_location_remove(primitive, node) id = "#{primitive}_on_#{node}" retry_command { pcs 'constraint', 'location', 'remove', id } end |
#decode_lrm_resources(lrm_resources) ⇒ Hash<String => Hash>
decode lrm_resources section of CIB
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 177 def decode_lrm_resources(lrm_resources) resources = {} lrm_resources.each do |lrm_resource| resource = attributes_to_hash lrm_resource id = resource['id'] next unless id lrm_rsc_ops = cib_section_lrm_rsc_ops lrm_resource next unless lrm_rsc_ops ops = decode_lrm_rsc_ops lrm_rsc_ops resource.store 'ops', ops resource.store 'status', determine_primitive_status(ops) resource.store 'failed', failed_operations_found?(ops) resources.store id, resource end resources end |
#decode_lrm_rsc_ops(lrm_rsc_ops) ⇒ Array<Hash>
decode lrm_rsc_ops section of the resource’s CIB
197 198 199 200 201 202 203 204 205 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 197 def decode_lrm_rsc_ops(lrm_rsc_ops) ops = [] lrm_rsc_ops.each do |lrm_rsc_op| op = attributes_to_hash lrm_rsc_op next unless op['call-id'] ops << op end ops.sort { |a,b| a['call-id'].to_i <=> b['call-id'].to_i } end |
#determine_primitive_status(ops) ⇒ 'start', ...
determine resource status by parsing last operations nil means that status is unknown
112 113 114 115 116 117 118 119 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 112 def determine_primitive_status(ops) status = nil ops.each do |op| op_status = operation_status op status = op_status if op_status end status end |
#disable_primitive(primitive) ⇒ Object Also known as: stop_primitive
disable this primitive
309 310 311 312 313 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 309 def disable_primitive(primitive) retry_command { pcs 'resource', 'disable', primitive } end |
#elements_to_hash(element, key, tag = nil) ⇒ Hash<String => String>
convert element’s children to hash of their attributes using key and hash key
161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 161 def elements_to_hash(element, key, tag = nil) elements = {} children = element.get_elements tag return elements unless children children.each do |child| child_structure = attributes_to_hash child name = child_structure[key] next unless name elements.store name, child_structure end elements end |
#enable_primitive(primitive) ⇒ Object Also known as: start_primitive
enable this primitive
318 319 320 321 322 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 318 def enable_primitive(primitive) retry_command { pcs 'resource', 'enable', primitive } end |
#failed_operations_found?(ops) ⇒ TrueClass, FalseClass
check if operations have same failed operations that should be cleaned up later
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 125 def failed_operations_found?(ops) ops.each do |op| # skip incompleate ops next unless op['op-status'] == '0' # skip useless ops next unless %w(start stop monitor promote).include? op['operation'] # are there failed start, stop if %w(start stop promote).include? op['operation'] return true if op['rc-code'] != '0' end # are there failed monitors if op['operation'] == 'monitor' return true unless %w(0 7 8).include? op['rc-code'] end end false end |
#get_cluster_debug_report ⇒ String
form a cluster status report for debugging
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 485 def get_cluster_debug_report report = "\n" primitives_status_by_node.each do |primitive, data| primitive_name = primitive primitive_name = primitives[primitive]['name'] if primitives[primitive]['name'] primitive_type = 'Simple' primitive_type = 'Cloned' if primitive_is_clone? primitive primitive_type = 'Multistate' if primitive_is_multistate? primitive primitive_status = primitive_status primitive report += "-> #{primitive_type} primitive '#{primitive_name}' global status: #{primitive_status}" report += ' (UNMANAGE)' unless primitive_is_managed? primitive report += "\n" report += ' ' if data.any? nodes = [] data.keys.sort.each do |node_name| node_status = data.fetch node_name node_block = "#{node_name}: #{node_status}" node_block += ' (FAIL)' if primitive_has_failures? primitive, node_name nodes << node_block end report += nodes.join ' | ' report += "\n" end report end |
#get_primitive_puppet_enable(primitive) ⇒ :true, :false
return service enabled status value expected by Puppet puppet wants :true or :false symbols
577 578 579 580 581 582 583 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 577 def get_primitive_puppet_enable(primitive) if primitive_is_managed? primitive :true else :false end end |
#get_primitive_puppet_status(primitive, node = nil) ⇒ :running, :stopped
return service status value expected by Puppet puppet wants :running or :stopped symbol
565 566 567 568 569 570 571 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 565 def get_primitive_puppet_status(primitive, node = nil) if primitive_is_running? primitive, node :running else :stopped end end |
#is_online? ⇒ TrueClass, FalseClass
check if pacemaker is online and we can work with it
614 615 616 617 618 619 620 621 622 623 624 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 614 def is_online? begin dc_version = crm_attribute '-q', '--type', 'crm_config', '--query', '--name', 'dc-version' return false unless dc_version return false if dc_version.empty? return false unless cib_section_nodes_state true rescue Puppet::ExecutionFailure false end end |
#maintenance_mode(primitive) ⇒ Object
set maintenance_mode of the cluster
387 388 389 390 391 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 387 def maintenance_mode(primitive) retry_command { pcs 'property', 'set', "maintenance-mode=#{primitive}" } end |
#manage_primitive(primitive) ⇒ Object
manage this primitive
363 364 365 366 367 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 363 def manage_primitive(primitive) retry_command { pcs 'resource', 'manage', primitive } end |
#move_primitive(primitive, node = '') ⇒ Object
move this primitive
335 336 337 338 339 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 335 def move_primitive(primitive, node = '') retry_command { pcs 'resource', 'move', primitive, node } end |
#no_quorum_policy(primitive) ⇒ Object
set quorum_policy of the cluster
379 380 381 382 383 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 379 def no_quorum_policy(primitive) retry_command { pcs 'property', 'set', "no-quorum-policy=#{primitive}" } end |
#nodes ⇒ Hash<String => Hash>
get nodes structure with resources and their statuses
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 209 def nodes return @nodes_structure if @nodes_structure @nodes_structure = {} cib_section_nodes_state.each do |node_state| node = attributes_to_hash node_state node_name = node['uname'] next unless node_name lrm = node_state.elements['lrm'] next unless lrm lrm_resources = cib_section_lrm_resources lrm next unless lrm_resources resources = decode_lrm_resources lrm_resources node.store 'primitives', resources @nodes_structure.store node_name, node end @nodes_structure end |
#operation_status(op) ⇒ 'start', ...
determine the status of a single operation
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 74 def operation_status(op) # skip pending ops # we should wait for status for become known return if op['op-status'] == '-1' if op['operation'] == 'monitor' # for monitor operation status is determined by its rc-code # 0 - start, 8 - master, 7 - stop, else - error case op['rc-code'] when '0' 'start' when '7' 'stop' when '8' 'master' else # not entirely correct but count failed monitor as 'stop' 'stop' end elsif %w(start stop promote).include? op['operation'] # for start/stop/promote status is set if op was successful # use master instead of promote return unless %w(0 7 8).include? op['rc-code'] if op['operation'] == 'promote' 'master' else op['operation'] end else # other operations are irrelevant nil end end |
#primitive_class(primitive) ⇒ String
return primitive class
302 303 304 305 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 302 def primitive_class(primitive) return unless primitive_exists? primitive primitives[primitive]['class'] end |
#primitive_exists?(primitive) ⇒ Boolean
check if primitive exists in the confiuguration
587 588 589 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 587 def primitive_exists?(primitive) primitives.key? primitive end |
#primitive_has_failures?(primitive, node = nil) ⇒ TrueClass, FalseClass
does this primitive have failed operations?
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 516 def primitive_has_failures?(primitive, node = nil) return unless primitive_exists? primitive if node nodes. fetch(node, {}). fetch('primitives',{}). fetch(primitive, {}). fetch('failed', nil) else nodes.each do |k,v| failed = v.fetch('primitives',{}). fetch(primitive, {}). fetch('failed', nil) return true if failed end false end end |
#primitive_has_master_running?(primitive, node = nil) ⇒ TrueClass, FalseClass
check if primitive is running as a master either anywhere or on the give node
552 553 554 555 556 557 558 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 552 def primitive_has_master_running?(primitive, node = nil) is_multistate = primitive_is_multistate? primitive return is_multistate unless is_multistate status = primitive_status primitive, node return status unless status status == 'master' end |
#primitive_is_clone?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone
284 285 286 287 288 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 284 def primitive_is_clone?(primitive) is_complex = primitive_is_complex? primitive return is_complex unless is_complex primitives[primitive]['parent']['type'] == 'clone' end |
#primitive_is_complex?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone or multistate
276 277 278 279 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 276 def primitive_is_complex?(primitive) return unless primitive_exists? primitive primitives[primitive].key? 'parent' end |
#primitive_is_managed?(primitive) ⇒ TrueClass, FalseClass
determine if primitive is managed TODO: will not work correctly if cluster is in management mode
595 596 597 598 599 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 595 def primitive_is_managed?(primitive) return unless primitive_exists? primitive is_managed = primitives.fetch(primitive).fetch('meta_attributes', {}).fetch('is-managed', {}).fetch('value', 'true') is_managed == 'true' end |
#primitive_is_multistate?(primitive) ⇒ TrueClass, FalseClass
check if primitive is multistate
293 294 295 296 297 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 293 def primitive_is_multistate?(primitive) is_complex = primitive_is_complex? primitive return is_complex unless is_complex primitives[primitive]['parent']['type'] == 'master' end |
#primitive_is_running?(primitive, node = nil) ⇒ TrueClass, FalseClass
determine if a primitive is running on the entire cluster of on a node if node name param given
540 541 542 543 544 545 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 540 def primitive_is_running?(primitive, node = nil) return unless primitive_exists? primitive status = primitive_status primitive, node return status unless status %w(start master).include? status end |
#primitive_is_started?(primitive) ⇒ TrueClass, FalseClass
determine if primitive has target-state started TODO: will not work correctly if target state is set globally to stopped
605 606 607 608 609 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 605 def primitive_is_started?(primitive) return unless primitive_exists? primitive target_role = primitives.fetch(primitive).fetch('meta_attributes', {}).fetch('target-role', {}).fetch('value', 'Started') target_role == 'Started' end |
#primitive_status(primitive, node = nil) ⇒ String
get a status of a primitive on the entire cluster of on a node if node name param given
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 432 def primitive_status(primitive, node = nil) if node found_node = nil nodes.each do |k, v| if v.fetch("uname", {}).eql? node found_node = v end end return unless found_node found_node. fetch('primitives',{}). fetch(primitive, {}). fetch('status', nil) else statuses = [] nodes.each do |k,v| status = v.fetch('primitives',{}). fetch(primitive, {}). fetch('status', nil) statuses << status end status_values = { 'stop' => 0, 'start' => 1, 'master' => 2, } statuses.max_by do |status| return unless status status_values[status] end end end |
#primitives ⇒ Hash<String => Hash>
get primitives configuration structure with primitives and their attributes
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 229 def primitives return @primitives_structure if @primitives_structure @primitives_structure = {} cib_section_primitives.each do |primitive| primitive_structure = {} id = primitive.attributes['id'] next unless id primitive_structure.store 'name', id primitive.attributes.each do |k, v| primitive_structure.store k.to_s, v end if primitive.parent.name and primitive.parent.attributes['id'] parent_structure = { 'id' => primitive.parent.attributes['id'], 'type' => primitive.parent.name } primitive_structure.store 'name', parent_structure['id'] primitive_structure.store 'parent', parent_structure end instance_attributes = primitive.elements['instance_attributes'] if instance_attributes instance_attributes_structure = elements_to_hash instance_attributes, 'name', 'nvpair' primitive_structure.store 'instance_attributes', instance_attributes_structure end = primitive.elements['meta_attributes'] if = elements_to_hash , 'name', 'nvpair' primitive_structure.store 'meta_attributes', end operations = primitive.elements['operations'] if operations operations_structure = elements_to_hash operations, 'id', 'op' primitive_structure.store 'operations', operations_structure end @primitives_structure.store id, primitive_structure end @primitives_structure end |
#primitives_status_by_node ⇒ Hash
generate report of primitive statuses by node mostly for debugging
468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 468 def primitives_status_by_node report = {} return unless nodes.is_a? Hash nodes.each do |node_name, node_data| primitives_of_node = node_data['primitives'] next unless primitives_of_node.is_a? Hash primitives_of_node.each do |primitive, primitive_data| primitive_status = primitive_data['status'] report[primitive] = {} unless report[primitive].is_a? Hash report[primitive][node_name] = primitive_status end end report end |
#raw_cib ⇒ String
get a raw CIB from cibadmin or from a debug file if raw_cib_file is set
16 17 18 19 20 21 22 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 16 def raw_cib @raw_cib = cibadmin '-Q' if @raw_cib == '' or not @raw_cib fail 'Could not dump CIB XML using "cibadmin -Q" command!' end @raw_cib end |
#retry_block_until_true ⇒ Object
retry the given block until it returns true or for RETRY_COUNT times with RETRY_STEP sec step print cluster status report on fail
649 650 651 652 653 654 655 656 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 649 def retry_block_until_true (0..RETRY_COUNT).each do return if yield sleep RETRY_STEP end Puppet.debug get_cluster_debug_report if is_online? fail "Execution timeout after #{RETRY_COUNT * RETRY_STEP} seconds!" end |
#retry_command ⇒ String
retry the given command until it runs without errors or for RETRY_COUNT times with RETRY_STEP sec step print cluster status report on fail returns normal command output on success
631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 631 def retry_command (0..RETRY_COUNT).each do begin out = yield rescue Puppet::ExecutionFailure => e Puppet.debug "Command failed: #{e.}" sleep RETRY_STEP else return out end end Puppet.debug get_cluster_debug_report if is_online? fail "Execution timeout after #{RETRY_COUNT * RETRY_STEP} seconds!" end |
#unban_primitive(primitive, node = '') ⇒ Object Also known as: clear_primitive, unmove_primitive
unban/unmove this primitive
343 344 345 346 347 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 343 def unban_primitive(primitive, node = '') retry_command { pcs 'resource', 'clear', primitive, node } end |
#unmanage_primitive(primitive) ⇒ Object
unamanage this primitive
371 372 373 374 375 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 371 def unmanage_primitive(primitive) retry_command { pcs 'resource', 'unmanage', primitive } end |
#wait_for_master(primitive, node = nil) ⇒ Object
wait for primitive to start as a master if node is given then start as a master on this node
705 706 707 708 709 710 711 712 713 714 715 716 717 718 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 705 def wait_for_master(primitive, node = nil) = "Waiting #{RETRY_COUNT * RETRY_STEP} seconds for service '#{primitive}' to start master" += " on node '#{node}'" if node Puppet.debug get_cluster_debug_report Puppet.debug retry_block_until_true do cib_reset primitive_has_master_running? primitive, node end Puppet.debug get_cluster_debug_report = "Service '#{primitive}' have started master" += " on node '#{node}'" if node Puppet.debug end |
#wait_for_online ⇒ Object
wait for pacemaker to become online
659 660 661 662 663 664 665 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 659 def wait_for_online Puppet.debug "Waiting #{RETRY_COUNT * RETRY_STEP} seconds for Pacemaker to become online" retry_block_until_true do is_online? end Puppet.debug 'Pacemaker is online' end |
#wait_for_start(primitive, node = nil) ⇒ Object
wait for primitive to start if node is given then start on this node
686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 686 def wait_for_start(primitive, node = nil) = "Waiting #{RETRY_COUNT * RETRY_STEP} seconds for service '#{primitive}' to start" += " on node '#{node}'" if node Puppet.debug get_cluster_debug_report Puppet.debug retry_block_until_true do cib_reset primitive_is_running? primitive, node end Puppet.debug get_cluster_debug_report = "Service '#{primitive}' have started" += " on node '#{node}'" if node Puppet.debug end |
#wait_for_status(primitive, node = nil) ⇒ Object
wait until we can get a known status of the primitive
669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 669 def wait_for_status(primitive, node = nil) msg = "Wait for known status of '#{primitive}'" msg += " on node '#{node}'" if node Puppet.debug msg retry_block_until_true do cib_reset primitive_status(primitive) != nil end msg = "Primitive '#{primitive}' has status '#{primitive_status primitive}'" msg += " on node '#{node}'" if node Puppet.debug msg end |
#wait_for_stop(primitive, node = nil) ⇒ Object
wait for primitive to stop if node is given then start on this node
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 |
# File 'lib/puppet/provider/pacemaker_common.rb', line 724 def wait_for_stop(primitive, node = nil) = "Waiting #{RETRY_COUNT * RETRY_STEP} seconds for service '#{primitive}' to stop" += " on node '#{node}'" if node Puppet.debug get_cluster_debug_report Puppet.debug retry_block_until_true do cib_reset result = primitive_is_running? primitive, node result.is_a? FalseClass end Puppet.debug get_cluster_debug_report = "Service '#{primitive}' was stopped" += " on node '#{node}'" if node Puppet.debug end |