
The previous use of require caused File.join on several occasions to calculate different paths to the same library, depending on which __FILE__ the library was being calculated as relative to; e.g. /some/path/prefix/spec/one/bar.rb would do the equivalent of: require '/some/path/prefix/spec/one/../../libraries/foo/mylib.rb' and /some/path/prefix/spec/two/baz.rb would do the equivalent of: require '/some/path/prefix/spec/two/../../libraries/foo/mylib.rb' This would result in mylib.rb being loaded multiple times, causing warnings from constants being redefined, and worse, multiple objects representing the same class hierarchy (@@foo) variables. The latter actually broke the @@subclasses registration mechanism in Pacemaker::CIBObject. By switching to File.expand_path, we ensure we always refer to each library using a single absolute path, which means Ruby's require mechanism works as it should, only loading the code the first time round.
29 lines
614 B
Ruby
29 lines
614 B
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 start_command
|
|
"crm resource start '#{name}'"
|
|
end
|
|
|
|
def stop_command
|
|
"crm resource stop '#{name}'"
|
|
end
|
|
|
|
end
|
|
end
|