Module: Pacemaker::Constraints
- Included in:
- Puppet::Provider::PacemakerXML, Serverspec::Type::PacemakerXML
- Defined in:
- lib/pacemaker/xml/constraints.rb
Overview
functions related to constraints (order, location, colocation) main structure “constraints” this structure is used by other specific location colocation and order submodules to form their data structures
Instance Method Summary collapse
-
#cib_section_constraint_rules(constraint) ⇒ Array<REXML::Element>
get all rule elements from the constraint element.
-
#cib_section_constraints ⇒ Array<REXML::Element>
get all ‘rsc_location’, ‘rsc_order’ and ‘rsc_colocation’ sections from CIB.
-
#constraint_exists?(id) ⇒ TrueClass, FalseClass
check if a constraint exists.
-
#constraints(type = nil) ⇒ Hash<String => Hash>
constraints found in the CIB filter them by the provided tag name.
-
#decode_constraint(element) ⇒ Hash<String => String>
decode a single constraint element to the data structure.
-
#decode_constraint_rules(element) ⇒ Hash<String => Hash>
parse constraint rule elements to the rule structure.
Instance Method Details
#cib_section_constraint_rules(constraint) ⇒ Array<REXML::Element>
get all rule elements from the constraint element
15 16 17 18 |
# File 'lib/pacemaker/xml/constraints.rb', line 15 def cib_section_constraint_rules(constraint) return unless constraint.is_a? REXML::Element REXML::XPath.match constraint, 'rule' end |
#cib_section_constraints ⇒ Array<REXML::Element>
get all ‘rsc_location’, ‘rsc_order’ and ‘rsc_colocation’ sections from CIB
9 10 11 |
# File 'lib/pacemaker/xml/constraints.rb', line 9 def cib_section_constraints REXML::XPath.match cib, '//constraints/*' end |
#constraint_exists?(id) ⇒ TrueClass, FalseClass
check if a constraint exists
73 74 75 |
# File 'lib/pacemaker/xml/constraints.rb', line 73 def constraint_exists?(id) constraints.key? id end |
#constraints(type = nil) ⇒ Hash<String => Hash>
constraints found in the CIB filter them by the provided tag name
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pacemaker/xml/constraints.rb', line 57 def constraints(type = nil) constraints = {} cib_section_constraints.each do |constraint| constraint_structure = decode_constraint constraint next unless constraint_structure next unless constraint_structure['id'] next if type && !(constraint_structure['type'] == type) constraint_structure.delete 'type' constraints.store constraint_structure['id'], constraint_structure end constraints end |
#decode_constraint(element) ⇒ Hash<String => String>
decode a single constraint element to the data structure
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pacemaker/xml/constraints.rb', line 40 def decode_constraint(element) return unless element.is_a? REXML::Element return unless element.attributes['id'] return unless element.name constraint_structure = attributes_to_hash element constraint_structure.store 'type', element.name rules = decode_constraint_rules element constraint_structure.store 'rules', rules if rules.any? constraint_structure end |
#decode_constraint_rules(element) ⇒ Hash<String => Hash>
parse constraint rule elements to the rule structure
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pacemaker/xml/constraints.rb', line 23 def decode_constraint_rules(element) rules = cib_section_constraint_rules element return [] unless rules.any? rules_array = [] rules.each do |rule| rule_structure = attributes_to_hash rule next unless rule_structure['id'] rule_expressions = children_elements_to_array rule, 'expression' rule_structure.store 'expressions', rule_expressions if rule_expressions rules_array << rule_structure end rules_array.sort_by { |rule| rule['id'] } end |