Class: FlockOfChefs::FlockedReport

Inherits:
Chef::Handler
  • Object
show all
Defined in:
lib/flock_of_chefs/flocked_report.rb

Instance Method Summary collapse

Instance Method Details

#reportObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/flock_of_chefs/flocked_report.rb', line 5

def report
  if(DCell.me.nil?)
    setup_dcell!
  end
  dnode = DCell.me
  if(dnode)
    dnode[:flock_api].node = node.to_hash
    Chef::Log.info 'Node information successfully stored in flock'
  else
    Chef::Log.warn 'Failed to store node information in flock!'
  end
end

#setup_dcell!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/flock_of_chefs/flocked_report.rb', line 18

def setup_dcell!
  raise 'Flock of chefs cookbook not in use!' unless node[:flock_of_chefs]
  if(node.recipes.include?('flock_of_chefs::keeper'))
    # NOTE: just gossip for now, zookeeper later
    start_args = {
      :node => node.name,
      :addr => "tcp://#{node[:ipaddress]}:#{node[:flock_of_chefs][:port]}"
    }
    case node[:flock_of_chefs][:registry][:type].to_s
    when 'zk'
      require 'dcell/registries/zk'
      start_args.merge(
        :registry => {
          :adapter => 'zk',
          :host => '127.0.0.1', # allow non-local?
          :port => 2181
        }
      )
    end
    DCell.start(start_args)
  else
    keeper_node = Chef::Search::Query.new.search(:node, 'recipes:flock_of_chefs\:\:keeper').first.first
    raise 'Failed to find flock keeper!' unless keeper_node
    DCell.start(
      :node => node.name,
      :addr => "tcp://#{node[:ipaddress]}:#{node[:flock_of_chefs][:port]}",
      :directory => {
        :id => keeper_node.name,
        :address => "tcp://#{keeper_node[:ipaddress]}:#{keeper_node[:flock_of_chefs][:port]}"
      }
    )
  end
end