Class | MCollective::RPC::Reply |
In: |
lib/mcollective/rpc/reply.rb
|
Parent: | Object |
Simple class to manage compliant replies to MCollective::RPC
data | [RW] | |
statuscode | [RW] | |
statusmsg | [RW] |
# File lib/mcollective/rpc/reply.rb, line 7 7: def initialize(action, ddl) 8: @data = {} 9: @statuscode = 0 10: @statusmsg = "OK" 11: @ddl = ddl 12: @action = action 13: 14: begin 15: initialize_data 16: rescue Exception => e 17: Log.warn("Could not pre-populate reply data from the DDL: %s: %s" % [e.class, e.to_s ]) 18: end 19: end
Read from the data hash
# File lib/mcollective/rpc/reply.rb, line 68 68: def [](key) 69: @data[key] 70: end
Write to the data hash
# File lib/mcollective/rpc/reply.rb, line 63 63: def []=(key, val) 64: @data[key] = val 65: end
Helper to fill in statusmsg and code on failure
# File lib/mcollective/rpc/reply.rb, line 34 34: def fail(msg, code=1) 35: @statusmsg = msg 36: @statuscode = code 37: end
Helper that fills in statusmsg and code but also raises an appropriate error
# File lib/mcollective/rpc/reply.rb, line 40 40: def fail!(msg, code=1) 41: @statusmsg = msg 42: @statuscode = code 43: 44: case code 45: when 1 46: raise RPCAborted, msg 47: 48: when 2 49: raise UnknownRPCAction, msg 50: 51: when 3 52: raise MissingRPCData, msg 53: 54: when 4 55: raise InvalidRPCData, msg 56: 57: else 58: raise UnknownRPCError, msg 59: end 60: end
# File lib/mcollective/rpc/reply.rb, line 72 72: def fetch(key, default) 73: @data.fetch(key, default) 74: end
# File lib/mcollective/rpc/reply.rb, line 21 21: def initialize_data 22: unless @ddl.actions.include?(@action) 23: raise "No action '%s' defined for agent '%s' in the DDL" % [@action, @ddl.pluginname] 24: end 25: 26: interface = @ddl.action_interface(@action) 27: 28: interface[:output].keys.each do |output| 29: @data[output] = interface[:output][output][:default] 30: end 31: end