forked from rodjek/puppet-pacemaker
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'rexml/document' | ||
|
||
Puppet::Type.type(:ha_crm_location).provide(:crm) do | ||
|
||
commands :crm => "crm" | ||
|
||
def create | ||
if resource[:rule] | ||
loc = "rule #{resource[:score]}: #{resource[:rule]}" | ||
else | ||
loc = "#{resource[:score]}: #{resource[:node]}" | ||
end | ||
|
||
crm "-F", "configure", "location", resource[:id], resource[:resource], loc | ||
end | ||
|
||
def destroy | ||
crm "-F", "configure", "delete", resource[:id] | ||
end | ||
|
||
def exists? | ||
if resource[:only_run_on_dc] and Facter.value(:ha_cluster_dc) != Facter.value(:fqdn) | ||
resource[:ensure] == :present ? true : false | ||
else | ||
cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml") | ||
colocation = REXML::XPath.first(cib, "//rsc_location[@id='#{resource[:id]}']") | ||
|
||
if colocation.nil? | ||
false | ||
else | ||
true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
Puppet::Type.newtype(:ha_crm_location) do | ||
@desc = "Manages Pacemaker resource location constraints." | ||
|
||
ensurable | ||
|
||
newparam(:id) do | ||
desc "A unique name for the order constraint" | ||
|
||
isnamevar | ||
end | ||
|
||
newparam(:resource) do | ||
desc "A resource name" | ||
end | ||
|
||
newparam(:node) do | ||
desc "A node's uname" | ||
end | ||
|
||
newparam(:score) do | ||
desc "Positive values indicate the resource CAN run on this node. | ||
Negative values indicate the resource CAN NOT run on this node. | ||
Values of +/i infinity (inf) change CAN to MUST." | ||
end | ||
|
||
newparam(:rule) do | ||
desc "An optional rule string to suppliment the basic location constraint" | ||
end | ||
|
||
newparam(:only_run_on_dc, :boolean => true) do | ||
desc "In order to prevent race conditions, we generally only want to | ||
make changes to the CIB on a single machine (in this case, the | ||
Designated Controller)." | ||
|
||
newvalues(:true, :false) | ||
defaultto(:true) | ||
end | ||
|
||
validate do | ||
raise Puppet::Error, "You must specify a resource" unless @parameters.include?(:resource) | ||
raise Puppet::Error, "You must specify a score" unless @parameters.include?(:score) | ||
if @parameters.include?(:node) and @parameters.include?(:rule) | ||
raise Puppet::Error, "You must specify either a node or a rule, not both." | ||
end | ||
|
||
if !@parameters.include?(:node) and !@parameters.include?(:rule) | ||
raise Puppet::Error, "You must specify either a node or a rule" | ||
end | ||
end | ||
end |