Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

New Feature: ha_crm_group type and provider #1

Open
wants to merge 2 commits into from

1 participant

Aimon Bustardo
Aimon Bustardo

This addition works well... only shortcoming that I know of is that it won't edit an existing group... Will add that functionality at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Oct 20, 2012
Aimon Bustardo aimonb New Feature: ha_crm_group type and provider 0c4bdc0
Aimon Bustardo aimonb Using the cib.xml means you are often behind reality. Instead save th…
…e cib to std out and grab with and Document.new
4b9bbfd
This page is out of date. Refresh to see the latest.
46 lib/puppet/provider/ha_crm_group/crm.rb
... ... @@ -0,0 +1,46 @@
  1 +require 'rexml/document'
  2 +
  3 +Puppet::Type.type(:ha_crm_group).provide(:crm) do
  4 +
  5 + commands :crm => "crm"
  6 + commands :crm_resource => "crm_resource"
  7 +
  8 + def create
  9 + with_rsc = resource[:resources]
  10 +
  11 + crm "-F", "configure", "group", resource[:id], with_rsc
  12 + end
  13 +
  14 + def destroy
  15 + crm "-F", "configure", "delete", resource[:id]
  16 + end
  17 +
  18 + def target_role
  19 + cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
  20 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/group[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='target-role']")
  21 + if nvpair.nil?
  22 + :absent
  23 + else
  24 + nvpair.attribute(:value).value
  25 + end
  26 + end
  27 +
  28 + def target_role=(value)
  29 + if value == :absent
  30 + crm_resource "-m", "-r", resource[:id], "-d", "target-role"
  31 + else
  32 + crm_resource "-m", "-r", resource[:id], "-p", "target-role", "-v", value.to_s.capitalize
  33 + end
  34 + end
  35 +
  36 + def exists?
  37 + cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
  38 + colocation = REXML::XPath.first(cib, "//group[@id='#{resource[:id]}']")
  39 +
  40 + if colocation
  41 + true
  42 + else
  43 + false
  44 + end
  45 + end
  46 +end
104 lib/puppet/provider/ha_crm_order/crm.rb
... ... @@ -1,57 +1,103 @@
1 1 require 'rexml/document'
2 2
3   -Puppet::Type.type(:ha_crm_colocation).provide(:crm) do
  3 +Puppet::Type.type(:ha_crm_order).provide(:crm) do
4 4
5 5 commands :crm => "crm"
6 6
7   - def create
8   - if resource[:first_action]
9   - first_rsc = "#{resource[:first]}:#{resource[:first_action]}"
  7 + def lensure
  8 + return resource[:ensure]
  9 + end
  10 +
  11 + def id
  12 + return resource[:id]
  13 + end
  14 +
  15 + def first
  16 + return resource[:first]
  17 + end
  18 +
  19 + def first_action
  20 + return resource[:first_action]
  21 + end
  22 +
  23 + def lthen
  24 + return resource[:then]
  25 + end
  26 +
  27 + def then_action
  28 + return resource[:then_action]
  29 + end
  30 +
  31 + def score
  32 + return resource[:score]
  33 + end
  34 +
  35 + def symmetrical
  36 + return resource[:symmetrical]
  37 + end
  38 +
  39 + def only_run_on_dc
  40 + return resource[:only_run_on_dc]
  41 + end
  42 +
  43 + def create
  44 + if first_action
  45 + first_rsc = "#{first}:#{first_action}"
10 46 else
11   - first_rsc = resource[:first]
  47 + first_rsc = first
12 48 end
13 49
14   - if resource[:then_action]
15   - then_rsc = "#{resource[:then]}:#{resource[:then_action]}"
  50 + if then_action
  51 + then_rsc = "#{lthen}:#{then_action}"
16 52 else
17   - then_rsc = resource[:then]
  53 + then_rsc = lthen
18 54 end
19   -
20   - crm "-F", "configure", "order", resource[:id], "#{resource[:score]}:", first_rsc, then_rsc, "symmetrical=#{resource[:symmetrical].to_s}"
  55 + begin
  56 + crm "-F", "configure", "delete", id
  57 + rescue
  58 + # Already deleted
  59 + end
  60 + crm "-F", "configure", "order", id, "#{score}:", first_rsc, then_rsc, "symmetrical=#{symmetrical.to_s}"
21 61 end
22 62
23 63 def destroy
24   - crm "-F", "configure", "delete", resource[:id]
  64 + crm "-F", "configure", "delete", id
