Simple class to manage compliant replies to MCollective::RPC
(Not documented)
# 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 70 70: def [](key) 71: @data[key] 72: end
Write to the data hash
# File lib/mcollective/rpc/reply.rb, line 65 65: def []=(key, val) 66: @data[key] = val 67: end
Helper to fill in statusmsg and code on failure
# File lib/mcollective/rpc/reply.rb, line 36 36: def fail(msg, code=1) 37: @statusmsg = msg 38: @statuscode = code 39: end
Helper that fills in statusmsg and code but also raises an appropriate error
# File lib/mcollective/rpc/reply.rb, line 42 42: def fail!(msg, code=1) 43: @statusmsg = msg 44: @statuscode = code 45: 46: case code 47: when 1 48: raise RPCAborted, msg 49: 50: when 2 51: raise UnknownRPCAction, msg 52: 53: when 3 54: raise MissingRPCData, msg 55: 56: when 4 57: raise InvalidRPCData, msg 58: 59: else 60: raise UnknownRPCError, msg 61: end 62: end
(Not documented)
# File lib/mcollective/rpc/reply.rb, line 74 74: def fetch(key, default) 75: @data.fetch(key, default) 76: end
(Not documented)
# 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: # must deep clone this data to avoid accidental updates of the DDL in cases where the 30: # default is for example a string and someone does << on it 31: @data[output] = Marshal.load(Marshal.dump(interface[:output][output].fetch(:default, nil))) 32: end 33: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.