extract meta attribute handling to Pacemaker::Resource::Meta mixin

This commit is contained in:
Adam Spiers 2014-02-06 18:32:56 +00:00
parent ac1f930681
commit daf3022e96
2 changed files with 32 additions and 14 deletions

View File

@ -0,0 +1,28 @@
# A mixin for Pacemaker::Resource subclasses which support meta attributes
# (priority, target-role, is-managed)
module Pacemaker
class Resource
module Meta
def self.included(base)
base.extend ClassMethods
end
attr_accessor :meta
def meta_string
self.class.meta_string(meta)
end
module ClassMethods
def meta_string(meta)
return "" if ! meta or meta.empty?
"meta " +
meta.sort.map do |key, value|
%'#{key}="#{value}"'
end.join(' ')
end
end
end
end
end

View File

@ -1,12 +1,14 @@
require 'shellwords'
require File.expand_path('../resource', File.dirname(__FILE__))
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__))
class Pacemaker::Resource::Primitive < Pacemaker::Resource
TYPE = 'primitive'
register_type TYPE
attr_accessor :agent, :params, :meta, :op
include Pacemaker::Resource::Meta
attr_accessor :agent, :params, :op
def initialize(*args)
super(*args)
@ -43,10 +45,6 @@ class Pacemaker::Resource::Primitive < Pacemaker::Resource
self.class.params_string(params)
end
def meta_string
self.class.meta_string(meta)
end
def op_string
self.class.op_string(op)
end
@ -78,14 +76,6 @@ class Pacemaker::Resource::Primitive < Pacemaker::Resource
end.join(' ')
end
def self.meta_string(meta)
return "" if ! meta or meta.empty?
"meta " +
meta.sort.map do |key, value|
%'#{key}="#{value}"'
end.join(' ')
end
def self.op_string(ops)
return "" if ! ops or ops.empty?
ops.sort.map do |op, attrs|