Resource

class
Superclass
Arborist::Node

A node type for Arborist trees that represent arbitrary resources of a host.

Public Class Methods

anchor
new( identifier, host, attributes={}, &block )

Create a new Resource node.

# 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

anchor
addresses()

Delegate the resources's address to its host.

# File lib/arborist/node/resource.rb, line 53
def addresses
        return @host.addresses
end
anchor
category( new_category=nil )

Get/set the resource category.

# File lib/arborist/node/resource.rb, line 46
def category( new_category=nil )
        return @category unless new_category
        @category = new_category
end
anchor
hostname()

Delegate the resource's hostname to it's parent host.

# File lib/arborist/node/resource.rb, line 59
def hostname
        return @host.hostname
end
anchor
match_criteria?( key, val )

Returns true if the node matches the specified key and val criteria.

# File lib/arborist/node/resource.rb, line 82
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
anchor
modify( attributes )

Set service attributes.

# File lib/arborist/node/resource.rb, line 27
def modify( attributes )
        attributes = stringify_keys( attributes )
        super
        self.category( attributes['category'] )
end
anchor
operational_values()

Return a Hash of the operational values that are included with the node's monitor state.

# File lib/arborist/node/resource.rb, line 36
def operational_values
        return super.merge(
                addresses: self.addresses.map( &:to_s ),
                hostname: self.hostname,
                category: self.category
        )
end
anchor
parent( new_parent=nil )

Overridden to disallow modification of a Resource parent, as it needs a reference to the Host node for delegation.

# File lib/arborist/node/resource.rb, line 66
def parent( new_parent=nil )
        return super unless new_parent
        raise "Can't reparent a resource; replace the node instead"
end
anchor
to_h( * )

Serialize the resource node. Return a Hash of the host node's state.

# File lib/arborist/node/resource.rb, line 73
def to_h( * )
        return super.merge(
                addresses: self.addresses.map( &:to_s ),
                category: self.category
        )
end