### Home Classes Methods

### In Files

- lib/mcollective/rpc/reply.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #fail
- #fail!
- #initialize_data
- #to_hash

### Files

- COPYING
- README
- Rakefile
- PLACEHOLDER
- PLACEHOLDER

### Class/Module Index

Quicksearch

- MCollective
- MCollective::Agent
- MCollective::Agents
- MCollective::Aggregate
- MCollective::Aggregate::Base
- MCollective::Aggregate::Result
- MCollective::Aggregate::Result::Base
- MCollective::Aggregate::Result::CollectionResult
- MCollective::Aggregate::Result::NumericResult
- MCollective::Application
- MCollective::Applications
- MCollective::Client
- MCollective::Config
- MCollective::Connector
- MCollective::Connector::Base
- MCollective::DDL
- MCollective::DDLValidationError
- MCollective::Data
- MCollective::Data::Base
- MCollective::Data::Result
- MCollective::Discovery
- MCollective::Facts
- MCollective::Facts::Base
- MCollective::Generators
- MCollective::Generators::AgentGenerator
- MCollective::Generators::Base
- MCollective::Generators::DataGenerator
- MCollective::InvalidRPCData
- MCollective::Log
- MCollective::Logger
- MCollective::Logger::Base
- MCollective::Logger::Console_logger
- MCollective::Logger::File_logger
- MCollective::Logger::Syslog_logger
- MCollective::Matcher
- MCollective::Matcher::Parser
- MCollective::Matcher::Scanner
- MCollective::Message
- MCollective::MissingRPCData
- MCollective::MsgDoesNotMatchRequestID
- MCollective::MsgTTLExpired
- MCollective::NotTargettedAtUs
- MCollective::Optionparser
- MCollective::PluginManager
- MCollective::PluginPackager
- MCollective::PluginPackager::AgentDefinition
- MCollective::PluginPackager::StandardDefinition
- MCollective::RPC
- MCollective::RPC::ActionRunner
- MCollective::RPC::Agent
- MCollective::RPC::Audit
- MCollective::RPC::Client
- MCollective::RPC::Helpers
- MCollective::RPC::Progress
- MCollective::RPC::Reply
- MCollective::RPC::Request
- MCollective::RPC::Result
- MCollective::RPC::Stats
- MCollective::RPCAborted
- MCollective::RPCError
- MCollective::Registration
- MCollective::Registration::Base
- MCollective::Runner
- MCollective::RunnerStats
- MCollective::SSL
- MCollective::Security
- MCollective::Security::Base
- MCollective::SecurityValidationFailed
- MCollective::Shell
- MCollective::UnixDaemon
- MCollective::UnknownRPCAction
- MCollective::UnknownRPCError
- MCollective::Util
- MCollective::WindowsDaemon
- Array
- Dir
- Object
- String
- Symbol

No matching classes.

# MCollective::RPC::Reply

Simple class to manage compliant replies to MCollective::RPC

### Attributes

data[RW]
statuscode[RW]
statusmsg[RW]

### Public Instance Methods

[](key) click to toggle source

Read from the data hash

    # File lib/mcollective/rpc/reply.rb, line 68
    def [](key)
      @data[key]
    end

[]=(key, val) click to toggle source

Write to the data hash

    # File lib/mcollective/rpc/reply.rb, line 63
    def []=(key, val)
      @data[key] = val
    end

fail(msg, code=1) click to toggle source

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

fail!(msg, code=1) click to toggle source

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

initialize_data() click to toggle source

    # 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

to_hash() click to toggle source

Returns a compliant Hash of the reply that should be sent over the middleware

    # File lib/mcollective/rpc/reply.rb, line 74
    def to_hash
      return {:statuscode => @statuscode,
              :statusmsg => @statusmsg,
              :data => @data}
    end

### Public Class Methods

new(action, ddl) click to toggle source

    # 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.