Class: Chef::Nanite

Inherits:
Object show all
Defined in:
lib/chef/nanite.rb

Class Method Summary collapse

Class Method Details

.get_identity(type = "mapper") ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/chef/nanite.rb', line 51

def get_identity(type="mapper")
  id = nil
  if Chef::Config[:nanite_persistent_mapper]
    if Chef::FileCache.has_key?("nanite-#{type}-identity")
      id = Chef::FileCache.load("nanite-#{type}-identity")
    else
      id = UUIDTools::UUID.random_create.to_s 
      Chef::FileCache.store("nanite-#{type}-identity", id)
    end
  else
    id = Chef::Config[:nanite_identity] ? "#{Chef::Config[:nanite_identity]}-#{UUIDTools::UUID.random_create.to_s}" : UUIDTools::UUID.random_create.to_s 
  end
  id
end

.in_event(&block) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/chef/nanite.rb', line 78

def in_event(&block)
  if EM.reactor_running?
    begin
      ::Nanite.ensure_mapper
    rescue ::Nanite::MapperNotRunning
      start_mapper
    end
    block.call
  else
    Chef::Log.warn("Starting Event Machine Loop")
    Thread.new do
      EM.run do
        start_mapper
        block.call
      end
    end
  end
end

.push(*args) ⇒ Object



72
73
74
75
76
# File 'lib/chef/nanite.rb', line 72

def push(*args)
  in_event do
    ::Nanite.push(*args)
  end
end

.request(*args) ⇒ Object



66
67
68
69
70
# File 'lib/chef/nanite.rb', line 66

def request(*args)
  in_event do
    ::Nanite.request(*args)
  end
end

.start_mapper(config = {}) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chef/nanite.rb', line 36

def start_mapper(config={})
  Chef::Log.info("Running the Nanite Mapper")
  ::Nanite::Log.logger = Chef::Log.logger
  identity = get_identity
  ::Nanite.start_mapper(
    :host => Chef::Config[:nanite_host], 
    :user => Chef::Config[:nanite_user],
    :pass => Chef::Config[:nanite_pass], 
    :vhost => Chef::Config[:nanite_vhost],
    :identity => identity,
    :format => :json,
    :log_level => Chef::Config[:log_level] 
  )
end