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

#close_socket, #communicate, #error, #error!, #initialize, #ok, #parse, #read_request, #reply_error, #reply_ok, #send_data, #send_update, #socket, #stop_requested?

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
40
# 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
ensure
  @cmd = nil
end

#log_typeObject



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

def log_type
  self.class.name
end

#request_stopObject



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

def request_stop
  @cmd && @cmd.request_stop
  super
end

#server_versionObject



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

def server_version
  OsCtld::VERSION
end