Class: MCollective::RPC::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/rpc/request.rb

Overview

Simple class to manage compliant requests for MCollective::RPC agents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
12
13
14
15
# File 'lib/mcollective/rpc/request.rb', line 7

def initialize(msg)
  @time = msg[:msgtime]
  @action = msg[:body][:action]
  @data = msg[:body][:data]
  @sender = msg[:senderid]
  @agent = msg[:body][:agent]
  @uniqid = msg[:requestid]
  @caller = msg[:callerid] || "unknown"
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def action
  @action
end

#agentObject

Returns the value of attribute agent.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def agent
  @agent
end

#callerObject

Returns the value of attribute caller.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def caller
  @caller
end

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def data
  @data
end

#senderObject

Returns the value of attribute sender.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def sender
  @sender
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def time
  @time
end

#uniqidObject

Returns the value of attribute uniqid.



5
6
7
# File 'lib/mcollective/rpc/request.rb', line 5

def uniqid
  @uniqid
end

Instance Method Details

#[](key) ⇒ Object

If data is a hash, gives easy access to its members, else returns nil



33
34
35
36
# File 'lib/mcollective/rpc/request.rb', line 33

def [](key)
  return nil unless @data.is_a?(Hash)
  return @data[key]
end

#include?(key) ⇒ Boolean

If data is a hash, quick helper to get access to it’s include? method else returns false

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/mcollective/rpc/request.rb', line 19

def include?(key)
  return false unless @data.is_a?(Hash)
  return @data.include?(key)
end

#should_respond?Boolean

If no :process_results is specified always respond else respond based on the supplied property

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/mcollective/rpc/request.rb', line 26

def should_respond?
  return @data[:process_results] if @data.include?(:process_results)

  return true
end

#to_hashObject



38
39
40
41
42
# File 'lib/mcollective/rpc/request.rb', line 38

def to_hash
  return {:agent => @agent,
    :action => @action,
    :data => @data}
end

#to_jsonObject



44
45
46
47
48
# File 'lib/mcollective/rpc/request.rb', line 44

def to_json
  to_hash.merge!({:sender   => @sender,
                   :callerid => @callerid,
                   :uniqid   => @uniqid}).to_json
end