Class: OsCtld::Daemon::ClientHandler

Inherits:
Generic::ClientHandler show all
Defined in:
lib/osctld/daemon.rb

Instance Attribute Summary

Attributes inherited from Generic::ClientHandler

#opts

Instance Method Summary collapse

Methods inherited from Generic::ClientHandler

#communicate, #error, #error!, #initialize, #ok, #parse, #reply_error, #reply_ok, #send_data, #send_update, #socket

Constructor Details

This class inherits a constructor from OsCtld::Generic::ClientHandler

Instance Method Details

#handle_cmd(req) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/osctld/daemon.rb', line 17

def handle_cmd(req)
  cmd_class = Command.find(req[:cmd].to_sym)
  error!("Unsupported command '#{req[:cmd]}'") unless cmd_class

  id = Command.get_id
  Eventd.report(:management, id: id, state: :run, cmd: req[:cmd], opts: req[:opts])

  @cmd = cmd = cmd_class.new(req[:opts], id: id, handler: self)
  ret = cmd.base_execute

  if ret.is_a?(Hash) && ret[:status]
    Eventd.report(:management, id: id, state: :done, cmd: req[:cmd], opts: req[:opts])

  else
    Eventd.report(:management, id: id, state: :failed, cmd: req[:cmd], opts: req[:opts])
  end

  ret

rescue => err
  Eventd.report(:management, id: id, state: :failed, cmd: req[:cmd], opts: req[:opts])
  raise
end

#log_typeObject



49
50
51
# File 'lib/osctld/daemon.rb', line 49

def log_type
  self.class.name
end

#request_stopObject



41
42
43
# File 'lib/osctld/daemon.rb', line 41

def request_stop
  @cmd && @cmd.request_stop
end

#server_versionObject



45
46
47
# File 'lib/osctld/daemon.rb', line 45

def server_version
  OsCtld::VERSION
end