Skip to content

Commit

Permalink
New Feature: ha_crm_group type and provider
Browse files Browse the repository at this point in the history
  • Loading branch information
Aimon Bustardo committed Oct 20, 2012
1 parent 9b4d88a commit 0c4bdc0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/puppet/provider/ha_crm_group/crm.rb
@@ -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
31 changes: 31 additions & 0 deletions lib/puppet/type/ha_crm_group.rb
@@ -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

0 comments on commit 0c4bdc0

Please sign in to comment.