25 65 end
26 66
27 67 def exists?
28   - if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
29   - resource[:ensure] == :present ? true : false
  68 + if only_run_on_dc and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
  69 + lensure == :present ? true : false
30 70 else
31   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
32   - colocation = REXML::XPath.first(cib, "//rsc_order[@id='#{resource[:id]}']")
  71 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  72 + rsc_order = REXML::XPath.first(cib, "//rsc_order[@id='#{id}']")
  73 +
  74 + return false if not rsc_order
33 75
34   - if resource[:first_action]
35   - if colocation.attribute("first-action").value != resource[:first_action]
36   - false
  76 + if first_action
  77 + if rsc_order.attribute(:first-action).value != first_action
  78 + return false
37 79 end
38 80 end
39 81
40   - if resource[:then_action]
41   - if colocation.attribute("then-action").value != resource[:then_action]
42   - false
  82 + if then_action
  83 + if rsc_order.attribute(:then-action).value != then_action
  84 + return false
43 85 end
44 86 end
45   -
46   - if colocation.attribute(:first).value != resource[:first]
47   - false
48   - elsif colocation.attribute(:then).value != resource[:then]
49   - false
50   - elsif colocation.attribute(:score).value != resource[:score]
51   - false
  87 + #We use crm directly now so need to convert inf to INFINITY for the match
  88 + if score == :inf
  89 + score = 'INFINITY'
  90 + end
  91 + if rsc_order.attribute(:first).value.downcase != first.downcase
  92 + return false
  93 + elsif rsc_order.attribute(:then).value.downcase != lthen.downcase
  94 + return false
  95 + elsif rsc_order.attribute(:score).value.downcase != score.downcase
  96 + return false
52 97 else
53   - true
  98 + return true
54 99 end
  100 + return true
55 101 end
56 102 end
57 103 end
62 lib/puppet/provider/ha_crm_primitive/crm.rb
@@ -3,24 +3,40 @@
3 3 Puppet::Type.type(:ha_crm_primitive).provide(:crm) do
4 4 desc "CRM shell support"
5 5
6   - commands :crm => "crm"
7   - commands :crm_resource => "crm_resource"
8   -
9   - def create
10   - crm "-F", "configure", "primitive", resource[:id], resource[:type]
  6 + commands :crm => "crm", :crm_resource => "crm_resource"
  7 +
  8 + def ops
  9 + return resource[:ops]
  10 + end
  11 +
  12 + def create
  13 + if ops
  14 + a_ops=[]
  15 + ops.split(',').each do |this_op|
  16 + a_ops << "op #{this_op} "
  17 + end
  18 + end
  19 + crm "-F", "configure", "primitive", resource[:id], resource[:type], *a_ops
11 20 end
12 21
13 22 def destroy
14   - crm "-F", "configure", "delete", resource[:id]
  23 + crm "-F", "resource", "stop", resource[:id]
  24 + crm "-F", "resource", "cleanup", resource[:id]
  25 + sleep 5
  26 + crm "-F", "configure", "delete", resource[:id]
15 27 end
16 28
17 29 def exists?
18 30 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
19 31 resource[:ensure] == :present ? true : false
20 32 else
21   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
22   - primitive = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']")
23   - !primitive.nil?
  33 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  34 + primitive = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']")
  35 + if primitive.nil?
  36 + false
  37 + else
  38 + true
  39 + end
24 40 end
25 41 end
26 42
@@ -28,8 +44,8 @@ def priority
28 44 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
29 45 resource[:priority]
30 46 else
31   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
32   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='priority']")
  47 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  48 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='priority']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='priority']")
33 49 if nvpair.nil?
34 50 :absent
35 51 else
@@ -50,8 +66,8 @@ def target_role
50 66 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
51 67 resource[:target_role]
52 68 else
53   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
54   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='target-role']")
  69 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  70 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='target-role']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='target-role']")
55 71 if nvpair.nil?
56 72 :absent
57 73 else
@@ -72,8 +88,8 @@ def is_managed
72 88 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
73 89 resource[:is_managed]
74 90 else
75   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
76   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='is-managed']")
  91 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  92 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='is-managed']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='is-managed']")
77 93 if nvpair.nil?
78 94 :absent
79 95 else
@@ -94,8 +110,8 @@ def resource_stickiness
94 110 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
95 111 resource[:resource_stickiness]
96 112 else
97   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
98   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='resource-stickiness']")
  113 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  114 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='resource-stickiness']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='resource-stickiness']")
