Class: Rundock::Node

Inherits:
Object show all
Defined in:
lib/rundock/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, backend) ⇒ Node

Returns a new instance of Node.



10
11
12
13
14
15
# File 'lib/rundock/node.rb', line 10

def initialize(name, backend)
  @name = name
  @backend = backend
  @operations = []
  @hooks = []
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



7
8
9
# File 'lib/rundock/node.rb', line 7

def backend
  @backend
end

#hooksObject

Returns the value of attribute hooks.



8
9
10
# File 'lib/rundock/node.rb', line 8

def hooks
  @hooks
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/rundock/node.rb', line 5

def name
  @name
end

#operationsObject (readonly)

Returns the value of attribute operations.



6
7
8
# File 'lib/rundock/node.rb', line 6

def operations
  @operations
end

Instance Method Details

#add_operation(ope) ⇒ Object



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

def add_operation(ope)
  @operations ||= []
  @operations << ope
end

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rundock/node.rb', line 22

def run
  Logger.formatter.on_rec
  Logger.debug("run node: #{@name}")
  Logger.warn("no operation running: #{@name}") if @operations.blank?

  node_attributes = []

  @operations.each do |ope|
    Logger.debug("run operation: #{ope.class}")
    node_attributes << ope.attributes
    ope.attributes[:nodename] = @name
    ope.run(@backend, ope.attributes)
  end

  log_buffer = Logger.formatter.flush unless Logger.formatter.buffer.empty?

  @hooks.each do |h|
    Logger.debug("run hook: #{h.name}")
    h.hook(node_attributes, log_buffer)
  end

  Logger.formatter.off_rec
end