Module: Pacemaker::Primitives
- Included in:
- Puppet::Provider::PacemakerXML, Serverspec::Type::PacemakerXML
- Defined in:
- lib/pacemaker/xml/primitives.rb
Overview
function related to the primitives configuration main structure “primitives”
Instance Method Summary collapse
-
#ban_primitive(primitive, node) ⇒ Object
ban this primitive.
-
#cib_section_primitives ⇒ Array<REXML::Element>
get all ‘primitive’ sections from CIB.
-
#cleanup_primitive(primitive, node = nil) ⇒ Object
cleanup this primitive cleanups on every node if node is not given.
-
#disable_primitive(primitive) ⇒ Object
(also: #stop_primitive)
disable this primitive.
-
#enable_primitive(primitive) ⇒ Object
(also: #start_primitive)
enable this primitive.
-
#manage_primitive(primitive) ⇒ Object
manage this primitive.
-
#move_primitive(primitive, node) ⇒ Object
move this primitive.
-
#parse_operations(operations_element) ⇒ Hash
parse the operations structure of a primitive.
-
#primitive_class(primitive) ⇒ String?
return primitive class.
-
#primitive_complex_type(primitive) ⇒ Symbol
return primitive complex type or nil is the primitive is simple.
-
#primitive_exists?(primitive) ⇒ Boolean
check if primitive exists in the configuration.
-
#primitive_full_name(primitive) ⇒ String
return the full name of the complex primitive or just a name for a simple primitive.
-
#primitive_group(primitive) ⇒ String?
get the group name of the primitive returns nil if primitive is not in a group.
-
#primitive_in_group?(primitive) ⇒ TrueClass, FalseClass
check if the primitive is assigned to a group.
-
#primitive_is_clone?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone.
-
#primitive_is_complex?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone or master primitives in groups are not considered complex despite having the complex structure.
-
#primitive_is_managed?(primitive) ⇒ TrueClass, FalseClass
determine if primitive is managed.
-
#primitive_is_master?(primitive) ⇒ TrueClass, FalseClass
check if primitive is master.
-
#primitive_is_simple?(primitive) ⇒ TrueClass, FalseClass
reverse of the complex? predicate but returns nil if resource doesn’t exist.
-
#primitive_is_started?(primitive) ⇒ TrueClass, FalseClass
determine if primitive has target-state started.
-
#primitive_provider(primitive) ⇒ String?
return primitive provider.
-
#primitive_type(primitive) ⇒ String?
return primitive type.
-
#primitives ⇒ Hash<String => Hash>
get primitives configuration structure with primitives and their attributes.
-
#read_complex_types ⇒ Array<String>
the list of complex types the library should read from the CIB and parse their meta-data.
-
#set_primitive_meta_attribute(primitive, attribute, value) ⇒ Object
sets the meta attribute of a primitive.
-
#unban_primitive(primitive, node) ⇒ Object
(also: #clear_primitive)
unban this primitive.
-
#unmanage_primitive(primitive) ⇒ Object
unmanage this primitive.
-
#unmove_primitive(primitive, node) ⇒ Object
un-move this primitive.
-
#write_complex_types ⇒ Array<String>
the list of complex type the library should be able to create XML elements for.
-
#xml_primitive(data) ⇒ REXML::Element
generate a new XML element object and fill it with the primitive data from the provided primitive structure.
Instance Method Details
#ban_primitive(primitive, node) ⇒ Object
ban this primitive
52 53 54 55 56 |
# File 'lib/pacemaker/xml/primitives.rb', line 52 def ban_primitive(primitive, node) = ['--quiet', '--resource', primitive, '--node', node] += ['--ban'] retry_block { crm_resource_safe } end |
#cib_section_primitives ⇒ Array<REXML::Element>
get all ‘primitive’ sections from CIB
7 8 9 |
# File 'lib/pacemaker/xml/primitives.rb', line 7 def cib_section_primitives REXML::XPath.match cib, '//primitive' end |
#cleanup_primitive(primitive, node = nil) ⇒ Object
cleanup this primitive cleanups on every node if node is not given
91 92 93 94 95 96 |
# File 'lib/pacemaker/xml/primitives.rb', line 91 def cleanup_primitive(primitive, node = nil) = ['--quiet', '--resource', primitive] += ['--node', node] if node += ['--cleanup'] retry_block { crm_resource_safe } end |
#disable_primitive(primitive) ⇒ Object Also known as: stop_primitive
disable this primitive
23 24 25 |
# File 'lib/pacemaker/xml/primitives.rb', line 23 def disable_primitive(primitive) primitive, 'target-role', 'Stopped' end |
#enable_primitive(primitive) ⇒ Object Also known as: start_primitive
enable this primitive
31 32 33 |
# File 'lib/pacemaker/xml/primitives.rb', line 31 def enable_primitive(primitive) primitive, 'target-role', 'Started' end |
#manage_primitive(primitive) ⇒ Object
manage this primitive
39 40 41 |
# File 'lib/pacemaker/xml/primitives.rb', line 39 def manage_primitive(primitive) primitive, 'is-managed', 'true' end |
#move_primitive(primitive, node) ⇒ Object
move this primitive
72 73 74 75 76 |
# File 'lib/pacemaker/xml/primitives.rb', line 72 def move_primitive(primitive, node) = ['--quiet', '--resource', primitive, '--node', node] += ['--move'] retry_block { crm_resource_safe } end |
#parse_operations(operations_element) ⇒ Hash
parse the operations structure of a primitive
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/pacemaker/xml/primitives.rb', line 167 def parse_operations(operations_element) return unless operations_element.is_a? REXML::Element operations = {} ops = operations_element.get_elements 'op' return operations unless ops.any? ops.each do |op| op_structure = attributes_to_hash op id = op_structure['id'] next unless id instance_attributes = op.elements['instance_attributes'] if instance_attributes instance_attributes_structure = children_elements_to_hash instance_attributes, 'name', 'nvpair' if instance_attributes_structure.key? 'OCF_CHECK_LEVEL' value = instance_attributes_structure.fetch('OCF_CHECK_LEVEL', {}).fetch('value', nil) op_structure['OCF_CHECK_LEVEL'] = value if value end end operations.store id, op_structure end operations end |
#primitive_class(primitive) ⇒ String?
return primitive class
198 199 200 201 |
# File 'lib/pacemaker/xml/primitives.rb', line 198 def primitive_class(primitive) return unless primitive_exists? primitive primitives[primitive]['class'] end |
#primitive_complex_type(primitive) ⇒ Symbol
return primitive complex type or nil is the primitive is simple
223 224 225 226 |
# File 'lib/pacemaker/xml/primitives.rb', line 223 def primitive_complex_type(primitive) return unless primitive_is_complex? primitive primitives[primitive]['complex']['type'].to_sym end |
#primitive_exists?(primitive) ⇒ Boolean
check if primitive exists in the configuration
191 192 193 |
# File 'lib/pacemaker/xml/primitives.rb', line 191 def primitive_exists?(primitive) primitives.key? primitive end |
#primitive_full_name(primitive) ⇒ String
return the full name of the complex primitive or just a name for a simple primitive
231 232 233 234 |
# File 'lib/pacemaker/xml/primitives.rb', line 231 def primitive_full_name(primitive) return unless primitive_exists? primitive primitives[primitive]['name'] end |
#primitive_group(primitive) ⇒ String?
get the group name of the primitive returns nil if primitive is not in a group
268 269 270 271 |
# File 'lib/pacemaker/xml/primitives.rb', line 268 def primitive_group(primitive) return unless primitive_in_group? primitive primitives[primitive]['complex']['id'] end |
#primitive_in_group?(primitive) ⇒ TrueClass, FalseClass
check if the primitive is assigned to a group
259 260 261 262 263 |
# File 'lib/pacemaker/xml/primitives.rb', line 259 def primitive_in_group?(primitive) return unless primitive_exists? primitive return false unless primitives[primitive].key? 'complex' primitives[primitive]['complex']['type'] == 'group' end |
#primitive_is_clone?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone
276 277 278 279 280 |
# File 'lib/pacemaker/xml/primitives.rb', line 276 def primitive_is_clone?(primitive) is_complex = primitive_is_complex? primitive return is_complex unless is_complex primitives[primitive]['complex']['type'] == 'clone' end |
#primitive_is_complex?(primitive) ⇒ TrueClass, FalseClass
check if primitive is clone or master primitives in groups are not considered complex despite having the complex structure
241 242 243 244 245 |
# File 'lib/pacemaker/xml/primitives.rb', line 241 def primitive_is_complex?(primitive) return unless primitive_exists? primitive return false unless primitives[primitive].key? 'complex' primitives[primitive]['complex']['type'] != 'group' end |
#primitive_is_managed?(primitive) ⇒ TrueClass, FalseClass
determine if primitive is managed
294 295 296 297 298 |
# File 'lib/pacemaker/xml/primitives.rb', line 294 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_master?(primitive) ⇒ TrueClass, FalseClass
check if primitive is master
285 286 287 288 289 |
# File 'lib/pacemaker/xml/primitives.rb', line 285 def primitive_is_master?(primitive) is_complex = primitive_is_complex? primitive return is_complex unless is_complex primitives[primitive]['complex']['type'] == 'master' end |
#primitive_is_simple?(primitive) ⇒ TrueClass, FalseClass
reverse of the complex? predicate but returns nil if resource doesn’t exist
251 252 253 254 |
# File 'lib/pacemaker/xml/primitives.rb', line 251 def primitive_is_simple?(primitive) return unless primitive_exists? primitive ! primitive_is_complex?(primitive) end |
#primitive_is_started?(primitive) ⇒ TrueClass, FalseClass
determine if primitive has target-state started
303 304 305 306 307 |
# File 'lib/pacemaker/xml/primitives.rb', line 303 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_provider(primitive) ⇒ String?
return primitive provider
214 215 216 217 |
# File 'lib/pacemaker/xml/primitives.rb', line 214 def primitive_provider(primitive) return unless primitive_exists? primitive primitives[primitive]['provider'] end |
#primitive_type(primitive) ⇒ String?
return primitive type
206 207 208 209 |
# File 'lib/pacemaker/xml/primitives.rb', line 206 def primitive_type(primitive) return unless primitive_exists? primitive primitives[primitive]['type'] end |
#primitives ⇒ Hash<String => Hash>
get primitives configuration structure with primitives and their attributes
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/pacemaker/xml/primitives.rb', line 116 def primitives return @primitives_structure if @primitives_structure @primitives_structure = {} cib_section_primitives.each do |primitive| id = primitive.attributes['id'] next unless id primitive_structure = attributes_to_hash primitive primitive_structure.store 'name', id if read_complex_types.include?(primitive.parent.name) && primitive.parent.attributes['id'] complex_structure = { 'id' => primitive.parent.attributes['id'], 'type' => primitive.parent.name } = primitive.parent.elements['meta_attributes'] if = children_elements_to_hash , 'name', 'nvpair' complex_structure.store 'meta_attributes', end primitive_structure.store 'name', complex_structure['id'] unless complex_structure['type'] == 'group' primitive_structure.store 'complex', complex_structure end instance_attributes = primitive.elements['instance_attributes'] if instance_attributes instance_attributes_structure = children_elements_to_hash instance_attributes, 'name', 'nvpair' primitive_structure.store 'instance_attributes', instance_attributes_structure end = primitive.elements['meta_attributes'] if = children_elements_to_hash , 'name', 'nvpair' primitive_structure.store 'meta_attributes', end operations = primitive.elements['operations'] if operations operations_structure = parse_operations operations primitive_structure.store 'operations', operations_structure end @primitives_structure.store id, primitive_structure end @primitives_structure end |
#read_complex_types ⇒ Array<String>
the list of complex types the library should read from the CIB and parse their meta-data
101 102 103 |
# File 'lib/pacemaker/xml/primitives.rb', line 101 def read_complex_types %w(clone master group) end |
#set_primitive_meta_attribute(primitive, attribute, value) ⇒ Object
sets the meta attribute of a primitive
15 16 17 18 19 |
# File 'lib/pacemaker/xml/primitives.rb', line 15 def (primitive, attribute, value) = ['--quiet', '--resource', primitive] += ['--set-parameter', attribute, '--meta', '--parameter-value', value] retry_block { crm_resource_safe } end |
#unban_primitive(primitive, node) ⇒ Object Also known as: clear_primitive
unban this primitive
61 62 63 64 65 |
# File 'lib/pacemaker/xml/primitives.rb', line 61 def unban_primitive(primitive, node) = ['--quiet', '--resource', primitive, '--node', node] += ['--clear'] retry_block { crm_resource_safe } end |
#unmanage_primitive(primitive) ⇒ Object
unmanage this primitive
45 46 47 |
# File 'lib/pacemaker/xml/primitives.rb', line 45 def unmanage_primitive(primitive) primitive, 'is-managed', 'false' end |
#unmove_primitive(primitive, node) ⇒ Object
un-move this primitive
81 82 83 84 85 |
# File 'lib/pacemaker/xml/primitives.rb', line 81 def unmove_primitive(primitive, node) = ['--quiet', '--resource', primitive, '--node', node] += ['--un-move'] retry_block { crm_resource_safe } end |
#write_complex_types ⇒ Array<String>
the list of complex type the library should be able to create XML elements for
108 109 110 |
# File 'lib/pacemaker/xml/primitives.rb', line 108 def write_complex_types %w(clone master) end |
#xml_primitive(data) ⇒ REXML::Element
generate a new XML element object and fill it with the primitive data from the provided primitive structure
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/pacemaker/xml/primitives.rb', line 314 def xml_primitive(data) raise "Primitive data should be a hash! Got: #{data.inspect}" unless data.is_a? Hash primitive_skip_attributes = %w(name parent instance_attributes operations meta_attributes utilization) primitive_element = xml_element 'primitive', data, primitive_skip_attributes # instance attributes if data['instance_attributes'].respond_to?(:each) && data['instance_attributes'].any? instance_attributes_document = xml_document 'instance_attributes', primitive_element instance_attributes_document.add_attribute 'id', data['id'] + '-instance_attributes' sort_data(data['instance_attributes']).each do |instance_attribute| instance_attribute_element = xml_element 'nvpair', instance_attribute instance_attributes_document.add_element instance_attribute_element if instance_attribute_element end end # meta attributes if data['meta_attributes'].respond_to?(:each) && data['meta_attributes'].any? = xml_document 'meta_attributes', primitive_element .add_attribute 'id', data['id'] + '-meta_attributes' sort_data(data['meta_attributes']).each do || = xml_element 'nvpair', .add_element if end end # operations if data['operations'].respond_to?(:each) && data['operations'].any? operations_document = xml_document 'operations', primitive_element sort_data(data['operations']).each do |operation| operation_element = xml_element 'op', operation, %w(OCF_CHECK_LEVEL) if operation.key? 'OCF_CHECK_LEVEL' instance_attributes_document = xml_document 'instance_attributes', operation_element instance_attributes_id = operation['id'] + '-instance_attributes' instance_attributes_document.add_attribute 'id', instance_attributes_id ocf_check_level_id = instance_attributes_id + '-OCF_CHECK_LEVEL' ocf_check_level_structure = { 'id' => ocf_check_level_id, 'name' => 'OCF_CHECK_LEVEL', 'value' => operation['OCF_CHECK_LEVEL'], } ocf_check_level_element = xml_element 'nvpair', ocf_check_level_structure instance_attributes_document.add_element ocf_check_level_element if ocf_check_level_element end operations_document.add_element operation_element if operation_element end end # complex structure if data['complex'].is_a?(Hash) && write_complex_types.include?(data['complex']['type'].to_s) skip_complex_attributes = 'type' complex_tag_name = data['complex']['type'].to_s complex_element = xml_element complex_tag_name, data['complex'], skip_complex_attributes # complex meta attributes if data['complex']['meta_attributes'].respond_to?(:each) && data['complex']['meta_attributes'].any? = xml_document 'meta_attributes', complex_element .add_attribute 'id', data['complex']['id'] + '-meta_attributes' sort_data(data['complex']['meta_attributes']).each do || = xml_element 'nvpair', .add_element if end end complex_element.add_element primitive_element return complex_element end primitive_element end |