Adam Spiers c0e3907ba0 tidy up requires
It's really ugly to have to keep repeating File.dirname(__FILE__),
so we use a temporary variable, even in the case of a single require.
This minimises long "requires" lines and "requires" statements with
needing line-breaks, and should make search-and-replace a bit easier
if we later want to migrate to __dir__ (Ruby >= 2.0) or require_relative.

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both

I've deliberately rejected the pattern:

  require File.expand_path('../relative/path', __FILE__)

because it relies on inconsistent semantics and inconsistent
documentation in File.expand_path:

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both#comment34147297_4333552
2014-03-25 18:37:50 +00:00

47 lines
1.5 KiB
Ruby

require ::File.expand_path('standard_cib_object', File.dirname(__FILE__))
# Common code used by Pacemaker LWRP providers for resources supporting
# the :run action.
class Chef
module Mixin::Pacemaker
module RunnableResource
include StandardCIBObject
def start_runnable_resource
name = new_resource.name
unless @current_resource
raise "Cannot start non-existent #{cib_object_class.description} '#{name}'"
end
return if @current_cib_object.running?
execute @current_cib_object.crm_start_command do
action :nothing
end.run_action(:run)
new_resource.updated_by_last_action(true)
Chef::Log.info "Successfully started #{@current_cib_object}"
end
def stop_runnable_resource
name = new_resource.name
unless @current_resource
raise "Cannot stop non-existent #{cib_object_class.description} '#{name}'"
end
return unless @current_cib_object.running?
execute @current_cib_object.crm_stop_command do
action :nothing
end.run_action(:run)
new_resource.updated_by_last_action(true)
Chef::Log.info "Successfully stopped #{@current_cib_object}"
end
def delete_runnable_resource
return unless @current_resource
if @current_cib_object.running?
raise "Cannot delete running #{@current_cib_object}"
end
standard_delete_resource
end
end
end
end