Module MCollective::RPC
In: spec/unit/rpc/actionrunner_spec.rb
spec/unit/rpc/reply_spec.rb
spec/unit/rpc/request_spec.rb
spec/unit/rpc/agent_spec.rb
spec/unit/rpc/result_spec.rb
spec/unit/rpc/stats_spec.rb
lib/mcollective/rpc.rb
lib/mcollective/rpc/ddl.rb
lib/mcollective/rpc/stats.rb
lib/mcollective/rpc/result.rb
lib/mcollective/rpc/agent.rb
lib/mcollective/rpc/progress.rb
lib/mcollective/rpc/request.rb
lib/mcollective/rpc/actionrunner.rb
lib/mcollective/rpc/audit.rb
lib/mcollective/rpc/client.rb
lib/mcollective/rpc/helpers.rb
lib/mcollective/rpc/reply.rb
plugins/mcollective/audit/logfile.rb

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

Methods

Classes and Modules

Class MCollective::RPC::ActionRunner
Class MCollective::RPC::Agent
Class MCollective::RPC::Audit
Class MCollective::RPC::Client
Class MCollective::RPC::DDL
Class MCollective::RPC::Helpers
Class MCollective::RPC::Logfile
Class MCollective::RPC::Progress
Class MCollective::RPC::Reply
Class MCollective::RPC::Request
Class MCollective::RPC::Result
Class MCollective::RPC::Stats

Public Class methods

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.

[Source]

    # File lib/mcollective/rpc.rb, line 92
92:         def self.discovered(discovered)
93:             @@discovered = discovered
94:         end

Factory for RPC::Reply messages, only really here to make agents a bit easier to understand

[Source]

     # File lib/mcollective/rpc.rb, line 165
165:         def self.reply
166:             RPC::Reply.new
167:         end

Factory for RPC::Request messages, only really here to make agents a bit easier to understand

[Source]

     # File lib/mcollective/rpc.rb, line 159
159:         def self.request(msg)
160:             RPC::Request.new(msg)
161:         end

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.

[Source]

    # File lib/mcollective/rpc.rb, line 84
84:         def self.stats(stats)
85:             @@stats = stats
86:         end

Public Instance methods

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

[Source]

     # File lib/mcollective/rpc.rb, line 149
149:         def empty_filter?(options)
150:             if options.include?(:filter)
151:                 Util.empty_filter?(options[:filter])
152:             else
153:                 Util.empty_filter?(options)
154:             end
155:         end

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.

[Source]

     # File lib/mcollective/rpc.rb, line 130
130:         def printrpc(result, flags = {})
131:             verbose = @options[:verbose] rescue verbose = false
132:             verbose = flags[:verbose] || verbose
133:             flatten = flags[:flatten] || false
134: 
135:             result_text =  Helpers.rpcresults(result, {:verbose => verbose, :flatten => flatten})
136: 
137:             if result.is_a?(Array)
138:                 puts "\n%s\n" % [ result_text ]
139:             else
140:                 # when we get just one result to print dont pad them all with
141:                 # blank spaces etc, just print the individual result with no
142:                 # padding
143:                 puts result_text unless result_text == ""
144:             end
145:         end

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, at the moment only one flag is supported:

printrpcstats :caption => "Foo"

This will use "Foo" as the caption to the stats in verbose mode

[Source]

     # File lib/mcollective/rpc.rb, line 109
109:         def printrpcstats(flags={})
110:             verbose = @options[:verbose] rescue verbose = false
111:             caption = flags[:caption] || "rpc stats"
112: 
113:             begin
114:                 stats = @@stats
115:             rescue
116:                 puts("no stats to display")
117:                 return
118:             end
119: 
120:             puts
121:             puts stats.report(caption, verbose)
122:         end

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

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

[Source]

    # File lib/mcollective/rpc.rb, line 56
56:         def rpcclient(agent, flags = {})
57:             configfile = flags[:configfile] || "/etc/mcollective/client.cfg"
58:             options = flags[:options] || nil
59: 
60:             begin
61:                 if options
62:                     rpc = Client.new(agent, :configfile => options[:config], :options => options)
63:                     @options = rpc.options
64:                 else
65:                     rpc = Client.new(agent, :configfile => configfile)
66:                     @options = rpc.options
67:                 end
68:             rescue Exception => e
69:                 puts("Could not create RPC client: #{e}")
70:                 exit!
71:             end
72: 
73:             if block_given?
74:                 yield(rpc)
75:             else
76:                 return rpc
77:             end
78:         end

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

[Source]

    # File lib/mcollective/rpc.rb, line 22
22:         def rpcoptions
23:             oparser = MCollective::Optionparser.new({:verbose => false, :progress_bar => true}, "filter")
24: 
25:             options = oparser.parse do |parser, options|
26:                 if block_given?
27:                     yield(parser, options)
28:                 end
29: 
30:                 Helpers.add_simplerpc_options(parser, options)
31:             end
32: 
33:             return options
34:         end

[Validate]