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.
New Feature: ha_crm_group type and provider
- Loading branch information
Aimon Bustardo
committed
Oct 20, 2012
1 parent
9b4d88a
commit 0c4bdc0
Showing
2 changed files
with
77 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,46 @@ | ||
require 'rexml/document' | ||
|
||
Puppet::Type.type(:ha_crm_group).provide(:crm) do | ||
|
||
commands :crm => "crm" | ||
commands :crm_resource => "crm_resource" | ||
|
||
def create | ||
with_rsc = resource[:resources] | ||
|
||
crm "-F", "configure", "group", resource[:id], with_rsc | ||
end | ||
|
||
def destroy | ||
crm "-F", "configure", "delete", resource[:id] | ||
end | ||
|
||
def target_role | ||
cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml") | ||
nvpair = REXML::XPath.first(cib, "//cib/configuration/resources/group[@id='#{resource[:id]}']/meta_attributes/nvpair[@name='target-role']") | ||
if nvpair.nil? | ||
:absent | ||
else | ||
nvpair.attribute(:value).value | ||
end | ||
end | ||
|
||
def target_role=(value) | ||
if value == :absent | ||
crm_resource "-m", "-r", resource[:id], "-d", "target-role" | ||
else | ||
crm_resource "-m", "-r", resource[:id], "-p", "target-role", "-v", value.to_s.capitalize | ||
end | ||
end | ||
|
||
def exists? | ||
cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml") | ||
colocation = REXML::XPath.first(cib, "//group[@id='#{resource[:id]}']") | ||
|
||
if colocation | ||
true | ||
else | ||
false | ||
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,31 @@ | ||
Puppet::Type.newtype(:ha_crm_group) do | ||
@desc = "Manages Pacemaker resource groups." | ||
|
||
ensurable | ||
|
||
newparam(:id) do | ||
desc "A unique name for the group" | ||
|
||
isnamevar | ||
end | ||
|
||
newparam(:resources) do | ||
desc "Array of resources to group. They will be started in the order they are ordered in the array." | ||
end | ||
|
||
newproperty(:target_role) do | ||
desc "What state should the cluster attempt to keep this resource in? | ||
Allowed values: | ||
* stopped - Force the resource not to run | ||
* started - Allow the resource to be started | ||
* master - Allow the resource to be started and promoted to Master" | ||
|
||
newvalues(:absent, :stopped, :started, :master) | ||
defaultto :absent | ||
end | ||
|
||
validate do | ||
raise Puppet::Error, "You must specify a list of resources" unless @parameters.include?(:resources) | ||
end | ||
end |