Simple class to manage compliant replies to MCollective::RPC
Read from the data hash
# File lib/mcollective/rpc/reply.rb, line 68 def [](key) @data[key] end
Write to the data hash
# File lib/mcollective/rpc/reply.rb, line 63 def []=(key, val) @data[key] = val end
Helper to fill in statusmsg and code on failure
# File lib/mcollective/rpc/reply.rb, line 34 def fail(msg, code=1) @statusmsg = msg @statuscode = code end
Helper that fills in statusmsg and code but also raises an appropriate error
# File lib/mcollective/rpc/reply.rb, line 40 def fail!(msg, code=1) @statusmsg = msg @statuscode = code case code when 1 raise RPCAborted, msg when 2 raise UnknownRPCAction, msg when 3 raise MissingRPCData, msg when 4 raise InvalidRPCData, msg else raise UnknownRPCError, msg end end
# File lib/mcollective/rpc/reply.rb, line 21 def initialize_data unless @ddl.actions.include?(@action) raise "No action '%s' defined for agent '%s' in the DDL" % [@action, @ddl.pluginname] end interface = @ddl.action_interface(@action) interface[:output].keys.each do |output| @data[output] = interface[:output][output][:default] end end
# File lib/mcollective/rpc/reply.rb, line 7 def initialize(action, ddl) @data = {} @statuscode = 0 @statusmsg = "OK" @ddl = ddl @action = action begin initialize_data rescue Exception => e Log.warn("Could not pre-populate reply data from the DDL: %s: %s" % [e.class, e.to_s ]) end end
Generated with the Darkfish Rdoc Generator 2.