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



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

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



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

def log_type
  self.class.name
end

#request_stopObject



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

def request_stop
  @cmd && @cmd.request_stop
end

#server_versionObject



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

def server_version
  OsCtld::VERSION
end