class Souffle::Node

A node object that's part of a given system.

A node object that's part of a given system.

Attributes

children[RW]
dependencies[RW]
name[RW]
options[RW]
parents[RW]
provisioner[RW]
run_list[RW]
system[RW]

Public Class Methods

new(parent_multiplier=5) click to toggle source

Creates a new souffle node with bare dependencies and run_list.

@param [ Fixnum ] parent_multiplier The multiplier for parent nodes.

# File lib/souffle/node.rb, line 15
def initialize(parent_multiplier=5)
  @dependencies = Souffle::Node::RunList.new
  @run_list = Souffle::Node::RunList.new
  @parents = []
  @children = []
  @options = {
    :attributes => Hash.new
  }
  @parent_multiplier = parent_multiplier
end

Public Instance Methods

add_child(node) click to toggle source

Adds a child node to the current node.

@param [ Souffle::Node ] node The node to add as a child.

@raise [ InvaidChild ] Children must have dependencies and a run_list.

# File lib/souffle/node.rb, line 55
def add_child(node)
  unless node.respond_to?(:dependencies) && node.respond_to?(:run_list)
    raise Souffle::Exceptions::InvalidChild,
      "Child must act as a Souffle::Node"
  end
  unless @children.include? node
    node.parents << self
    @children.push(node)
  end
end
depends_on?(node) click to toggle source

Check whether or not a given node depends on another node.

@example

n1 = Souffle::Node.new
n2 = Souffle::Node.new

n1.run_list     << "role[dns_server]"
n2.dependencies << "role[dns_server]"
n2.depends_on?(n1)

> [ true, [role[dns_server]] ]

@param [ Souffle::Node ] node Check to see whether this node depends

@return [ Array ] The tuple of [depends_on, dependency_list].

# File lib/souffle/node.rb, line 42
def depends_on?(node)
  dependency_list = []
  @dependencies.each do |d|
    dependency_list << d if node.run_list.include? d
  end
  [dependency_list.any?, dependency_list]
end
domain() click to toggle source

The top-level domain name for the given node.

@return [ String ] The top-level domain name for the given node.

# File lib/souffle/node.rb, line 126
def domain
  try_opt(:domain)
end
each_child() { |child| ... } click to toggle source

Iterator method for children.

@yield [ Souffle::Node,NilClass ] The child node.

# File lib/souffle/node.rb, line 69
def each_child
  @children.each { |child| yield child }
end
eql?(other) click to toggle source

Equality comparator for nodes.

@param [ Souffle::Node ] other The node to compare against.

# File lib/souffle/node.rb, line 76
def eql?(other)
  @dependencies == other.dependencies && @run_list == other.run_list
end
fqdn() click to toggle source

The fully qualified domain name for the given node.

@return [ String ] The fully qualified domain name for the given node.

# File lib/souffle/node.rb, line 133
def fqdn
  [name, tag, domain].compact.join('.')
end
log_prefix() click to toggle source

The logging prefix for the given node.

@return [ String ] The logging prefix for the given node.

# File lib/souffle/node.rb, line 112
def log_prefix
  "[#{tag}: #{name}]"
end
provider() click to toggle source

Returns the current system provider.

@return [ Souffle::Provider::Base ] The current system provider.

# File lib/souffle/node.rb, line 105
def provider
  system.provider
end
tag() click to toggle source

The tag for the given node.

@return [ String ] The tag for the given node.

# File lib/souffle/node.rb, line 119
def tag
  try_opt(:tag)
end
to_hash() click to toggle source

Returns the description of a node in hash format.

@return [ Hash ] The description of a node in hash format.

# File lib/souffle/node.rb, line 140
def to_hash
  {
    :name => @name,
    :options => @options,
    :provisioner => @provisioner,
    :dependencies => @dependencies.to_hash,
    :run_list => @run_list.to_hash
  }
end
try_opt(opt) click to toggle source

Tries to fetch an option parameter otherwise it grabs it from config.

@param [ Symbol ] opt The option to try and fetch.

@return [ String ] The option return value.

# File lib/souffle/node.rb, line 92
def try_opt(opt)
  if system
    options.fetch(opt, system.try_opt(opt))
  else
    options.fetch(opt, Souffle::Config[opt])
  end
rescue
  nil
end
weight() click to toggle source

The dependency weight of a given node.

@return [ Fixnum ] The relative weight of a node used for balancing.

# File lib/souffle/node.rb, line 83
def weight
  @parents.inject(1) { |res, p| res + p.weight * @parent_multiplier }
end