Adam Spiers 3bb5d93b80 add FIXMEs for full grammar parsing
@tserong will probably have to fix these if he wants to incorporate this
class hierarchy into Hawk ;-) But of course we'd first need to split it
off into a separate gem (which should be easy - I've deliberately kept
the code fairly cleanly separated).
2014-03-21 17:25:59 +00:00

35 lines
951 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
# FIXME: this is incomplete. It probably doesn't handle resource
# sets correctly, and certainly doesn't handle node attributes.
# See the crm(8) man page for the official BNF grammar.
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