Host

class
Superclass
Arborist::Node
Included Modules
Arborist::NetworkUtilities

A node type for Arborist trees that represent network-connected hosts.

host_node = Arborist::Node.create( :host, 'acme' ) do
    description "Public-facing webserver"
    address '93.184.216.34'

    tags :public, :dmz

    resource 'disk'
    resource 'memory' do
        config hwm: '3.4G'
    end
    resource 'loadavg'
    resource 'processes' do
        config expect: { nginx: 2 }
    end

    service 'ssh'
    service 'www'

end

Attributes

addresses[R]

The network address(es) of this Host as an Array of IPAddr objects

Public Class Methods

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

Create a new Host node.

# File lib/arborist/node/host.rb, line 36
def initialize( identifier, attributes={}, &block )
        @addresses = []
        @hostname = nil
        super
end

Public Instance Methods

anchor
==( other_host )

Equality operator – returns true if other_node is equal to the receiver. Overridden to also compare addresses.

# File lib/arborist/node/host.rb, line 140
def ==( other_host )
        return super &&
                other_host.addresses == self.addresses &&
                other_host.hostname == @hostname
end
anchor
address( new_address )

Set an IP address of the host.

# File lib/arborist/node/host.rb, line 84
def address( new_address )
        self.log.debug "Adding address %p to %p" % [ new_address, self ]

        if new_address =~ /^[[:alnum:]][a-z0-9\-]+/i && ! @hostname
                @hostname = new_address
        end

        @addresses += normalize_address( new_address )
        @addresses.uniq!
end
anchor
hostname()

An optional hostname.

# File lib/arborist/node/host.rb, line 53
dsl_accessor :hostname
anchor
marshal_load( hash )

Marshal API – set up the object's state using the hash from a previously-marshalled node. Overridden to turn the addresses back into IPAddr objects.

# File lib/arborist/node/host.rb, line 131
def marshal_load( hash )
        super
        @addresses = hash[:addresses].map {|addr| IPAddr.new(addr) }
        @hostname = hash[:hostname]
end
anchor
match_criteria?( key, val )

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

# File lib/arborist/node/host.rb, line 97
def match_criteria?( key, val )
        return case key
                when 'hostname' then @hostname == val
                when 'address'
                        search_addr = IPAddr.new( val )
                        @addresses.any? {|a| search_addr.include?(a) }
                else
                        super
                end
end
anchor
modify( attributes )

Set one or more node attributes. Supported attributes (in addition to those supported by Node) are: addresses.

# File lib/arborist/node/host.rb, line 58
def modify( attributes )
        attributes = stringify_keys( attributes )

        super

        self.hostname( attributes['hostname'] ) if attributes[ 'hostname' ]
        if attributes[ 'addresses' ]
                self.addresses.clear
                Array( attributes['addresses'] ).each do |addr|
                        self.address( addr )
                end
        end
end
anchor
node_description()

Return host-node-specific information for inspect.

# File lib/arborist/node/host.rb, line 110
def node_description
        return "{no addresses}" if self.addresses.empty?
        return "{addresses: %s}" % [ self.addresses.map(&:to_s).join(', ') ]
end
anchor
operational_values()

Return the host's operational attributes.

# File lib/arborist/node/host.rb, line 74
def operational_values
        properties = super
        return properties.merge(
                hostname: @hostname,
                addresses: self.addresses.map(&:to_s)
        )
end
anchor
to_h( * )

Return a Hash of the host node's state.

# File lib/arborist/node/host.rb, line 121
def to_h( * )
        return super.merge(
                hostname:  @hostname,
                addresses: self.addresses.map(&:to_s)
        )
end