99 115 if nvpair.nil?
100 116 :absent
101 117 else
@@ -116,8 +132,8 @@ def migration_threshold
116 132 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
117 133 resource[:migration_threshold]
118 134 else
119   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
120   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='migration-threshold']")
  135 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  136 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='migration-threshold']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='migration-threshold']")
121 137 if nvpair.nil?
122 138 :absent
123 139 else
@@ -138,8 +154,8 @@ def failure_timeout
138 154 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
139 155 resource[:failure_timeout]
140 156 else
141   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
142   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='failure-timeout']")
  157 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  158 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='failure-timeout']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='failure-timeout']")
143 159 if nvpair.nil?
144 160 :absent
145 161 else
@@ -160,8 +176,8 @@ def multiple_active
160 176 if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)
161 177 resource[:multiple_active]
162 178 else
163   - cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml")
164   - nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='multiple-active']")
  179 + cib = REXML::Document.new `/usr/sbin/crm configure save xml -`
  180 + nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/*/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='multiple-active']") || REXML::XPath.first(cib, "//cib/configuration/resources/primitive[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='multiple-active']")
165 181 if nvpair.nil?
166 182 :absent
167 183 else
31 lib/puppet/type/ha_crm_group.rb
... ... @@ -0,0 +1,31 @@
  1 +Puppet::Type.newtype(:ha_crm_group) do
  2 + @desc = "Manages Pacemaker resource groups."
  3 +
  4 + ensurable
  5 +
  6 + newparam(:id) do
  7 + desc "A unique name for the group"
  8 +
  9 + isnamevar
  10 + end
  11 +
  12 + newparam(:resources) do
  13 + desc "Array of resources to group. They will be started in the order they are ordered in the array."
  14 + end
  15 +
  16 + newproperty(:target_role) do
  17 + desc "What state should the cluster attempt to keep this resource in?
  18 +
  19 + Allowed values:
  20 + * stopped - Force the resource not to run
  21 + * started - Allow the resource to be started
  22 + * master - Allow the resource to be started and promoted to Master"
  23 +
  24 + newvalues(:absent, :stopped, :started, :master)
  25 + defaultto :absent
  26 + end
  27 +
  28 + validate do
  29 + raise Puppet::Error, "You must specify a list of resources" unless @parameters.include?(:resources)
  30 + end
  31 +end
10 lib/puppet/type/ha_crm_order.rb
@@ -50,9 +50,9 @@
50 50 defaultto(:true)
51 51 end
52 52
53   - validate do
54   - raise Puppet::Error, "You must specify a first resource (first)" unless @parameters.include?(:first)
55   - raise Puppet::Error, "You must specify a second resource (then)" unless @parameters.include(:then)
56   - raise Puppet::Error, "You must specify a score" unless @parameters.include?(:score)
57   - end
  53 + #validate do
  54 + # defined? @parameters['first'] or raise Puppet::Error, "You must specify a first resource (first)"
  55 + # defined? @parameters['then'] or raise Puppet::Error, "You must specify a second resource (then)"
  56 + # defined? @parameters['has_key'] or raise Puppet::Error, "You must specify a score"
  57 + #end
58 58 end
6 lib/puppet/type/ha_crm_primitive.rb
@@ -92,6 +92,12 @@
92 92 newvalues(:absent, :block, :stop_only, :stop_start)
93 93 defaultto :absent
94 94 end
  95 +
  96 + newproperty(:ops) do
  97 + desc "Array of 'op' parameters.
  98 + Example: ['stop interval=\"0\" timeout=\"30s\"', 'start interval=\"0\" timeout=\"30s\"']"
  99 + defaultto(:false)
  100 + end
95 101
96 102 validate do
97 103 raise Puppet::Error, "You must specify a type for this primitive" unless @parameters.include?(:type)
2  manifests/crm/primitive.pp
... ... @@ -1,4 +1,4 @@
1   -define ha::crm::primitive($resource_type, $ensure=present, $monitor_interval, $ignore_dc="false"
  1 +define ha::crm::primitive($resource_type, $ensure=present, $monitor_interval, $ignore_dc="false",
2 2 $priority="", $target_role="", $is_managed="", $resource_stickiness="", $migration_threshold="",
3 3 $failure_timeout="", $multiple_active="") {
4 4
4 manifests/init.pp
... ... @@ -1,7 +1,7 @@
1   -import "primitive.pp"
  1 +import "crm/primitive.pp"
2 2 import "stonith.pp"
3 3 import "ip.pp"
4   -
  4 +class ha(){}
5 5 define ha::authkey($method, $key="") {
6 6 if($method == "crc") {
7 7 $changes = ["set ${name}/method ${method}"]

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.