Class: OatsAgent::Rclient

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
EM::P::ObjectProtocol
Defined in:
lib/oats_agent/rclient.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, request) ⇒ Rclient

def serializer

  YAML
end


10
11
12
13
# File 'lib/oats_agent/rclient.rb', line 10

def initialize(host, request)
  @host = host
  @request = request
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/oats_agent/rclient.rb', line 4

def response
  @response
end

Instance Method Details

#client_logger(arg) ⇒ Object



26
27
28
# File 'lib/oats_agent/rclient.rb', line 26

def client_logger(arg)
  $log.info arg + " #{@request[:id]}@#{@host} at " + Time.now.strftime("%y-%m-%d %H:%M:%S")
end

#post_initObject



30
31
32
33
34
35
# File 'lib/oats_agent/rclient.rb', line 30

def post_init
  password = @request.delete(:password)
  client_logger "Sending " + @request.inspect + " to"
  @request[:password] = password
  send_object(@request)
end

#receive_object(response) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/oats_agent/rclient.rb', line 15

def receive_object(response)
  @response = response
  password = response.delete(:password)
  length = 500
  resp = response.inspect
  resp = resp[0..length] + ' ..... ' + resp[-length..-1] if resp.size > 2*length
  client_logger "Received " + resp + " from"
  response[:password] = password
  client_logger "Command was not recognized" if response[:unknown_command]
end

#unbindObject



36
37
38
39
# File 'lib/oats_agent/rclient.rb', line 36

def unbind
  client_logger "Did not hear from " unless @response
  EventMachine::stop_event_loop
end