Simple class to manage compliant requests for MCollective::RPC agents
# 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
If data is a hash, gives easy access to its members, else returns nil
# File lib/mcollective/rpc/request.rb, line 33 def [](key) return nil unless @data.is_a?(Hash) return @data[key] end
If data is a hash, quick helper to get access to it’s include? method else returns false
# File lib/mcollective/rpc/request.rb, line 19 def include?(key) return false unless @data.is_a?(Hash) return @data.include?(key) end
If no :process_results is specified always respond else respond based on the supplied property
# File lib/mcollective/rpc/request.rb, line 26 def should_respond? return @data[:process_results] if @data.include?(:process_results) return true end
# File lib/mcollective/rpc/request.rb, line 38 def to_hash return {:agent => @agent, :action => @action, :data => @data} end
# File lib/mcollective/rpc/request.rb, line 44 def to_json to_hash.merge!({:sender => @sender, :callerid => @callerid, :uniqid => @uniqid}).to_json end