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 # 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)))
35 # Helper to fill in statusmsg and code on failure
41 # Helper that fills in statusmsg and code but also raises an appropriate error
42 def fail!(msg, code=1)
51 raise UnknownRPCAction, msg
54 raise MissingRPCData, msg
57 raise InvalidRPCData, msg
60 raise UnknownRPCError, msg
64 # Write to the data hash
69 # Read from the data hash
74 def fetch(key, default)
75 @data.fetch(key, default)
78 # Returns a compliant Hash of the reply that should be sent
81 return {:statuscode => @statuscode,
82 :statusmsg => @statusmsg,