Files
cookbook-pacemaker/libraries/pacemaker/resource.rb
Adam Spiers c08fb8a3bd use crm --force to ensure start/stop in batch mode
We want to allow a resource X to be created without starting it, and
then for a group/clone Y to be created referencing X, which can
subsequently be started.  This ensures that child resources are only
started via their parent, respecting the constraints their parent needs
to impose (e.g. ordering if the parent is a group).

However in this case, changing target-role on Y causes a "Do you want to
override target-role for child resource ..." interactive prompt.  When
STDIN is not a tty, --force is required to ensure that the target-role
on the child resource.  This only works with newer versions of crm which
are patched according to:

  https://bugzilla.novell.com/show_bug.cgi?id=868697
2014-04-10 21:33:13 +01:00

54 lines
1.6 KiB
Ruby

require 'chef/mixin/shell_out'
require File.expand_path('cib_object', File.dirname(__FILE__))
module Pacemaker
class Resource < Pacemaker::CIBObject
include Chef::Mixin::ShellOut
def self.description
type = self.to_s.split('::').last.downcase
"#{type} resource"
end
def running?
cmd = shell_out! "crm", "resource", "status", name
Chef::Log.info cmd.stdout
!! cmd.stdout.include?("resource #{name} is running")
end
def crm_start_command
"crm --force resource start '#{name}'"
end
def crm_stop_command
"crm --force resource stop '#{name}'"
end
# CIB object definitions look something like:
#
# primitive keystone ocf:openstack:keystone \
# params os_username="crowbar" os_password="crowbar" os_tenant_name="openstack" \
# meta target-role="Started" is-managed="true" \
# op monitor interval="10" timeout=30s \
# op start interval="10s" timeout="240" \
#
# This method extracts a Hash from one of the params / meta / op lines.
def self.extract_hash(obj_definition, data_type)
unless obj_definition =~ /\s+#{data_type} (.+?)\s*\\?$/
return {}
end
h = {}
Shellwords.split($1).each do |kvpair|
break if kvpair == 'op'
unless kvpair =~ /^(.+?)=(.*)$/
raise "Couldn't understand '#{kvpair}' for '#{data_type}' section "\
"of #{name} primitive (definition was [#{obj_definition}])"
end
h[$1] = $2.sub(/^"(.*)"$/, "\1")
end
h
end
end
end