Files
cookbook-pacemaker/libraries/pacemaker/constraint/colocation.rb
Adam Spiers 35bc3a4ceb refer to TYPE via self.class to allow inheritance
When referring to TYPE directly, the value is taken from the class in
which the method is defined, but we want it to be taken from the class
for the object being acted on, so we instead use self.class::TYPE to
ensure that methods still work in inherited subclasses.  For example
this means that Pacemaker::Resource::MasterSlave will be able to inherit
from Pacemaker::Resource::Clone.
2014-03-16 10:28:47 +00:00

32 lines
753 B
Ruby

require File.expand_path('../constraint', File.dirname(__FILE__))
class Pacemaker::Constraint::Colocation < Pacemaker::Constraint
TYPE = 'colocation'
register_type TYPE
attr_accessor :score, :resources
def self.attrs_to_copy_from_chef
%w(score resources)
end
def parse_definition
unless definition =~ /^#{self.class::TYPE} (\S+) (\d+|[-+]?inf): (.+?)\s*$/
raise Pacemaker::CIBObject::DefinitionParseError, \
"Couldn't parse definition '#{definition}'"
end
self.name = $1
self.score = $2
self.resources = $3.split
end
def definition_string
"#{self.class::TYPE} #{name} #{score}: " + resources.join(' ')
end
def crm_configure_command
"crm configure " + definition_string
end
end