Module: Pacemaker::Cib

Included in:
Puppet::Provider::PacemakerXML, Serverspec::Type::PacemakerXML
Defined in:
lib/pacemaker/xml/cib.rb

Overview

this submodule contains the basic functions for low-level actions with CIB data

Instance Method Summary collapse

Instance Method Details

#cibREXML::Document

REXML::Document of the CIB data

Returns:

  • (REXML::Document)

    at ‘/’



18
19
20
21
# File 'lib/pacemaker/xml/cib.rb', line 18

def cib
  return @cib if @cib
  @cib = REXML::Document.new(raw_cib)
end

#cib=(cib) ⇒ Object

insert a new cib xml data instead of retrieving it can be used either for prefetching or for debugging

Parameters:

  • cib (String, REXML::Document)

    CIB XML text or element



26
27
28
29
30
31
32
# File 'lib/pacemaker/xml/cib.rb', line 26

def cib=(cib)
  @cib = if cib.is_a? REXML::Document
           cib
         else
           REXML::Document.new(cib)
         end
end

#cib?TrueClass, FalseClass

check id the CIB is retrieved and memorized

Returns:

  • (TrueClass, FalseClass)


36
37
38
# File 'lib/pacemaker/xml/cib.rb', line 36

def cib?
  !@cib.nil?
end

#cib_reset(comment = nil) ⇒ Object

reset all mnemoization variables to force pacemaker to reload all the data structures

Parameters:

  • comment (String) (defaults to: nil)

    log file comment tag to trace calls



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/pacemaker/xml/cib.rb', line 105

def cib_reset(comment = nil)
  message = 'Call: cib_reset'
  message += " (#{comment})" if comment
  debug message

  @cib = nil

  @primitives_structure = nil
  @locations_structure = nil
  @colocations_structure = nil
  @orders_structure = nil
  @node_status_structure = nil
  @cluster_properties_structure = nil
  @nodes_structure = nil
  @resource_defaults_structure = nil
  @operation_defaults_structure = nil
end

#cibadmin_create(xml, scope = nil) ⇒ Object

add a new XML element to CIB

Parameters:

  • xml (String, REXML::Element)

    XML block to add

  • scope (String) (defaults to: nil)

    XML root scope



43
44
45
46
47
48
# File 'lib/pacemaker/xml/cib.rb', line 43

def cibadmin_create(xml, scope = nil)
  xml = xml_pretty_format xml if xml.is_a? REXML::Element
  options = %w(--force  --sync-call --create)
  options += ['--scope', scope.to_s] if scope
  cibadmin_safe options, '--xml-text', xml.to_s
end

#cibadmin_delete(xml, scope = nil) ⇒ Object

delete the XML element to CIB

Parameters:

  • xml (String, REXML::Element)

    XML block to delete

  • scope (String) (defaults to: nil)

    XML root scope



53
54
55
56
57
58
# File 'lib/pacemaker/xml/cib.rb', line 53

def cibadmin_delete(xml, scope = nil)
  xml = xml_pretty_format xml if xml.is_a? REXML::Element
  options = %w(--force  --sync-call --delete)
  options += ['--scope', scope.to_s] if scope
  cibadmin_safe options, '--xml-text', xml.to_s
end

#cibadmin_modify(xml, scope = nil) ⇒ Object

modify the XML element

Parameters:

  • xml (String, REXML::Element)

    XML element to modify

  • scope (String) (defaults to: nil)

    XML root scope



63
64
65
66
67
68
# File 'lib/pacemaker/xml/cib.rb', line 63

def cibadmin_modify(xml, scope = nil)
  xml = xml_pretty_format xml if xml.is_a? REXML::Element
  options = %w(--force  --sync-call --modify)
  options += ['--scope', scope.to_s] if scope
  cibadmin_safe options, '--xml-text', xml.to_s
end

#cibadmin_replace(xml, scope = nil) ⇒ Object

replace the XML element

Parameters:

  • xml (String, REXML::Element)

    XML element to replace

  • scope (String) (defaults to: nil)

    XML root scope



73
74
75
76
77
78
# File 'lib/pacemaker/xml/cib.rb', line 73

def cibadmin_replace(xml, scope = nil)
  xml = xml_pretty_format xml if xml.is_a? REXML::Element
  options = %w(--force  --sync-call --replace)
  options += ['--scope', scope.to_s] if scope
  cibadmin_safe options, '--xml-text', xml.to_s
end

#dcString?

get the name of the DC (Designated Controller) node used to determine if the cluster have elected one and is ready

Returns:

  • (String, nil)


83
84
85
86
87
88
89
90
# File 'lib/pacemaker/xml/cib.rb', line 83

def dc
  cib_element = cib.elements['/cib']
  return unless cib_element
  dc_node_id = cib_element.attribute('dc-uuid')
  return unless dc_node_id
  return if dc_node_id == 'NONE'
  dc_node_id.to_s
end

#dc_versionString?

get the dc_version string from the CIB configuration used to determine that the cluster have finished forming a correct cib structure uses an independent command call because CIB may not be ready yet

Returns:

  • (String, nil)


96
97
98
99
100
# File 'lib/pacemaker/xml/cib.rb', line 96

def dc_version
  dc_version = crm_attribute '-q', '--type', 'crm_config', '--query', '--name', 'dc-version'
  return if dc_version.empty?
  dc_version
end

#raw_cibString

get the raw CIB from Pacemaker

Returns:

  • (String)

    cib xml data



10
11
12
13
14
# File 'lib/pacemaker/xml/cib.rb', line 10

def raw_cib
  raw_cib = cibadmin '-Q'
  raise 'Could not dump CIB XML!' if !raw_cib || raw_cib == ''
  raw_cib
end