class Arborist::Node::Resource
A node type for Arborist
trees that represent arbitrary resources of a host.
Public Class Methods
new( identifier, host, attributes={}, &block )
click to toggle source
Create a new Resource
node.
Calls superclass method
Arborist::Node::new
# File lib/arborist/node/resource.rb, line 15 def initialize( identifier, host, attributes={}, &block ) raise Arborist::NodeError, "no host given" unless host.is_a?( Arborist::Node::Host ) qualified_identifier = "%s-%s" % [ host.identifier, identifier ] @host = host attributes[ :category ] ||= identifier super( qualified_identifier, host, attributes, &block ) end
Public Instance Methods
addresses()
click to toggle source
Delegate the resources's address to its host.
# File lib/arborist/node/resource.rb, line 60 def addresses return @host.addresses end
category( new_category=nil )
click to toggle source
Get/set the resource category.
# File lib/arborist/node/resource.rb, line 53 def category( new_category=nil ) return @category unless new_category @category = new_category end
family()
click to toggle source
Return the node family, so observers can know ancestry after serialization for custom node types that inherit from this class.
# File lib/arborist/node/resource.rb, line 28 def family return :resource end
hostname()
click to toggle source
Delegate the resource's hostname to it's parent host.
# File lib/arborist/node/resource.rb, line 66 def hostname return @host.hostname end
match_criteria?( key, val )
click to toggle source
Returns true
if the node matches the specified key
and val
criteria.
Calls superclass method
Arborist::Node#match_criteria?
# File lib/arborist/node/resource.rb, line 89 def match_criteria?( key, val ) self.log.debug "Matching %p: %p against %p" % [ key, val, self ] return case key when 'address' search_addr = IPAddr.new( val ) self.addresses.any? {|a| search_addr.include?(a) } when 'category' Array( val ).include?( self.category ) else super end end
modify( attributes )
click to toggle source
Set service attributes
.
Calls superclass method
Arborist::Node#modify
# File lib/arborist/node/resource.rb, line 34 def modify( attributes ) attributes = stringify_keys( attributes ) super self.category( attributes['category'] ) end
operational_values()
click to toggle source
Return a Hash of the operational values that are included with the node's monitor state.
Calls superclass method
Arborist::Node#operational_values
# File lib/arborist/node/resource.rb, line 43 def operational_values return super.merge( addresses: self.addresses.map( &:to_s ), hostname: self.hostname, category: self.category ) end
parent( new_parent=nil )
click to toggle source
Overridden to disallow modification of a Resource
parent, as it needs a reference to the Host node for delegation.
Calls superclass method
Arborist::Node#parent
# File lib/arborist/node/resource.rb, line 73 def parent( new_parent=nil ) return super unless new_parent raise "Can't reparent a resource; replace the node instead" end
to_h( * )
click to toggle source
Serialize the resource node. Return a Hash of the host node's state.
Calls superclass method
Arborist::Node#to_h
# File lib/arborist/node/resource.rb, line 80 def to_h( * ) return super.merge( addresses: self.addresses.map( &:to_s ), category: self.category ) end