Skip to content

Instantly share code, notes, and snippets.

@domcleal
Created May 28, 2011 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domcleal/996986 to your computer and use it in GitHub Desktop.
Save domcleal/996986 to your computer and use it in GitHub Desktop.
puppet-pacemaker ha_crm_property provider, using lazy_pip style
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