Module: Pacemaker::ConstraintLocations
- Included in:
- Puppet::Provider::PacemakerXML, Serverspec::Type::PacemakerXML
- Defined in:
- lib/pacemaker/xml/constraint_locations.rb
Overview
functions related to locations constraints main structure “constraint_locations”
Instance Method Summary collapse
-
#constraint_location_add(location_structure) ⇒ Object
add a location constraint.
-
#constraint_location_exists?(id) ⇒ TrueClass, FalseClass
check if locations constraint exists.
-
#constraint_location_remove(id) ⇒ Object
remove a location constraint.
-
#constraint_locations ⇒ Hash<String => Hash>
get location constraints and use mnemoization on the list.
-
#service_location_add(primitive, node, score = 100) ⇒ Object
add a location constraint to enable a service on a node.
-
#service_location_exists?(primitive, node) ⇒ true, false
check if service location exists for this primitive on this node.
-
#service_location_name(primitive, node) ⇒ String
construct the constraint unique name from primitive’s and node’s names.
-
#service_location_remove(primitive, node) ⇒ Object
remove the service location on this node.
-
#xml_rsc_location(data) ⇒ REXML::Element
generate rsc_location elements from data structure.
Instance Method Details
#constraint_location_add(location_structure) ⇒ Object
add a location constraint
54 55 56 57 58 59 60 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 54 def constraint_location_add(location_structure) location_patch = xml_document location_element = xml_rsc_location location_structure raise "Could not create XML patch from location '#{location_structure.inspect}'!" unless location_element location_patch.add_element location_element wait_for_constraint_create xml_pretty_format(location_patch.root), location_structure['id'] end |
#constraint_location_exists?(id) ⇒ TrueClass, FalseClass
check if locations constraint exists
71 72 73 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 71 def constraint_location_exists?(id) constraint_locations.key? id end |
#constraint_location_remove(id) ⇒ Object
remove a location constraint
64 65 66 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 64 def constraint_location_remove(id) wait_for_constraint_remove "<rsc_location id='#{id}'/>\n", id end |
#constraint_locations ⇒ Hash<String => Hash>
get location constraints and use mnemoization on the list
47 48 49 50 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 47 def constraint_locations return @locations_structure if @locations_structure @locations_structure = constraints 'rsc_location' end |
#service_location_add(primitive, node, score = 100) ⇒ Object
add a location constraint to enable a service on a node
27 28 29 30 31 32 33 34 35 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 27 def service_location_add(primitive, node, score = 100) location_structure = { 'id' => service_location_name(primitive, node), 'node' => node, 'rsc' => primitive, 'score' => score, } constraint_location_add location_structure end |
#service_location_exists?(primitive, node) ⇒ true, false
check if service location exists for this primitive on this node
18 19 20 21 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 18 def service_location_exists?(primitive, node) id = service_location_name primitive, node constraint_location_exists? id end |
#service_location_name(primitive, node) ⇒ String
construct the constraint unique name from primitive’s and node’s names
10 11 12 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 10 def service_location_name(primitive, node) "#{primitive}-on-#{node}" end |
#service_location_remove(primitive, node) ⇒ Object
remove the service location on this node
40 41 42 43 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 40 def service_location_remove(primitive, node) id = service_location_name primitive, node constraint_location_remove id end |
#xml_rsc_location(data) ⇒ REXML::Element
generate rsc_location elements from data structure
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 |
# File 'lib/pacemaker/xml/constraint_locations.rb', line 78 def xml_rsc_location(data) return unless data && data.is_a?(Hash) # create an element from the top level hash and skip 'rules' attribute # because if should be processed as children elements and useless 'type' attribute rsc_location_element = xml_element 'rsc_location', data, %w(rules type) # there are no rule elements return rsc_location_element unless data['rules'] && data['rules'].respond_to?(:each) # create a rule element with attributes and treat expressions as children elements sort_data(data['rules']).each do |rule| next unless rule.is_a? Hash rule_element = xml_element 'rule', rule, 'expressions' # add expression children elements to the rule element if the are present if rule['expressions'] && rule['expressions'].respond_to?(:each) sort_data(rule['expressions']).each do |expression| next unless expression.is_a? Hash expression_element = xml_element 'expression', expression rule_element.add_element expression_element end end rsc_location_element.add_element rule_element end rsc_location_element end |