class Gusteau::Node

Attributes

config[R]
name[R]
server[R]

Public Class Methods

new(node_name, node_config) click to toggle source
# File lib/gusteau/node.rb, line 9
def initialize(node_name, node_config)
  @name   = node_name
  @config = node_config

  @server = Server.new(@config['server'])
  @dna_path = '/tmp/dna.json'
end

Public Instance Methods

apply(run_list, opts = {}) click to toggle source
# File lib/gusteau/node.rb, line 27
def apply(run_list, opts = {})
  with_hooks do
    server.chef.run dna(run_list), opts
  end
end
converge(opts = {}) click to toggle source
# File lib/gusteau/node.rb, line 21
def converge(opts = {})
  with_hooks do
    server.chef.run dna, opts
  end
end
ssh() click to toggle source
# File lib/gusteau/node.rb, line 33
def ssh
  server.ssh
end
to_s() click to toggle source
# File lib/gusteau/node.rb, line 17
def to_s
  "#{name} (#{@server})"
end

Private Instance Methods

dna(run_list = nil) click to toggle source
# File lib/gusteau/node.rb, line 55
def dna(run_list = nil)
  node_dna = {
    :path => @dna_path,
    :hash => {
      :instance_role => @name,
      :run_list      => run_list || @config['run_list']
    }.merge(@config['attributes'] || {})
  }

  File.open(node_dna[:path], 'w+') { |f| f.puts node_dna[:hash].to_json }
  node_dna
end
hook(hook_type) click to toggle source
# File lib/gusteau/node.rb, line 45
def hook(hook_type)
  (@config[hook_type] || []).each do |cmd|
    Kernel.system({ 'GUSTEAU_NODE' => name }, cmd)
    unless $?.exitstatus == 0
      log_error "Error executing a #{hook_type} hook: '#{cmd}'"
      exit 1
    end
  end
end
with_hooks() { || ... } click to toggle source
# File lib/gusteau/node.rb, line 39
def with_hooks(&block)
  hook 'before'
  yield
  hook 'after'
end