Created
May 28, 2011 16:08
-
-
Save domcleal/996986 to your computer and use it in GitHub Desktop.
puppet-pacemaker ha_crm_property provider, using lazy_pip style
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
require 'rexml/document' | |
Puppet::Type.type(:ha_crm_property).provide(:crm) do | |
def create | |
lazy_crm_attribute "-t", "crm_config", "-n", resource[:name], "-v", resource[:value] | |
end | |
def destroy | |
lazy_crm_attribute "-t", "crm_config", "-n", resource[:name], "-D" | |
end | |
def exists? | |
if (resource[:only_run_on_dc] == :true) and (Facter.value(:ha_cluster_dc) != Facter.value(:fqdn)) | |
true | |
else | |
cib = REXML::Document.new File.open("/var/lib/heartbeat/crm/cib.xml") | |
property = REXML::XPath.first(cib, "/cib/configuration/crm_config/cluster_property_set/nvpair[@name='#{resource[:name]}']") | |
if property.nil? | |
false | |
else | |
property.attribute(:value).value == resource[:value] ? true : false | |
end | |
end | |
end | |
private | |
def lazy_crm_attribute(*args) | |
crm_attribute *args | |
rescue NoMethodError => e | |
if pathname = which('crm_attribute') | |
self.class.commands :crm_attribute => pathname | |
crm_attribute *args | |
else | |
raise e | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment