3 # Simple class to manage compliant replies to MCollective::RPC
5 attr_accessor :statuscode, :statusmsg, :data
7 def initialize(action, ddl)
17 Log.warn("Could not pre-populate reply data from the DDL: %s: %s" % [e.class, e.to_s ])
22 unless @ddl.actions.include?(@action)
23 raise "No action '%s' defined for agent '%s' in the DDL" % [@action, @ddl.pluginname]
26 interface = @ddl.action_interface(@action)
28 interface[:output].keys.each do |output|
29 @data[output] = interface[:output][output][:default]
33 # Helper to fill in statusmsg and code on failure
39 # Helper that fills in statusmsg and code but also raises an appropriate error
40 def fail!(msg, code=1)
49 raise UnknownRPCAction, msg
52 raise MissingRPCData, msg
55 raise InvalidRPCData, msg
58 raise UnknownRPCError, msg
62 # Write to the data hash
67 # Read from the data hash
72 def fetch(key, default)
73 @data.fetch(key, default)
76 # Returns a compliant Hash of the reply that should be sent
79 return {:statuscode => @statuscode,
80 :statusmsg => @statusmsg,