Sha256: 6b63543ae26b01792077ff5d071f856186b0c2a1c7c8af6c162956e09fcc09ad

Contents?: true

Size: 1.13 KB

Versions: 2

Compression:

Stored size: 1.13 KB

Contents

require 'rundock'

module Rundock
  class Node
    attr_reader :name
    attr_reader :operations
    attr_reader :backend
    attr_accessor :hooks

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

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

    def complete(scenario)
      @operations.each do |ope|
        ope.attributes[:nodeinfo].merge!(scenario.node_info)
      end
    end

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

      nodeinfo = nil

      @operations.each do |ope|
        Logger.debug("run operation: #{ope.class}")
        nodeinfo = ope.attributes[:nodeinfo] if nodeinfo.nil?
        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(log_buffer, nodeinfo)
      end

      Logger.formatter.onrec = false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rundock-0.4.2 lib/rundock/node.rb
rundock-0.4.1 lib/rundock/node.rb