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
# 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:, state: :run, cmd: req[:cmd], opts: req[:opts])

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

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

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

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

#log_typeObject



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

def log_type
  self.class.name
end

#request_stopObject



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

def request_stop
  @cmd && @cmd.request_stop
end

#server_versionObject



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

def server_version
  OsCtld::VERSION
end