Module: MCollective::RPC

### Home Classes Methods

### In Files

- lib/mcollective/rpc/agent.rb
- lib/mcollective/rpc/request.rb
- lib/mcollective/rpc/reply.rb
- lib/mcollective/rpc/progress.rb
- lib/mcollective/rpc/result.rb
- lib/mcollective/rpc/helpers.rb
- lib/mcollective/rpc/actionrunner.rb
- lib/mcollective/rpc/audit.rb
- lib/mcollective/rpc/client.rb
- lib/mcollective/rpc/stats.rb
- lib/mcollective/rpc.rb

### Namespace

- CLASS MCollective::RPC::ActionRunner
- CLASS MCollective::RPC::Agent
- CLASS MCollective::RPC::Audit
- CLASS MCollective::RPC::Client
- CLASS MCollective::RPC::Helpers
- CLASS MCollective::RPC::Progress
- CLASS MCollective::RPC::Reply
- CLASS MCollective::RPC::Request
- CLASS MCollective::RPC::Result
- CLASS MCollective::RPC::Stats

### Methods

- ::const_missing
- ::discovered
- ::stats
- #empty_filter?
- #printrpc
- #printrpcstats
- #rpcclient
- #rpcoptions

### 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

Toolset to create a standard interface of client and agent using an RPC metaphor, standard compliant agents will make it easier to create generic clients like web interfaces etc

### Public Instance Methods

empty_filter?(options) click to toggle source

Wrapper for MCollective::Util.empty_filter? to make clients less fugly to write - ticket #18

    # File lib/mcollective/rpc.rb, line 167
    def empty_filter?(options)
      if options.include?(:filter)
        Util.empty_filter?(options[:filter])
      else
        Util.empty_filter?(options)
      end
    end

printrpc(result, flags = {}) click to toggle source

Prints the result of an RPC call.

In the default quiet mode - no flattening or verbose - only results that produce an error will be printed

To get details of each result run with the -v command line option.

    # File lib/mcollective/rpc.rb, line 146
    def printrpc(result, flags = {})
      verbose = @options[:verbose] rescue verbose = false
      verbose = flags[:verbose] || verbose
      flatten = flags[:flatten] || false
      format = @options[:output_format]
      forced_mode = @options[:force_display_mode] || false

      result_text =  Helpers.rpcresults(result, {:verbose => verbose, :flatten => flatten, :format => format, :force_display_mode => forced_mode})

      if result.is_a?(Array) && format == :console
        puts "\n%s\n" % [ result_text ]
      else
        # when we get just one result to print dont pad them all with
        # blank spaces etc, just print the individual result with no
        # padding
        puts result_text unless result_text == ""
      end
    end

printrpcstats(flags={}) click to toggle source

Prints stats, requires stats to be saved from elsewhere using the MCollective::RPC.stats method.

If you’ve passed -v on the command line a detailed stat block will be printed, else just a one liner.

You can pass flags into it:

    printrpcstats :caption => "Foo", :summarize => true

This will use “Foo” as the caption to the stats in verbose mode and print out any aggregate summary information if present

    # File lib/mcollective/rpc.rb, line 123
    def printrpcstats(flags={})
      return unless @options[:output_format] == :console

      flags = {:summarize => false, :caption => "rpc stats"}.merge(flags)

      verbose = @options[:verbose] rescue verbose = false

      begin
        stats = @@stats
      rescue
        puts("no stats to display")
        return
      end

      puts stats.report(flags[:caption], flags[:summarize], verbose)
    end

rpcclient(agent, flags = {}) click to toggle source

Wrapper to create clients, supposed to be used as a mixin:

include MCollective::RPC

exim = rpcclient(“exim”) printrpc exim.mailq

or

rpcclient(“exim”) do |exim|

    printrpc exim.mailq

end

It will take a few flags:

    :configfile => "etc/client.cfg"
    :options => options
    :exit_on_failure => true

Options would be a build up options hash from the Optionparser you can use the rpcoptions helper to create this

:exit_on_failure is true by default, and causes the application to exit if there is a failure constructing the RPC client. Set this flag to false to cause an Exception to be raised instead.

    # File lib/mcollective/rpc.rb, line 60
    def rpcclient(agent, flags = {})
      configfile = flags[:configfile] || "/etc/mcollective/client.cfg"
      options = flags[:options] || nil

      if flags.key?(:exit_on_failure)
        exit_on_failure = flags[:exit_on_failure]
      else
        # We exit on failure by default for CLI-friendliness
        exit_on_failure = true
      end

      begin
        if options
          rpc = Client.new(agent, :configfile => options[:config], :options => options)
          @options = rpc.options
        else
          rpc = Client.new(agent, :configfile => configfile)
          @options = rpc.options
        end
      rescue Exception => e
        if exit_on_failure
          puts("Could not create RPC client: #{e}")
          exit!
        else
          raise e
        end
      end

      if block_given?
        yield(rpc)
      else
        return rpc
      end
    end

rpcoptions() click to toggle source

Creates a standard options hash, pass in a block to add extra headings etc see Optionparser

    # File lib/mcollective/rpc.rb, line 21
    def rpcoptions
      oparser = MCollective::Optionparser.new({:verbose => false, :progress_bar => true}, "filter")

      options = oparser.parse do |parser, options|
        if block_given?
          yield(parser, options)
        end

        Helpers.add_simplerpc_options(parser, options)
      end

      return options
    end

### Public Class Methods

const_missing(const_name) click to toggle source

    # File lib/mcollective/rpc.rb, line 175
    def self.const_missing(const_name)
      super unless const_name == :DDL

      Log.warn("MCollective::RPC::DDL is deprecatd, please use MCollective::DDL instead")
      MCollective::DDL
    end

discovered(discovered) click to toggle source

means for other classes to drop discovered hosts into this module its a bit hacky but needed so that the mixin methods like printrpcstats can easily get access to it without users having to pass it around in params.

    # File lib/mcollective/rpc.rb, line 107
    def self.discovered(discovered)
      @@discovered = discovered
    end

stats(stats) click to toggle source

means for other classes to drop stats into this module its a bit hacky but needed so that the mixin methods like printrpcstats can easily get access to it without users having to pass it around in params.

    # File lib/mcollective/rpc.rb, line 99
    def self.stats(stats)
      @@stats = stats
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.