Class: Maestro::Node::Base

Inherits:
Object
  • Object
show all
Includes:
Validator
Defined in:
lib/maestro/node.rb

Overview

A node (i.e. a server, a machine, a vm, a device, etc…) in a cloud.

Direct Known Subclasses

Aws::Elb, Aws::Rds, Configurable

Instance Attribute Summary collapse

Attributes included from Validator

#valid, #validation_errors

Instance Method Summary collapse

Methods included from Validator

#invalidate, #valid?, #validate

Constructor Details

#initialize(name, cloud, &block) ⇒ Base

Creates a new Node

Raises:

  • (StandardError)


27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/maestro/node.rb', line 27

def initialize(name, cloud, &block)
  super()
  raise StandardError, "Node name cannot contain spaces: #{name}" if name.is_a?(String) && !name.index(/\s/).nil?
  @name = name
  @cloud = cloud
  @logger = Log4r::Logger.new(Regexp::quote(@name.to_s))
  outputter = Log4r::StdoutOutputter.new("#{@name.to_s}-stdout")
  outputter.formatter = ConsoleFormatter.new
  @logger.add(outputter)
  init_logs
  instance_eval(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *params) ⇒ Object

:nodoc:



40
41
42
# File 'lib/maestro/node.rb', line 40

def method_missing(name, *params) #:nodoc:
  invalidate "Unexpected attribute: #{name}"
end

Instance Attribute Details

#cloudObject (readonly)

the Cloud this Node is associated with



16
17
18
# File 'lib/maestro/node.rb', line 16

def cloud
  @cloud
end

#hostnameObject

the host name of this Node



18
19
20
# File 'lib/maestro/node.rb', line 18

def hostname
  @hostname
end

#ip_addressObject

the IP address of this Node



20
21
22
# File 'lib/maestro/node.rb', line 20

def ip_address
  @ip_address
end

#log_fileObject (readonly)

String containing the fully qualified path to the log file of this Node



24
25
26
# File 'lib/maestro/node.rb', line 24

def log_file
  @log_file
end

#loggerObject (readonly)

the logger of this Node



22
23
24
# File 'lib/maestro/node.rb', line 22

def logger
  @logger
end

#nameObject (readonly)

the name of this Node



14
15
16
# File 'lib/maestro/node.rb', line 14

def name
  @name
end

Instance Method Details

#disable_stdoutObject

disables the stdout Outputter and only logs to this Node’s log file



45
46
47
48
# File 'lib/maestro/node.rb', line 45

def disable_stdout
  stdoutoutputter = Log4r::Outputter["#{@name.to_s}-stdout"]
  stdoutoutputter.level = Log4r::OFF
end

#enable_stdoutObject

enables the stdout Outputter



51
52
53
54
# File 'lib/maestro/node.rb', line 51

def enable_stdout
  stdoutoutputter = Log4r::Outputter["#{@name.to_s}-stdout"]
  stdoutoutputter.level = Log4r::ALL
end