1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6 <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
8 <title>Class: MCollective::RPC::Client</title>
10 <link rel="stylesheet" href="../../rdoc.css" type="text/css" media="screen" />
12 <script src="../../js/jquery.js" type="text/javascript"
13 charset="utf-8"></script>
14 <script src="../../js/thickbox-compressed.js" type="text/javascript"
15 charset="utf-8"></script>
16 <script src="../../js/quicksearch.js" type="text/javascript"
17 charset="utf-8"></script>
18 <script src="../../js/darkfish.js" type="text/javascript"
19 charset="utf-8"></script>
25 <div id="file-metadata">
26 <div id="file-list-section" class="section">
27 <h3 class="section-header">In Files</h3>
28 <div class="section-body">
31 <li><a href="../../lib/mcollective/rpc/client_rb.html?TB_iframe=true&height=550&width=785"
32 class="thickbox" title="lib/mcollective/rpc/client.rb">lib/mcollective/rpc/client.rb</a></li>
41 <div id="class-metadata">
45 <div id="parent-class-section" class="section">
46 <h3 class="section-header">Parent</h3>
48 <p class="link"><a href="../../Object.html">Object</a></p>
53 <!-- Namespace Contents -->
56 <!-- Method Quickref -->
58 <div id="method-list-section" class="section">
59 <h3 class="section-header">Methods</h3>
60 <ul class="link-list">
62 <li><a href="#M000443">::new</a></li>
64 <li><a href="#M000461">#agent_filter</a></li>
66 <li><a href="#M000475">#aggregate_reply</a></li>
68 <li><a href="#M000471">#batch_size=</a></li>
70 <li><a href="#M000472">#batch_sleep_time=</a></li>
72 <li><a href="#M000480">#call_agent</a></li>
74 <li><a href="#M000479">#call_agent_batched</a></li>
76 <li><a href="#M000459">#class_filter</a></li>
78 <li><a href="#M000468">#collective=</a></li>
80 <li><a href="#M000463">#compound_filter</a></li>
82 <li><a href="#M000454">#custom_request</a></li>
84 <li><a href="#M000446">#disconnect</a></li>
86 <li><a href="#M000466">#discover</a></li>
88 <li><a href="#M000457">#discovery_method=</a></li>
90 <li><a href="#M000458">#discovery_options=</a></li>
92 <li><a href="#M000455">#discovery_timeout</a></li>
94 <li><a href="#M000456">#discovery_timeout=</a></li>
96 <li><a href="#M000460">#fact_filter</a></li>
98 <li><a href="#M000477">#fire_and_forget_request</a></li>
100 <li><a href="#M000447">#help</a></li>
102 <li><a href="#M000462">#identity_filter</a></li>
104 <li><a href="#M000478">#identity_filter_discovery_optimization</a></li>
106 <li><a href="#M000470">#limit_method=</a></li>
108 <li><a href="#M000469">#limit_targets=</a></li>
110 <li><a href="#M000474">#load_aggregate_functions</a></li>
112 <li><a href="#M000452">#method_missing</a></li>
114 <li><a href="#M000448">#new_request</a></li>
116 <li><a href="#M000467">#options</a></li>
118 <li><a href="#M000473">#pick_nodes_from_discovered</a></li>
120 <li><a href="#M000485">#process_results_with_block</a></li>
122 <li><a href="#M000481">#process_results_without_block</a></li>
124 <li><a href="#M000464">#reset</a></li>
126 <li><a href="#M000465">#reset_filter</a></li>
128 <li><a href="#M000476">#rpc_result_from_reply</a></li>
130 <li><a href="#M000449">#validate_request</a></li>
136 <!-- Included Modules -->
140 <div id="project-metadata">
143 <div id="fileindex-section" class="section project-section">
144 <h3 class="section-header">Files</h3>
147 <li class="file"><a href="../../COPYING.html">COPYING</a></li>
149 <li class="file"><a href="../../Gemfile.html">Gemfile</a></li>
151 <li class="file"><a href="../../README.html">README</a></li>
153 <li class="file"><a href="../../Rakefile.html">Rakefile</a></li>
155 <li class="file"><a href="../../etc/client_cfg_dist.html">client.cfg.dist</a></li>
157 <li class="file"><a href="../../etc/data-help_erb.html">data-help.erb</a></li>
159 <li class="file"><a href="../../etc/discovery-help_erb.html">discovery-help.erb</a></li>
161 <li class="file"><a href="../../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
163 <li class="file"><a href="../../etc/metadata-help_erb.html">metadata-help.erb</a></li>
165 <li class="file"><a href="../../etc/msg-help_erb.html">msg-help.erb</a></li>
167 <li class="file"><a href="../../etc/rpc-help_erb.html">rpc-help.erb</a></li>
169 <li class="file"><a href="../../etc/server_cfg_dist.html">server.cfg.dist</a></li>
171 <li class="file"><a href="../../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
173 <li class="file"><a href="../../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
175 <li class="file"><a href="../../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
177 <li class="file"><a href="../../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
179 <li class="file"><a href="../../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
181 <li class="file"><a href="../../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
183 <li class="file"><a href="../../lib/mcollective/locales/en_yml.html">en.yml</a></li>
185 <li class="file"><a href="../../mcollective_init.html">mcollective.init</a></li>
191 <div id="classindex-section" class="section project-section">
192 <h3 class="section-header">Class Index
193 <span class="search-toggle"><img src="../../images/find.png"
194 height="16" width="16" alt="[+]"
195 title="show/hide quicksearch" /></span></h3>
196 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
198 <legend>Quicksearch</legend>
199 <input type="text" name="quicksearch" value=""
200 class="quicksearch-field" />
204 <ul class="link-list">
206 <li><a href="../../MCollective.html">MCollective</a></li>
208 <li><a href="../../MCollective/Agent.html">MCollective::Agent</a></li>
210 <li><a href="../../MCollective/Agents.html">MCollective::Agents</a></li>
212 <li><a href="../../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
214 <li><a href="../../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
216 <li><a href="../../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
218 <li><a href="../../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
220 <li><a href="../../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
222 <li><a href="../../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
224 <li><a href="../../MCollective/Application.html">MCollective::Application</a></li>
226 <li><a href="../../MCollective/Applications.html">MCollective::Applications</a></li>
228 <li><a href="../../MCollective/Cache.html">MCollective::Cache</a></li>
230 <li><a href="../../MCollective/Client.html">MCollective::Client</a></li>
232 <li><a href="../../MCollective/CodedError.html">MCollective::CodedError</a></li>
234 <li><a href="../../MCollective/Config.html">MCollective::Config</a></li>
236 <li><a href="../../MCollective/Connector.html">MCollective::Connector</a></li>
238 <li><a href="../../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
240 <li><a href="../../MCollective/DDL.html">MCollective::DDL</a></li>
242 <li><a href="../../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
244 <li><a href="../../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
246 <li><a href="../../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
248 <li><a href="../../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
250 <li><a href="../../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
252 <li><a href="../../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
254 <li><a href="../../MCollective/Data.html">MCollective::Data</a></li>
256 <li><a href="../../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
258 <li><a href="../../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
260 <li><a href="../../MCollective/Discovery.html">MCollective::Discovery</a></li>
262 <li><a href="../../MCollective/Facts.html">MCollective::Facts</a></li>
264 <li><a href="../../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
266 <li><a href="../../MCollective/Generators.html">MCollective::Generators</a></li>
268 <li><a href="../../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
270 <li><a href="../../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
272 <li><a href="../../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
274 <li><a href="../../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
276 <li><a href="../../MCollective/Log.html">MCollective::Log</a></li>
278 <li><a href="../../MCollective/Logger.html">MCollective::Logger</a></li>
280 <li><a href="../../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
282 <li><a href="../../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
284 <li><a href="../../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
286 <li><a href="../../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
288 <li><a href="../../MCollective/Matcher.html">MCollective::Matcher</a></li>
290 <li><a href="../../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
292 <li><a href="../../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
294 <li><a href="../../MCollective/Message.html">MCollective::Message</a></li>
296 <li><a href="../../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
298 <li><a href="../../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
300 <li><a href="../../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
302 <li><a href="../../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
304 <li><a href="../../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
306 <li><a href="../../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
308 <li><a href="../../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
310 <li><a href="../../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
312 <li><a href="../../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
314 <li><a href="../../MCollective/RPC.html">MCollective::RPC</a></li>
316 <li><a href="../../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
318 <li><a href="../../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
320 <li><a href="../../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
322 <li><a href="../../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
324 <li><a href="../../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
326 <li><a href="../../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
328 <li><a href="../../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
330 <li><a href="../../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
332 <li><a href="../../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
334 <li><a href="../../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
336 <li><a href="../../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
338 <li><a href="../../MCollective/RPCError.html">MCollective::RPCError</a></li>
340 <li><a href="../../MCollective/Registration.html">MCollective::Registration</a></li>
342 <li><a href="../../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
344 <li><a href="../../MCollective/Runner.html">MCollective::Runner</a></li>
346 <li><a href="../../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
348 <li><a href="../../MCollective/SSL.html">MCollective::SSL</a></li>
350 <li><a href="../../MCollective/Security.html">MCollective::Security</a></li>
352 <li><a href="../../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
354 <li><a href="../../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
356 <li><a href="../../MCollective/Shell.html">MCollective::Shell</a></li>
358 <li><a href="../../MCollective/Translatable.html">MCollective::Translatable</a></li>
360 <li><a href="../../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
362 <li><a href="../../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
364 <li><a href="../../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
366 <li><a href="../../MCollective/Util.html">MCollective::Util</a></li>
368 <li><a href="../../MCollective/Validator.html">MCollective::Validator</a></li>
370 <li><a href="../../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
372 <li><a href="../../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
374 <li><a href="../../Array.html">Array</a></li>
376 <li><a href="../../Dir.html">Dir</a></li>
378 <li><a href="../../Object.html">Object</a></li>
380 <li><a href="../../String.html">String</a></li>
382 <li><a href="../../Symbol.html">Symbol</a></li>
385 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
392 <div id="documentation">
393 <h1 class="class">MCollective::RPC::Client</h1>
395 <div id="description">
397 The main component of the Simple <a href="../RPC.html">RPC</a> client
398 system, this wraps around <a href="../Client.html">MCollective::Client</a>
399 and just brings in a lot of convention and standard approached.
409 <div id="attribute-method-details" class="method-section section">
410 <h3 class="section-header">Attributes</h3>
413 <div id="timeout-attribute-method" class="method-detail">
414 <a name="timeout"></a>
416 <a name="timeout="></a>
418 <div class="method-heading attribute-method-heading">
419 <span class="method-name">timeout</span><span
420 class="attribute-access-type">[RW]</span>
423 <div class="method-description">
425 <p class="missing-docs">(Not documented)</p>
430 <div id="verbose-attribute-method" class="method-detail">
431 <a name="verbose"></a>
433 <a name="verbose="></a>
435 <div class="method-heading attribute-method-heading">
436 <span class="method-name">verbose</span><span
437 class="attribute-access-type">[RW]</span>
440 <div class="method-description">
442 <p class="missing-docs">(Not documented)</p>
447 <div id="filter-attribute-method" class="method-detail">
448 <a name="filter"></a>
450 <a name="filter="></a>
452 <div class="method-heading attribute-method-heading">
453 <span class="method-name">filter</span><span
454 class="attribute-access-type">[RW]</span>
457 <div class="method-description">
459 <p class="missing-docs">(Not documented)</p>
464 <div id="config-attribute-method" class="method-detail">
465 <a name="config"></a>
467 <a name="config="></a>
469 <div class="method-heading attribute-method-heading">
470 <span class="method-name">config</span><span
471 class="attribute-access-type">[RW]</span>
474 <div class="method-description">
476 <p class="missing-docs">(Not documented)</p>
481 <div id="progress-attribute-method" class="method-detail">
482 <a name="progress"></a>
484 <a name="progress="></a>
486 <div class="method-heading attribute-method-heading">
487 <span class="method-name">progress</span><span
488 class="attribute-access-type">[RW]</span>
491 <div class="method-description">
493 <p class="missing-docs">(Not documented)</p>
498 <div id="ttl-attribute-method" class="method-detail">
503 <div class="method-heading attribute-method-heading">
504 <span class="method-name">ttl</span><span
505 class="attribute-access-type">[RW]</span>
508 <div class="method-description">
510 <p class="missing-docs">(Not documented)</p>
515 <div id="reply-to-attribute-method" class="method-detail">
516 <a name="reply_to"></a>
518 <a name="reply_to="></a>
520 <div class="method-heading attribute-method-heading">
521 <span class="method-name">reply_to</span><span
522 class="attribute-access-type">[RW]</span>
525 <div class="method-description">
527 <p class="missing-docs">(Not documented)</p>
532 <div id="client-attribute-method" class="method-detail">
533 <a name="client"></a>
535 <div class="method-heading attribute-method-heading">
536 <span class="method-name">client</span><span
537 class="attribute-access-type">[R]</span>
540 <div class="method-description">
542 <p class="missing-docs">(Not documented)</p>
547 <div id="stats-attribute-method" class="method-detail">
550 <div class="method-heading attribute-method-heading">
551 <span class="method-name">stats</span><span
552 class="attribute-access-type">[R]</span>
555 <div class="method-description">
557 <p class="missing-docs">(Not documented)</p>
562 <div id="ddl-attribute-method" class="method-detail">
565 <div class="method-heading attribute-method-heading">
566 <span class="method-name">ddl</span><span
567 class="attribute-access-type">[R]</span>
570 <div class="method-description">
572 <p class="missing-docs">(Not documented)</p>
577 <div id="agent-attribute-method" class="method-detail">
580 <div class="method-heading attribute-method-heading">
581 <span class="method-name">agent</span><span
582 class="attribute-access-type">[R]</span>
585 <div class="method-description">
587 <p class="missing-docs">(Not documented)</p>
592 <div id="limit-targets-attribute-method" class="method-detail">
593 <a name="limit_targets"></a>
595 <div class="method-heading attribute-method-heading">
596 <span class="method-name">limit_targets</span><span
597 class="attribute-access-type">[R]</span>
600 <div class="method-description">
602 <p class="missing-docs">(Not documented)</p>
607 <div id="limit-method-attribute-method" class="method-detail">
608 <a name="limit_method"></a>
610 <div class="method-heading attribute-method-heading">
611 <span class="method-name">limit_method</span><span
612 class="attribute-access-type">[R]</span>
615 <div class="method-description">
617 <p class="missing-docs">(Not documented)</p>
622 <div id="output-format-attribute-method" class="method-detail">
623 <a name="output_format"></a>
625 <div class="method-heading attribute-method-heading">
626 <span class="method-name">output_format</span><span
627 class="attribute-access-type">[R]</span>
630 <div class="method-description">
632 <p class="missing-docs">(Not documented)</p>
637 <div id="batch-size-attribute-method" class="method-detail">
638 <a name="batch_size"></a>
640 <div class="method-heading attribute-method-heading">
641 <span class="method-name">batch_size</span><span
642 class="attribute-access-type">[R]</span>
645 <div class="method-description">
647 <p class="missing-docs">(Not documented)</p>
652 <div id="batch-sleep-time-attribute-method" class="method-detail">
653 <a name="batch_sleep_time"></a>
655 <div class="method-heading attribute-method-heading">
656 <span class="method-name">batch_sleep_time</span><span
657 class="attribute-access-type">[R]</span>
660 <div class="method-description">
662 <p class="missing-docs">(Not documented)</p>
667 <div id="batch-mode-attribute-method" class="method-detail">
668 <a name="batch_mode"></a>
670 <div class="method-heading attribute-method-heading">
671 <span class="method-name">batch_mode</span><span
672 class="attribute-access-type">[R]</span>
675 <div class="method-description">
677 <p class="missing-docs">(Not documented)</p>
682 <div id="discovery-options-attribute-method" class="method-detail">
683 <a name="discovery_options"></a>
685 <div class="method-heading attribute-method-heading">
686 <span class="method-name">discovery_options</span><span
687 class="attribute-access-type">[R]</span>
690 <div class="method-description">
692 <p class="missing-docs">(Not documented)</p>
697 <div id="discovery-method-attribute-method" class="method-detail">
698 <a name="discovery_method"></a>
700 <div class="method-heading attribute-method-heading">
701 <span class="method-name">discovery_method</span><span
702 class="attribute-access-type">[R]</span>
705 <div class="method-description">
707 <p class="missing-docs">(Not documented)</p>
712 <div id="default-discovery-method-attribute-method" class="method-detail">
713 <a name="default_discovery_method"></a>
715 <div class="method-heading attribute-method-heading">
716 <span class="method-name">default_discovery_method</span><span
717 class="attribute-access-type">[R]</span>
720 <div class="method-description">
722 <p class="missing-docs">(Not documented)</p>
727 <div id="limit-seed-attribute-method" class="method-detail">
728 <a name="limit_seed"></a>
730 <div class="method-heading attribute-method-heading">
731 <span class="method-name">limit_seed</span><span
732 class="attribute-access-type">[R]</span>
735 <div class="method-description">
737 <p class="missing-docs">(Not documented)</p>
747 <div id="public-class-method-details" class="method-section section">
748 <h3 class="section-header">Public Class Methods</h3>
751 <div id="new-method" class="method-detail ">
752 <a name="M000443"></a>
754 <div class="method-heading">
756 <span class="method-name">new</span><span
757 class="method-args">(agent, flags = {})</span>
758 <span class="method-click-advice">click to toggle source</span>
762 <div class="method-description">
765 Creates a stub for a remote agent, you can pass in an options array in the
766 flags which will then be used else it will just create a default options
767 array with filtering enabled based on the standard command line use.
770 rpc = RPC::Client.new("rpctest", :configfile => "client.cfg", :options => options)
773 You typically would not call this directly you’d use <a
774 href="../RPC.html#M000314">MCollective::RPC#rpcclient</a> instead which is
775 a wrapper around this that can be used as a Mixin
780 <div class="method-source-code"
783 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 20</span>
784 20: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">flags</span> = {})
785 21: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:options</span>)
786 22: <span class="ruby-identifier">initial_options</span> = <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:options</span>]
788 24: <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@@initial_options</span>
789 25: <span class="ruby-identifier">initial_options</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-ivar">@@initial_options</span>)
791 27: <span class="ruby-keyword kw">else</span>
792 28: <span class="ruby-identifier">oparser</span> = <span class="ruby-constant">MCollective</span><span class="ruby-operator">::</span><span class="ruby-constant">Optionparser</span>.<span class="ruby-identifier">new</span>({<span class="ruby-identifier">:verbose</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">:progress_bar</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">:mcollective_limit_targets</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">false</span>, <span class="ruby-identifier">:batch_size</span> =<span class="ruby-operator">></span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">:batch_sleep_time</span> =<span class="ruby-operator">></span> <span class="ruby-value">1</span>}, <span class="ruby-value str">"filter"</span>)
794 30: <span class="ruby-identifier">initial_options</span> = <span class="ruby-identifier">oparser</span>.<span class="ruby-identifier">parse</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">parser</span>, <span class="ruby-identifier">opts</span><span class="ruby-operator">|</span>
795 31: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
796 32: <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">parser</span>, <span class="ruby-identifier">opts</span>)
797 33: <span class="ruby-keyword kw">end</span>
799 35: <span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">add_simplerpc_options</span>(<span class="ruby-identifier">parser</span>, <span class="ruby-identifier">opts</span>)
800 36: <span class="ruby-keyword kw">end</span>
802 38: <span class="ruby-ivar">@@initial_options</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">initial_options</span>)
803 39: <span class="ruby-keyword kw">end</span>
805 41: <span class="ruby-ivar">@initial_options</span> = <span class="ruby-identifier">initial_options</span>
807 43: <span class="ruby-ivar">@config</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:config</span>]
808 44: <span class="ruby-ivar">@client</span> = <span class="ruby-constant">MCollective</span><span class="ruby-operator">::</span><span class="ruby-constant">Client</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@config</span>)
809 45: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">initial_options</span>
811 47: <span class="ruby-ivar">@stats</span> = <span class="ruby-constant">Stats</span>.<span class="ruby-identifier">new</span>
812 48: <span class="ruby-ivar">@agent</span> = <span class="ruby-identifier">agent</span>
813 49: <span class="ruby-ivar">@timeout</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-value">5</span>
814 50: <span class="ruby-ivar">@verbose</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:verbose</span>]
815 51: <span class="ruby-ivar">@filter</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:filter</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Util</span>.<span class="ruby-identifier">empty_filter</span>
816 52: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-keyword kw">nil</span>
817 53: <span class="ruby-ivar">@progress</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:progress_bar</span>]
818 54: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:mcollective_limit_targets</span>]
819 55: <span class="ruby-ivar">@limit_method</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">rpclimitmethod</span>
820 56: <span class="ruby-ivar">@limit_seed</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:limit_seed</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">nil</span>
821 57: <span class="ruby-ivar">@output_format</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:output_format</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">:console</span>
822 58: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">false</span>
823 59: <span class="ruby-ivar">@reply_to</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:reply_to</span>]
824 60: <span class="ruby-ivar">@discovery_method</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:discovery_method</span>]
825 61: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@discovery_method</span>
826 62: <span class="ruby-ivar">@discovery_method</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">default_discovery_method</span>
827 63: <span class="ruby-ivar">@default_discovery_method</span> = <span class="ruby-keyword kw">true</span>
828 64: <span class="ruby-keyword kw">else</span>
829 65: <span class="ruby-ivar">@default_discovery_method</span> = <span class="ruby-keyword kw">false</span>
830 66: <span class="ruby-keyword kw">end</span>
831 67: <span class="ruby-ivar">@discovery_options</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:discovery_options</span>] <span class="ruby-operator">||</span> []
832 68: <span class="ruby-ivar">@force_display_mode</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:force_display_mode</span>] <span class="ruby-operator">||</span> <span class="ruby-keyword kw">false</span>
834 70: <span class="ruby-ivar">@batch_size</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:batch_size</span>] <span class="ruby-operator">||</span> <span class="ruby-value">0</span>)
835 71: <span class="ruby-ivar">@batch_sleep_time</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:batch_sleep_time</span>] <span class="ruby-operator">||</span> <span class="ruby-value">1</span>)
836 72: <span class="ruby-ivar">@batch_mode</span> = <span class="ruby-ivar">@batch_size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
838 74: <span class="ruby-identifier">agent_filter</span> <span class="ruby-identifier">agent</span>
840 76: <span class="ruby-ivar">@discovery_timeout</span> = <span class="ruby-ivar">@initial_options</span>.<span class="ruby-identifier">fetch</span>(<span class="ruby-identifier">:disctimeout</span>, <span class="ruby-keyword kw">nil</span>)
842 78: <span class="ruby-ivar">@collective</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">collective</span>
843 79: <span class="ruby-ivar">@ttl</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:ttl</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">ttl</span>
844 80: <span class="ruby-ivar">@publish_timeout</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:publish_timeout</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">publish_timeout</span>
845 81: <span class="ruby-ivar">@threaded</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:threaded</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">threaded</span>
847 83: <span class="ruby-comment cmt"># if we can find a DDL for the service override</span>
848 84: <span class="ruby-comment cmt"># the timeout of the client so we always magically</span>
849 85: <span class="ruby-comment cmt"># wait appropriate amounts of time.</span>
850 86: <span class="ruby-comment cmt">#</span>
851 87: <span class="ruby-comment cmt"># We add the discovery timeout to the ddl supplied</span>
852 88: <span class="ruby-comment cmt"># timeout as the discovery timeout tends to be tuned</span>
853 89: <span class="ruby-comment cmt"># for local network conditions and fact source speed</span>
854 90: <span class="ruby-comment cmt"># which would other wise not be accounted for and</span>
855 91: <span class="ruby-comment cmt"># some results might get missed.</span>
856 92: <span class="ruby-comment cmt">#</span>
857 93: <span class="ruby-comment cmt"># We do this only if the timeout is the default 5</span>
858 94: <span class="ruby-comment cmt"># seconds, so that users cli overrides will still</span>
859 95: <span class="ruby-comment cmt"># get applied</span>
860 96: <span class="ruby-comment cmt">#</span>
861 97: <span class="ruby-comment cmt"># DDLs are required, failure to find a DDL is fatal</span>
862 98: <span class="ruby-ivar">@ddl</span> = <span class="ruby-constant">DDL</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">agent</span>)
863 99: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">ddl</span> = <span class="ruby-ivar">@ddl</span>
864 100: <span class="ruby-ivar">@timeout</span> = <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">meta</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">discovery_timeout</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@timeout</span> <span class="ruby-operator">==</span> <span class="ruby-value">5</span>
866 102: <span class="ruby-comment cmt"># allows stderr and stdout to be overridden for testing</span>
867 103: <span class="ruby-comment cmt"># but also for web apps that might not want a bunch of stuff</span>
868 104: <span class="ruby-comment cmt"># generated to actual file handles</span>
869 105: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stderr</span>]
870 106: <span class="ruby-ivar">@stderr</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stderr</span>]
871 107: <span class="ruby-keyword kw">else</span>
872 108: <span class="ruby-ivar">@stderr</span> = <span class="ruby-constant">STDERR</span>
873 109: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword kw">true</span>
874 110: <span class="ruby-keyword kw">end</span>
876 112: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stdout</span>]
877 113: <span class="ruby-ivar">@stdout</span> = <span class="ruby-identifier">initial_options</span>[<span class="ruby-identifier">:stdout</span>]
878 114: <span class="ruby-keyword kw">else</span>
879 115: <span class="ruby-ivar">@stdout</span> = <span class="ruby-constant">STDOUT</span>
880 116: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword kw">true</span>
881 117: <span class="ruby-keyword kw">end</span>
882 118: <span class="ruby-keyword kw">end</span></pre>
893 <div id="public-instance-method-details" class="method-section section">
894 <h3 class="section-header">Public Instance Methods</h3>
897 <div id="agent-filter-method" class="method-detail ">
898 <a name="M000461"></a>
900 <div class="method-heading">
902 <span class="method-name">agent_filter</span><span
903 class="method-args">(agent)</span>
904 <span class="method-click-advice">click to toggle source</span>
908 <div class="method-description">
911 Sets the agent filter
916 <div class="method-source-code"
917 id="agent-filter-source">
919 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 422</span>
920 422: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">agent_filter</span>(<span class="ruby-identifier">agent</span>)
921 423: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"agent"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"agent"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">agent</span>]
922 424: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"agent"</span>].<span class="ruby-identifier">compact!</span>
923 425: <span class="ruby-identifier">reset</span>
924 426: <span class="ruby-keyword kw">end</span></pre>
933 <div id="aggregate-reply-method" class="method-detail ">
934 <a name="M000475"></a>
936 <div class="method-heading">
938 <span class="method-name">aggregate_reply</span><span
939 class="method-args">(reply, aggregate)</span>
940 <span class="method-click-advice">click to toggle source</span>
944 <div class="method-description">
946 <p class="missing-docs">(Not documented)</p>
950 <div class="method-source-code"
951 id="aggregate-reply-source">
953 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 687</span>
954 687: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">aggregate_reply</span>(<span class="ruby-identifier">reply</span>, <span class="ruby-identifier">aggregate</span>)
955 688: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">aggregate</span>
957 690: <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">call_functions</span>(<span class="ruby-identifier">reply</span>)
958 691: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">aggregate</span>
959 692: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
960 693: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">"Failed to calculate aggregate summaries for reply from %s, calculating summaries disabled: %s: %s (%s)"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:senderid</span>], <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">first</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>])
961 694: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
962 695: <span class="ruby-keyword kw">end</span></pre>
971 <div id="batch-size--method" class="method-detail ">
972 <a name="M000471"></a>
974 <div class="method-heading">
976 <span class="method-name">batch_size=</span><span
977 class="method-args">(limit)</span>
978 <span class="method-click-advice">click to toggle source</span>
982 <div class="method-description">
985 Sets the batch size, if the size is set to 0 that will disable batch mode
990 <div class="method-source-code"
991 id="batch-size--source">
993 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 608</span>
994 608: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">batch_size=</span>(<span class="ruby-identifier">limit</span>)
995 609: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can only set batch size if direct addressing is supported"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
997 611: <span class="ruby-ivar">@batch_size</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">limit</span>)
998 612: <span class="ruby-ivar">@batch_mode</span> = <span class="ruby-ivar">@batch_size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
999 613: <span class="ruby-keyword kw">end</span></pre>
1008 <div id="batch-sleep-time--method" class="method-detail ">
1009 <a name="M000472"></a>
1011 <div class="method-heading">
1013 <span class="method-name">batch_sleep_time=</span><span
1014 class="method-args">(time)</span>
1015 <span class="method-click-advice">click to toggle source</span>
1019 <div class="method-description">
1021 <p class="missing-docs">(Not documented)</p>
1025 <div class="method-source-code"
1026 id="batch-sleep-time--source">
1028 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 615</span>
1029 615: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">batch_sleep_time=</span>(<span class="ruby-identifier">time</span>)
1030 616: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can only set batch sleep time if direct addressing is supported"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1032 618: <span class="ruby-ivar">@batch_sleep_time</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">time</span>)
1033 619: <span class="ruby-keyword kw">end</span></pre>
1042 <div id="call-agent-method" class="method-detail ">
1043 <a name="M000480"></a>
1045 <div class="method-heading">
1047 <span class="method-name">call_agent</span><span
1048 class="method-args">(action, args, opts, disc=:auto, &block)</span>
1049 <span class="method-click-advice">click to toggle source</span>
1053 <div class="method-description">
1056 Handles traditional calls to the remote agents with full stats blocks, non
1057 blocks and everything else supported.
1060 Other methods of calling the nodes can reuse this code by for example
1061 specifying custom options and discovery data
1066 <div class="method-source-code"
1067 id="call-agent-source">
1069 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 844</span>
1070 844: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-identifier">disc</span>=<span class="ruby-identifier">:auto</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1071 845: <span class="ruby-comment cmt"># Handle fire and forget requests and make sure</span>
1072 846: <span class="ruby-comment cmt"># the :process_results value is set appropriately</span>
1073 847: <span class="ruby-comment cmt">#</span>
1074 848: <span class="ruby-comment cmt"># specific reply-to requests should be treated like</span>
1075 849: <span class="ruby-comment cmt"># fire and forget since the client will never get</span>
1076 850: <span class="ruby-comment cmt"># the responses</span>
1077 851: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@reply_to</span>
1078 852: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">fire_and_forget_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
1079 853: <span class="ruby-keyword kw">else</span>
1080 854: <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] = <span class="ruby-keyword kw">true</span>
1081 855: <span class="ruby-keyword kw">end</span>
1083 857: <span class="ruby-comment cmt"># Do discovery when no specific discovery array is given</span>
1084 858: <span class="ruby-comment cmt">#</span>
1085 859: <span class="ruby-comment cmt"># If an array is given set the force_direct_request hint that</span>
1086 860: <span class="ruby-comment cmt"># will tell the message object to be a direct request one</span>
1087 861: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">disc</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:auto</span>
1088 862: <span class="ruby-identifier">discovered</span> = <span class="ruby-identifier">discover</span>
1089 863: <span class="ruby-keyword kw">else</span>
1090 864: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1091 865: <span class="ruby-identifier">discovered</span> = <span class="ruby-identifier">disc</span>
1092 866: <span class="ruby-keyword kw">end</span>
1094 868: <span class="ruby-identifier">req</span> = <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">args</span>)
1096 870: <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-keyword kw">nil</span>, {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:request</span>, <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>, <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:filter</span>], <span class="ruby-identifier">:options</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>})
1097 871: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">discovered_hosts</span> = <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">clone</span>
1099 873: <span class="ruby-identifier">results</span> = []
1100 874: <span class="ruby-identifier">respcount</span> = <span class="ruby-value">0</span>
1102 876: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
1103 877: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">type</span> = <span class="ruby-identifier">:direct_request</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@force_direct_request</span>
1105 879: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">block_given?</span>
1106 880: <span class="ruby-identifier">twirl</span> = <span class="ruby-constant">Progress</span>.<span class="ruby-identifier">new</span>
1107 881: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">puts</span>
1108 882: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>)
1109 883: <span class="ruby-keyword kw">end</span>
1111 885: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">load_aggregate_functions</span>(<span class="ruby-identifier">action</span>, <span class="ruby-ivar">@ddl</span>)
1113 887: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">req</span>(<span class="ruby-identifier">message</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">resp</span><span class="ruby-operator">|</span>
1114 888: <span class="ruby-identifier">respcount</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
1116 890: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
1117 891: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_with_block</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">block</span>, <span class="ruby-identifier">aggregate</span>)
1118 892: <span class="ruby-keyword kw">else</span>
1119 893: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
1121 895: <span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_without_block</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">aggregate</span>)
1123 897: <span class="ruby-identifier">results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">result</span>
1124 898: <span class="ruby-keyword kw">end</span>
1125 899: <span class="ruby-keyword kw">end</span>
1127 901: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_summary</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">summarize</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
1128 902: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_failures</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">failed</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
1129 903: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">client_stats</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>
1130 904: <span class="ruby-keyword kw">else</span>
1131 905: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\nNo request sent, we did not discover any nodes."</span>)
1132 906: <span class="ruby-keyword kw">end</span>
1134 908: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">finish_request</span>
1136 910: <span class="ruby-constant">RPC</span>.<span class="ruby-identifier">stats</span>(<span class="ruby-ivar">@stats</span>)
1138 912: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\n\n"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
1140 914: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
1141 915: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">stats</span>
1142 916: <span class="ruby-keyword kw">else</span>
1143 917: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">results</span>].<span class="ruby-identifier">flatten</span>
1144 918: <span class="ruby-keyword kw">end</span>
1145 919: <span class="ruby-keyword kw">end</span></pre>
1154 <div id="call-agent-batched-method" class="method-detail ">
1155 <a name="M000479"></a>
1157 <div class="method-heading">
1159 <span class="method-name">call_agent_batched</span><span
1160 class="method-args">(action, args, opts, batch_size, sleep_time, &block)</span>
1161 <span class="method-click-advice">click to toggle source</span>
1165 <div class="method-description">
1168 Calls an agent in a way very similar to <a
1169 href="Client.html#M000480">call_agent</a> but it supports batching the
1170 queries to the network.
1173 The result sets, stats, block handling etc is all exactly like you would
1174 expect from normal call_agent.
1177 This is used by <a href="Client.html#M000452">method_missing</a> and works
1178 only with direct addressing mode
1183 <div class="method-source-code"
1184 id="call-agent-batched-source">
1186 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 759</span>
1187 759: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">call_agent_batched</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">opts</span>, <span class="ruby-identifier">batch_size</span>, <span class="ruby-identifier">sleep_time</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1188 760: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Batched requests requires direct addressing"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1189 761: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Cannot bypass result processing for batched requests"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1191 763: <span class="ruby-identifier">batch_size</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">batch_size</span>)
1192 764: <span class="ruby-identifier">sleep_time</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">sleep_time</span>)
1194 766: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Calling #{agent}##{action} in batches of #{batch_size} with sleep time of #{sleep_time}"</span>)
1196 768: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span>
1198 770: <span class="ruby-identifier">discovered</span> = <span class="ruby-identifier">discover</span>
1199 771: <span class="ruby-identifier">results</span> = []
1200 772: <span class="ruby-identifier">respcount</span> = <span class="ruby-value">0</span>
1202 774: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
1203 775: <span class="ruby-identifier">req</span> = <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">args</span>)
1205 777: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">load_aggregate_functions</span>(<span class="ruby-identifier">action</span>, <span class="ruby-ivar">@ddl</span>)
1207 779: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">block_given?</span>
1208 780: <span class="ruby-identifier">twirl</span> = <span class="ruby-constant">Progress</span>.<span class="ruby-identifier">new</span>
1209 781: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">puts</span>
1210 782: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>)
1211 783: <span class="ruby-keyword kw">end</span>
1213 785: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span> = <span class="ruby-keyword kw">nil</span>
1215 787: <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">in_groups_of</span>(<span class="ruby-identifier">batch_size</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">hosts</span>, <span class="ruby-identifier">last_batch</span><span class="ruby-operator">|</span>
1216 788: <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-keyword kw">nil</span>, {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:direct_request</span>, <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>, <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:filter</span>], <span class="ruby-identifier">:options</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">opts</span>})
1218 790: <span class="ruby-comment cmt"># first time round we let the Message object create a request id</span>
1219 791: <span class="ruby-comment cmt"># we then re-use it for future requests to keep auditing sane etc</span>
1220 792: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span> = <span class="ruby-identifier">message</span>.<span class="ruby-identifier">create_reqid</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span>
1221 793: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">requestid</span> = <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">requestid</span>
1223 795: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">discovered_hosts</span> = <span class="ruby-identifier">hosts</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">compact</span>
1225 797: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">req</span>(<span class="ruby-identifier">message</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">resp</span><span class="ruby-operator">|</span>
1226 798: <span class="ruby-identifier">respcount</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
1228 800: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
1229 801: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_with_block</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">block</span>, <span class="ruby-identifier">aggregate</span>)
1230 802: <span class="ruby-keyword kw">else</span>
1231 803: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-identifier">twirl</span>.<span class="ruby-identifier">twirl</span>(<span class="ruby-identifier">respcount</span>, <span class="ruby-identifier">discovered</span>.<span class="ruby-identifier">size</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
1233 805: <span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">process_results_without_block</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">aggregate</span>)
1235 807: <span class="ruby-identifier">results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">result</span>
1236 808: <span class="ruby-keyword kw">end</span>
1237 809: <span class="ruby-keyword kw">end</span>
1239 811: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">noresponsefrom</span>.<span class="ruby-identifier">concat</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:noresponsefrom</span>]
1240 812: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">responses</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:responses</span>]
1241 813: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">blocktime</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:blocktime</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">sleep_time</span>
1242 814: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">totaltime</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:totaltime</span>]
1243 815: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">discoverytime</span> <span class="ruby-operator">+=</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">stats</span>[<span class="ruby-identifier">:discoverytime</span>]
1245 817: <span class="ruby-identifier">sleep</span> <span class="ruby-identifier">sleep_time</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">last_batch</span>
1246 818: <span class="ruby-keyword kw">end</span>
1248 820: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_summary</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">summarize</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
1249 821: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">aggregate_failures</span> = <span class="ruby-identifier">aggregate</span>.<span class="ruby-identifier">failed</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
1250 822: <span class="ruby-keyword kw">else</span>
1251 823: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\nNo request sent, we did not discover any nodes."</span>)
1252 824: <span class="ruby-keyword kw">end</span>
1254 826: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">finish_request</span>
1256 828: <span class="ruby-constant">RPC</span>.<span class="ruby-identifier">stats</span>(<span class="ruby-ivar">@stats</span>)
1258 830: <span class="ruby-ivar">@stdout</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"\n"</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@progress</span>
1260 832: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
1261 833: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">stats</span>
1262 834: <span class="ruby-keyword kw">else</span>
1263 835: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">results</span>].<span class="ruby-identifier">flatten</span>
1264 836: <span class="ruby-keyword kw">end</span>
1265 837: <span class="ruby-keyword kw">end</span></pre>
1274 <div id="class-filter-method" class="method-detail ">
1275 <a name="M000459"></a>
1277 <div class="method-heading">
1279 <span class="method-name">class_filter</span><span
1280 class="method-args">(klass)</span>
1281 <span class="method-click-advice">click to toggle source</span>
1285 <div class="method-description">
1288 Sets the class filter
1293 <div class="method-source-code"
1294 id="class-filter-source">
1296 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 398</span>
1297 398: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_filter</span>(<span class="ruby-identifier">klass</span>)
1298 399: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"cf_class"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"cf_class"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">klass</span>]
1299 400: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"cf_class"</span>].<span class="ruby-identifier">compact!</span>
1300 401: <span class="ruby-identifier">reset</span>
1301 402: <span class="ruby-keyword kw">end</span></pre>
1310 <div id="collective--method" class="method-detail ">
1311 <a name="M000468"></a>
1313 <div class="method-heading">
1315 <span class="method-name">collective=</span><span
1316 class="method-args">(c)</span>
1317 <span class="method-click-advice">click to toggle source</span>
1321 <div class="method-description">
1324 Sets the collective we are communicating with
1329 <div class="method-source-code"
1330 id="collective--source">
1332 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 573</span>
1333 573: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">collective=</span>(<span class="ruby-identifier">c</span>)
1334 574: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown collective #{c}"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">collectives</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">c</span>)
1336 576: <span class="ruby-ivar">@collective</span> = <span class="ruby-identifier">c</span>
1337 577: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
1338 578: <span class="ruby-identifier">reset</span>
1339 579: <span class="ruby-keyword kw">end</span></pre>
1348 <div id="compound-filter-method" class="method-detail ">
1349 <a name="M000463"></a>
1351 <div class="method-heading">
1353 <span class="method-name">compound_filter</span><span
1354 class="method-args">(filter)</span>
1355 <span class="method-click-advice">click to toggle source</span>
1359 <div class="method-description">
1362 Set a compound filter
1367 <div class="method-source-code"
1368 id="compound-filter-source">
1370 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 436</span>
1371 436: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compound_filter</span>(<span class="ruby-identifier">filter</span>)
1372 437: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"compound"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"compound"</span>] <span class="ruby-operator">|</span> [<span class="ruby-constant">Matcher</span>.<span class="ruby-identifier">create_compound_callstack</span>(<span class="ruby-identifier">filter</span>)]
1373 438: <span class="ruby-identifier">reset</span>
1374 439: <span class="ruby-keyword kw">end</span></pre>
1383 <div id="custom-request-method" class="method-detail ">
1384 <a name="M000454"></a>
1386 <div class="method-heading">
1388 <span class="method-name">custom_request</span><span
1389 class="method-args">(action, args, expected_agents, filter = {}, &block)</span>
1390 <span class="method-click-advice">click to toggle source</span>
1394 <div class="method-description">
1397 Constructs custom requests with custom filters and discovery data the idea
1398 is that this would be used in web applications where you might be using a
1399 cached copy of data provided by a registration agent to figure out on your
1400 own what nodes will be responding and what your filter would be.
1403 This will help you essentially short circuit the traditional cycle of:
1406 mc discover / call / wait for discovered nodes
1409 by doing discovery however you like, contructing a filter and a list of
1410 nodes you expect responses from.
1413 Other than that it will work exactly like a normal call, blocks will behave
1414 the same way, stats will be handled the same way etcetc
1417 If you just wanted to contact one machine for example with a client that
1418 already has other filter options setup you can do:
1421 puppet.custom_request(“runonce”, {},
1422 [“your.box.com“], {:identity => “your.box.com“})
1425 This will do runonce action on just ‘your.box.com’, no
1426 discovery will be done and after receiving just one response it will stop
1427 waiting for responses
1430 If direct_addressing is enabled in the config file you can provide an empty
1431 hash as a filter, this will force that request to be a directly addressed
1432 request which technically does not need filters. If you try to use this
1433 mode with direct addressing disabled an exception will be raise
1438 <div class="method-source-code"
1439 id="custom-request-source">
1441 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 296</span>
1442 296: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">custom_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">expected_agents</span>, <span class="ruby-identifier">filter</span> = {}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
1443 297: <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
1445 299: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">filter</span> <span class="ruby-operator">==</span> {} <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1446 300: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Attempted to do a filterless custom_request without direct_addressing enabled, preventing unexpected call to all nodes"</span>
1447 301: <span class="ruby-keyword kw">end</span>
1449 303: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">reset</span>
1451 305: <span class="ruby-identifier">custom_filter</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">empty_filter</span>
1452 306: <span class="ruby-identifier">custom_options</span> = <span class="ruby-identifier">options</span>.<span class="ruby-identifier">clone</span>
1454 308: <span class="ruby-comment cmt"># merge the supplied filter with the standard empty one</span>
1455 309: <span class="ruby-comment cmt"># we could just use the merge method but I want to be sure</span>
1456 310: <span class="ruby-comment cmt"># we dont merge in stuff that isnt actually valid</span>
1457 311: [<span class="ruby-value str">"identity"</span>, <span class="ruby-value str">"fact"</span>, <span class="ruby-value str">"agent"</span>, <span class="ruby-value str">"cf_class"</span>, <span class="ruby-value str">"compound"</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ftype</span><span class="ruby-operator">|</span>
1458 312: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">filter</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">ftype</span>)
1459 313: <span class="ruby-identifier">custom_filter</span>[<span class="ruby-identifier">ftype</span>] = [<span class="ruby-identifier">filter</span>[<span class="ruby-identifier">ftype</span>], <span class="ruby-identifier">custom_filter</span>[<span class="ruby-identifier">ftype</span>]].<span class="ruby-identifier">flatten</span>
1460 314: <span class="ruby-keyword kw">end</span>
1461 315: <span class="ruby-keyword kw">end</span>
1463 317: <span class="ruby-comment cmt"># ensure that all filters at least restrict the call to the agent we're a proxy for</span>
1464 318: <span class="ruby-identifier">custom_filter</span>[<span class="ruby-value str">"agent"</span>] <span class="ruby-operator"><<</span> <span class="ruby-ivar">@agent</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">custom_filter</span>[<span class="ruby-value str">"agent"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-ivar">@agent</span>)
1465 319: <span class="ruby-identifier">custom_options</span>[<span class="ruby-identifier">:filter</span>] = <span class="ruby-identifier">custom_filter</span>
1467 321: <span class="ruby-comment cmt"># Fake out the stats discovery would have put there</span>
1468 322: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">discovered_agents</span>([<span class="ruby-identifier">expected_agents</span>].<span class="ruby-identifier">flatten</span>)
1470 324: <span class="ruby-comment cmt"># Handle fire and forget requests</span>
1471 325: <span class="ruby-comment cmt">#</span>
1472 326: <span class="ruby-comment cmt"># If a specific reply-to was set then from the client perspective this should</span>
1473 327: <span class="ruby-comment cmt"># be a fire and forget request too since no response will ever reach us - it</span>
1474 328: <span class="ruby-comment cmt"># will go to the reply-to destination</span>
1475 329: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-identifier">:process_results</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@reply_to</span>
1476 330: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">fire_and_forget_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">custom_filter</span>)
1477 331: <span class="ruby-keyword kw">end</span>
1479 333: <span class="ruby-comment cmt"># Now do a call pretty much exactly like in method_missing except with our own</span>
1480 334: <span class="ruby-comment cmt"># options and discovery magic</span>
1481 335: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
1482 336: <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">custom_options</span>, [<span class="ruby-identifier">expected_agents</span>].<span class="ruby-identifier">flatten</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">r</span><span class="ruby-operator">|</span>
1483 337: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">r</span>)
1484 338: <span class="ruby-keyword kw">end</span>
1485 339: <span class="ruby-keyword kw">else</span>
1486 340: <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">custom_options</span>, [<span class="ruby-identifier">expected_agents</span>].<span class="ruby-identifier">flatten</span>)
1487 341: <span class="ruby-keyword kw">end</span>
1488 342: <span class="ruby-keyword kw">end</span></pre>
1497 <div id="disconnect-method" class="method-detail ">
1498 <a name="M000446"></a>
1500 <div class="method-heading">
1502 <span class="method-name">disconnect</span><span
1503 class="method-args">()</span>
1504 <span class="method-click-advice">click to toggle source</span>
1508 <div class="method-description">
1511 Disconnects cleanly from the middleware
1516 <div class="method-source-code"
1517 id="disconnect-source">
1519 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 121</span>
1520 121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">disconnect</span>
1521 122: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">disconnect</span>
1522 123: <span class="ruby-keyword kw">end</span></pre>
1531 <div id="discover-method" class="method-detail ">
1532 <a name="M000466"></a>
1534 <div class="method-heading">
1536 <span class="method-name">discover</span><span
1537 class="method-args">(flags={})</span>
1538 <span class="method-click-advice">click to toggle source</span>
1542 <div class="method-description">
1545 Does discovery based on the filters set, if a discovery was previously done
1546 return that else do a new discovery.
1549 Alternatively if identity filters are given and none of them are regular
1550 expressions then just use the provided data as discovered data, avoiding
1554 <a href="../Discovery.html">Discovery</a> can be forced if
1555 direct_addressing is enabled by passing in an array of nodes with :nodes or
1556 JSON data like those produced by mcollective <a href="../RPC.html">RPC</a>
1557 JSON output using :json
1560 Will show a message indicating its doing discovery if running verbose or if
1561 the :verbose flag is passed in.
1564 Use reset to force a new discovery
1569 <div class="method-source-code"
1570 id="discover-source">
1572 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 468</span>
1573 468: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discover</span>(<span class="ruby-identifier">flags</span>={})
1574 469: <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
1575 470: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown option #{key} passed to discover"</span> <span class="ruby-keyword kw">unless</span> [<span class="ruby-identifier">:verbose</span>, <span class="ruby-identifier">:hosts</span>, <span class="ruby-identifier">:nodes</span>, <span class="ruby-identifier">:json</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">key</span>)
1576 471: <span class="ruby-keyword kw">end</span>
1578 473: <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:verbose</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">verbose</span> = <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:verbose</span>] <span class="ruby-operator">:</span> <span class="ruby-identifier">verbose</span> = <span class="ruby-ivar">@verbose</span>
1580 475: <span class="ruby-identifier">verbose</span> = <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@output_format</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:console</span>
1582 477: <span class="ruby-comment cmt"># flags[:nodes] and flags[:hosts] are the same thing, we should never have</span>
1583 478: <span class="ruby-comment cmt"># allowed :hosts as that was inconsistent with the established terminology</span>
1584 479: <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>] = <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:hosts</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:hosts</span>)
1586 481: <span class="ruby-identifier">reset</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>]
1588 483: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@discovered_agents</span>
1589 484: <span class="ruby-comment cmt"># if either hosts or JSON is supplied try to figure out discovery data from there</span>
1590 485: <span class="ruby-comment cmt"># if direct_addressing is not enabled this is a critical error as the user might</span>
1591 486: <span class="ruby-comment cmt"># not have supplied filters so raise an exception</span>
1592 487: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>]
1593 488: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can only supply discovery data if direct_addressing is enabled"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
1595 490: <span class="ruby-identifier">hosts</span> = []
1597 492: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>]
1598 493: <span class="ruby-identifier">hosts</span> = <span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">extract_hosts_from_array</span>(<span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:nodes</span>])
1599 494: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>]
1600 495: <span class="ruby-identifier">hosts</span> = <span class="ruby-constant">Helpers</span>.<span class="ruby-identifier">extract_hosts_from_json</span>(<span class="ruby-identifier">flags</span>[<span class="ruby-identifier">:json</span>])
1601 496: <span class="ruby-keyword kw">end</span>
1603 498: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Could not find any hosts in discovery data provided"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hosts</span>.<span class="ruby-identifier">empty?</span>
1605 500: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-identifier">hosts</span>
1606 501: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span>
1608 503: <span class="ruby-keyword kw">else</span>
1609 504: <span class="ruby-identifier">identity_filter_discovery_optimization</span>
1610 505: <span class="ruby-keyword kw">end</span>
1611 506: <span class="ruby-keyword kw">end</span>
1613 508: <span class="ruby-comment cmt"># All else fails we do it the hard way using a traditional broadcast</span>
1614 509: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@discovered_agents</span>
1615 510: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_discovery</span> <span class="ruby-identifier">:start</span>
1617 512: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
1619 514: <span class="ruby-comment cmt"># if compound filters are used the only real option is to use the mc</span>
1620 515: <span class="ruby-comment cmt"># discovery plugin since its the only capable of using data queries etc</span>
1621 516: <span class="ruby-comment cmt"># and we do not want to degrade that experience just to allow compounds</span>
1622 517: <span class="ruby-comment cmt"># on other discovery plugins the UX would be too bad raising complex sets</span>
1623 518: <span class="ruby-comment cmt"># of errors etc.</span>
1624 519: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">force_discovery_method_by_filter</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>])
1626 521: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">verbose</span>
1627 522: <span class="ruby-identifier">actual_timeout</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">discovery_timeout</span>(<span class="ruby-identifier">discovery_timeout</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>])
1629 524: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">actual_timeout</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
1630 525: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"Discovering hosts using the %s method for %d second(s) .... "</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">discovery_method</span>, <span class="ruby-identifier">actual_timeout</span>])
1631 526: <span class="ruby-keyword kw">else</span>
1632 527: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">print</span>(<span class="ruby-value str">"Discovering hosts using the %s method .... "</span> <span class="ruby-operator">%</span> [<span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">discovery_method</span>])
1633 528: <span class="ruby-keyword kw">end</span>
1634 529: <span class="ruby-keyword kw">end</span>
1636 531: <span class="ruby-comment cmt"># if the requested limit is a pure number and not a percent</span>
1637 532: <span class="ruby-comment cmt"># and if we're configured to use the first found hosts as the</span>
1638 533: <span class="ruby-comment cmt"># limit method then pass in the limit thus minimizing the amount</span>
1639 534: <span class="ruby-comment cmt"># of work we do in the discover phase and speeding it up significantly</span>
1640 535: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_method</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:first</span> <span class="ruby-keyword kw">and</span> <span class="ruby-ivar">@limit_targets</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Fixnum</span>)
1641 536: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discover</span>(<span class="ruby-ivar">@filter</span>, <span class="ruby-identifier">discovery_timeout</span>, <span class="ruby-ivar">@limit_targets</span>)
1642 537: <span class="ruby-keyword kw">else</span>
1643 538: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discover</span>(<span class="ruby-ivar">@filter</span>, <span class="ruby-identifier">discovery_timeout</span>)
1644 539: <span class="ruby-keyword kw">end</span>
1646 541: <span class="ruby-ivar">@stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-ivar">@discovered_agents</span>.<span class="ruby-identifier">size</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">verbose</span>
1648 543: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">force_direct_mode?</span>
1650 545: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_discovery</span> <span class="ruby-identifier">:end</span>
1651 546: <span class="ruby-keyword kw">end</span>
1653 548: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">discovered_agents</span>(<span class="ruby-ivar">@discovered_agents</span>)
1654 549: <span class="ruby-constant">RPC</span>.<span class="ruby-identifier">discovered</span>(<span class="ruby-ivar">@discovered_agents</span>)
1656 551: <span class="ruby-ivar">@discovered_agents</span>
1657 552: <span class="ruby-keyword kw">end</span></pre>
1666 <div id="discovery-method--method" class="method-detail ">
1667 <a name="M000457"></a>
1669 <div class="method-heading">
1671 <span class="method-name">discovery_method=</span><span
1672 class="method-args">(method)</span>
1673 <span class="method-click-advice">click to toggle source</span>
1677 <div class="method-description">
1680 Sets the discovery method. If we change the method there are a number of
1684 - set the new method
1685 - if discovery options were provided, re-set those to initially
1686 provided ones else clear them as they might now apply to a
1688 - update the client options so it knows there is a new discovery
1690 - reset discovery data forcing a discover on the next request
1693 The remaining item is the discovery timeout, we leave that as is since that
1694 is the user supplied timeout either via initial options or via specifically
1695 setting it on the client.
1700 <div class="method-source-code"
1701 id="discovery-method--source">
1703 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 377</span>
1704 377: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_method=</span>(<span class="ruby-identifier">method</span>)
1705 378: <span class="ruby-ivar">@default_discovery_method</span> = <span class="ruby-keyword kw">false</span>
1706 379: <span class="ruby-ivar">@discovery_method</span> = <span class="ruby-identifier">method</span>
1708 381: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@initial_options</span>[<span class="ruby-identifier">:discovery_options</span>]
1709 382: <span class="ruby-ivar">@discovery_options</span> = <span class="ruby-ivar">@initial_options</span>[<span class="ruby-identifier">:discovery_options</span>]
1710 383: <span class="ruby-keyword kw">else</span>
1711 384: <span class="ruby-ivar">@discovery_options</span>.<span class="ruby-identifier">clear</span>
1712 385: <span class="ruby-keyword kw">end</span>
1714 387: <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">options</span> = <span class="ruby-identifier">options</span>
1716 389: <span class="ruby-identifier">reset</span>
1717 390: <span class="ruby-keyword kw">end</span></pre>
1726 <div id="discovery-options--method" class="method-detail ">
1727 <a name="M000458"></a>
1729 <div class="method-heading">
1731 <span class="method-name">discovery_options=</span><span
1732 class="method-args">(options)</span>
1733 <span class="method-click-advice">click to toggle source</span>
1737 <div class="method-description">
1739 <p class="missing-docs">(Not documented)</p>
1743 <div class="method-source-code"
1744 id="discovery-options--source">
1746 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 392</span>
1747 392: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_options=</span>(<span class="ruby-identifier">options</span>)
1748 393: <span class="ruby-ivar">@discovery_options</span> = [<span class="ruby-identifier">options</span>].<span class="ruby-identifier">flatten</span>
1749 394: <span class="ruby-identifier">reset</span>
1750 395: <span class="ruby-keyword kw">end</span></pre>
1759 <div id="discovery-timeout-method" class="method-detail ">
1760 <a name="M000455"></a>
1762 <div class="method-heading">
1764 <span class="method-name">discovery_timeout</span><span
1765 class="method-args">()</span>
1766 <span class="method-click-advice">click to toggle source</span>
1770 <div class="method-description">
1772 <p class="missing-docs">(Not documented)</p>
1776 <div class="method-source-code"
1777 id="discovery-timeout-source">
1779 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 344</span>
1780 344: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_timeout</span>
1781 345: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@discovery_timeout</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@discovery_timeout</span>
1782 346: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">ddl</span>.<span class="ruby-identifier">meta</span>[<span class="ruby-identifier">:timeout</span>]
1783 347: <span class="ruby-keyword kw">end</span></pre>
1792 <div id="discovery-timeout--method" class="method-detail ">
1793 <a name="M000456"></a>
1795 <div class="method-heading">
1797 <span class="method-name">discovery_timeout=</span><span
1798 class="method-args">(timeout)</span>
1799 <span class="method-click-advice">click to toggle source</span>
1803 <div class="method-description">
1805 <p class="missing-docs">(Not documented)</p>
1809 <div class="method-source-code"
1810 id="discovery-timeout--source">
1812 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 349</span>
1813 349: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">discovery_timeout=</span>(<span class="ruby-identifier">timeout</span>)
1814 350: <span class="ruby-ivar">@discovery_timeout</span> = <span class="ruby-constant">Float</span>(<span class="ruby-identifier">timeout</span>)
1816 352: <span class="ruby-comment cmt"># we calculate the overall timeout from the DDL of the agent and</span>
1817 353: <span class="ruby-comment cmt"># the supplied discovery timeout unless someone specifically</span>
1818 354: <span class="ruby-comment cmt"># specifies a timeout to the constructor</span>
1819 355: <span class="ruby-comment cmt">#</span>
1820 356: <span class="ruby-comment cmt"># But if we also then specifically set a discovery_timeout on the</span>
1821 357: <span class="ruby-comment cmt"># agent that has to override the supplied timeout so we then</span>
1822 358: <span class="ruby-comment cmt"># calculate a correct timeout based on DDL timeout and the</span>
1823 359: <span class="ruby-comment cmt"># supplied discovery timeout</span>
1824 360: <span class="ruby-ivar">@timeout</span> = <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">meta</span>[<span class="ruby-identifier">:timeout</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">discovery_timeout</span>
1825 361: <span class="ruby-keyword kw">end</span></pre>
1834 <div id="fact-filter-method" class="method-detail ">
1835 <a name="M000460"></a>
1837 <div class="method-heading">
1839 <span class="method-name">fact_filter</span><span
1840 class="method-args">(fact, value=nil, operator="=")</span>
1841 <span class="method-click-advice">click to toggle source</span>
1845 <div class="method-description">
1848 Sets the fact filter
1853 <div class="method-source-code"
1854 id="fact-filter-source">
1856 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 405</span>
1857 405: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fact_filter</span>(<span class="ruby-identifier">fact</span>, <span class="ruby-identifier">value</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">operator</span>=<span class="ruby-value str">"="</span>)
1858 406: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fact</span>.<span class="ruby-identifier">nil?</span>
1859 407: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">fact</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1861 409: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
1862 410: <span class="ruby-identifier">parsed</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">parse_fact_string</span>(<span class="ruby-identifier">fact</span>)
1863 411: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">parsed</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">parsed</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1864 412: <span class="ruby-keyword kw">else</span>
1865 413: <span class="ruby-identifier">parsed</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">parse_fact_string</span>(<span class="ruby-node">"#{fact}#{operator}#{value}"</span>)
1866 414: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">parsed</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">parsed</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span>
1867 415: <span class="ruby-keyword kw">end</span>
1869 417: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"fact"</span>].<span class="ruby-identifier">compact!</span>
1870 418: <span class="ruby-identifier">reset</span>
1871 419: <span class="ruby-keyword kw">end</span></pre>
1880 <div id="fire-and-forget-request-method" class="method-detail ">
1881 <a name="M000477"></a>
1883 <div class="method-heading">
1885 <span class="method-name">fire_and_forget_request</span><span
1886 class="method-args">(action, args, filter=nil)</span>
1887 <span class="method-click-advice">click to toggle source</span>
1891 <div class="method-description">
1894 for requests that do not care for results just return the request id and
1895 don’t do any of the response processing.
1898 We send the :process_results flag with to the nodes so they can make
1899 decisions based on that.
1902 Should only be called via <a href="Client.html#M000452">method_missing</a>
1907 <div class="method-source-code"
1908 id="fire-and-forget-request-source">
1910 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 710</span>
1911 710: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fire_and_forget_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">filter</span>=<span class="ruby-keyword kw">nil</span>)
1912 711: <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
1914 713: <span class="ruby-identifier">identity_filter_discovery_optimization</span>
1916 715: <span class="ruby-identifier">req</span> = <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">args</span>)
1918 717: <span class="ruby-identifier">filter</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">filter</span>
1920 719: <span class="ruby-identifier">message</span> = <span class="ruby-constant">Message</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">req</span>, <span class="ruby-keyword kw">nil</span>, {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">:request</span>, <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>, <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">filter</span>, <span class="ruby-identifier">:options</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">options</span>})
1921 720: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">reply_to</span> = <span class="ruby-ivar">@reply_to</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@reply_to</span>
1923 722: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@force_direct_request</span> <span class="ruby-operator">||</span> <span class="ruby-ivar">@client</span>.<span class="ruby-identifier">discoverer</span>.<span class="ruby-identifier">force_direct_mode?</span>
1924 723: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">discovered_hosts</span> = <span class="ruby-identifier">discover</span>.<span class="ruby-identifier">clone</span>
1925 724: <span class="ruby-identifier">message</span>.<span class="ruby-identifier">type</span> = <span class="ruby-identifier">:direct_request</span>
1926 725: <span class="ruby-keyword kw">end</span>
1928 727: <span class="ruby-identifier">client</span>.<span class="ruby-identifier">sendreq</span>(<span class="ruby-identifier">message</span>, <span class="ruby-keyword kw">nil</span>)
1929 728: <span class="ruby-keyword kw">end</span></pre>
1938 <div id="help-method" class="method-detail ">
1939 <a name="M000447"></a>
1941 <div class="method-heading">
1943 <span class="method-name">help</span><span
1944 class="method-args">(template)</span>
1945 <span class="method-click-advice">click to toggle source</span>
1949 <div class="method-description">
1952 Returns help for an agent if a <a href="../DDL.html">DDL</a> was found
1957 <div class="method-source-code"
1960 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 126</span>
1961 126: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">help</span>(<span class="ruby-identifier">template</span>)
1962 127: <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">help</span>(<span class="ruby-identifier">template</span>)
1963 128: <span class="ruby-keyword kw">end</span></pre>
1972 <div id="identity-filter-method" class="method-detail ">
1973 <a name="M000462"></a>
1975 <div class="method-heading">
1977 <span class="method-name">identity_filter</span><span
1978 class="method-args">(identity)</span>
1979 <span class="method-click-advice">click to toggle source</span>
1983 <div class="method-description">
1986 Sets the identity filter
1991 <div class="method-source-code"
1992 id="identity-filter-source">
1994 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 429</span>
1995 429: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identity_filter</span>(<span class="ruby-identifier">identity</span>)
1996 430: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"identity"</span>] = <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"identity"</span>] <span class="ruby-operator">|</span> [<span class="ruby-identifier">identity</span>]
1997 431: <span class="ruby-ivar">@filter</span>[<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">compact!</span>
1998 432: <span class="ruby-identifier">reset</span>
1999 433: <span class="ruby-keyword kw">end</span></pre>
2008 <div id="identity-filter-discovery-optimization-method" class="method-detail ">
2009 <a name="M000478"></a>
2011 <div class="method-heading">
2013 <span class="method-name">identity_filter_discovery_optimization</span><span
2014 class="method-args">()</span>
2015 <span class="method-click-advice">click to toggle source</span>
2019 <div class="method-description">
2022 if an identity filter is supplied and it is all strings no regex we can use
2023 that as discovery data, technically the identity filter is then redundant
2024 if we are in direct addressing mode and we could empty it out but this use
2025 case should only really be for a few -I’s on the CLI
2028 For safety we leave the filter in place for now, that way we can support
2029 this enhancement also in broadcast mode.
2032 This is only needed for the ‘mc’ discovery method, other
2033 methods might change the concept of identity to mean something else so we
2034 should pass the full identity filter to them
2039 <div class="method-source-code"
2040 id="identity-filter-discovery-optimization-source">
2042 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 741</span>
2043 741: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">identity_filter_discovery_optimization</span>
2044 742: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>][<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span> <span class="ruby-operator">&&</span> <span class="ruby-ivar">@discovery_method</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"mc"</span>
2045 743: <span class="ruby-identifier">regex_filters</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>][<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">select</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">match</span>(<span class="ruby-value str">"^\/"</span>)}.<span class="ruby-identifier">size</span>
2047 745: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">regex_filters</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
2048 746: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:filter</span>][<span class="ruby-value str">"identity"</span>].<span class="ruby-identifier">clone</span>
2049 747: <span class="ruby-ivar">@force_direct_request</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">direct_addressing</span>
2050 748: <span class="ruby-keyword kw">end</span>
2051 749: <span class="ruby-keyword kw">end</span>
2052 750: <span class="ruby-keyword kw">end</span></pre>
2061 <div id="limit-method--method" class="method-detail ">
2062 <a name="M000470"></a>
2064 <div class="method-heading">
2066 <span class="method-name">limit_method=</span><span
2067 class="method-args">(method)</span>
2068 <span class="method-click-advice">click to toggle source</span>
2072 <div class="method-description">
2075 Sets and sanity check the <a
2076 href="Client.html#limit_method">limit_method</a> variable used to determine
2077 how to limit targets if <a
2078 href="Client.html#limit_targets">limit_targets</a> is set
2083 <div class="method-source-code"
2084 id="limit-method--source">
2086 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 599</span>
2087 599: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">limit_method=</span>(<span class="ruby-identifier">method</span>)
2088 600: <span class="ruby-identifier">method</span> = <span class="ruby-identifier">method</span>.<span class="ruby-identifier">to_sym</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">method</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>)
2090 602: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Unknown limit method #{method} must be :random or :first"</span> <span class="ruby-keyword kw">unless</span> [<span class="ruby-identifier">:random</span>, <span class="ruby-identifier">:first</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">method</span>)
2092 604: <span class="ruby-ivar">@limit_method</span> = <span class="ruby-identifier">method</span>
2093 605: <span class="ruby-keyword kw">end</span></pre>
2102 <div id="limit-targets--method" class="method-detail ">
2103 <a name="M000469"></a>
2105 <div class="method-heading">
2107 <span class="method-name">limit_targets=</span><span
2108 class="method-args">(limit)</span>
2109 <span class="method-click-advice">click to toggle source</span>
2113 <div class="method-description">
2116 Sets and sanity checks the <a
2117 href="Client.html#limit_targets">limit_targets</a> variable used to
2118 restrict how many nodes we’ll target
2123 <div class="method-source-code"
2124 id="limit-targets--source">
2126 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 583</span>
2127 583: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">limit_targets=</span>(<span class="ruby-identifier">limit</span>)
2128 584: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">limit</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">String</span>)
2129 585: <span class="ruby-identifier">raise</span> <span class="ruby-node">"Invalid limit specified: #{limit} valid limits are /^\d+%*$/"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">limit</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+%*$/</span>
2131 587: <span class="ruby-keyword kw">begin</span>
2132 588: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">limit</span>)
2133 589: <span class="ruby-keyword kw">rescue</span>
2134 590: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-identifier">limit</span>
2135 591: <span class="ruby-keyword kw">end</span>
2136 592: <span class="ruby-keyword kw">else</span>
2137 593: <span class="ruby-ivar">@limit_targets</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">limit</span>)
2138 594: <span class="ruby-keyword kw">end</span>
2139 595: <span class="ruby-keyword kw">end</span></pre>
2148 <div id="load-aggregate-functions-method" class="method-detail ">
2149 <a name="M000474"></a>
2151 <div class="method-heading">
2153 <span class="method-name">load_aggregate_functions</span><span
2154 class="method-args">(action, ddl)</span>
2155 <span class="method-click-advice">click to toggle source</span>
2159 <div class="method-description">
2161 <p class="missing-docs">(Not documented)</p>
2165 <div class="method-source-code"
2166 id="load-aggregate-functions-source">
2168 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 676</span>
2169 676: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_aggregate_functions</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">ddl</span>)
2170 677: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ddl</span>
2171 678: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ddl</span>.<span class="ruby-identifier">action_interface</span>(<span class="ruby-identifier">action</span>).<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:aggregate</span>)
2173 680: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Aggregate</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ddl</span>.<span class="ruby-identifier">action_interface</span>(<span class="ruby-identifier">action</span>))
2175 682: <span class="ruby-keyword kw">rescue</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
2176 683: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-value str">"Failed to load aggregate functions, calculating summaries disabled: %s: %s (%s)"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">first</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">class</span>])
2177 684: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
2178 685: <span class="ruby-keyword kw">end</span></pre>
2187 <div id="method-missing-method" class="method-detail ">
2188 <a name="M000452"></a>
2190 <div class="method-heading">
2192 <span class="method-name">method_missing</span><span
2193 class="method-args">(method_name, *args, &block)</span>
2194 <span class="method-click-advice">click to toggle source</span>
2198 <div class="method-description">
2201 Magic handler to invoke remote methods
2204 Once the stub is created using the constructor or the <a
2205 href="../RPC.html#M000314">RPC#rpcclient</a> helper you can call remote
2209 ret = rpc.echo(:msg => "hello world")
2212 This will call the ‘echo’ action of the ‘rpctest’
2213 agent and return the result as an array, the array will be a simplified
2214 result set from the usual full <a
2215 href="../Client.html#M000503">MCollective::Client#req</a> with additional
2216 error codes and error text:
2222 :sender => "remote.box.com",
2223 :statuscode => 0,
2224 :statusmsg => "OK",
2225 :data => "hello world"
2231 If :statuscode is 0 then everything went find, if it’s 1 then you
2232 supplied the correct arguments etc but the request could not be completed,
2233 you’ll find a human parsable reason in :statusmsg then.
2236 Codes 2 to 5 maps directly to <a
2237 href="../UnknownRPCAction.html">UnknownRPCAction</a>, <a
2238 href="../MissingRPCData.html">MissingRPCData</a>, <a
2239 href="../InvalidRPCData.html">InvalidRPCData</a> and <a
2240 href="../UnknownRPCError.html">UnknownRPCError</a> see below for a
2241 description of those, in each case :statusmsg would be the reason for
2245 To get access to the full result of the <a
2246 href="../Client.html#M000503">MCollective::Client#req</a> calls you can
2250 rpc.echo(:msg => "hello world") do |resp|
2255 In this case resp will the result from <a
2256 href="../Client.html#M000503">MCollective::Client#req</a>. Instead of
2257 returning simple text and codes as above you’ll also need to handle
2258 the following exceptions:
2261 <a href="../UnknownRPCAction.html">UnknownRPCAction</a> - There is no
2262 matching action on the agent <a
2263 href="../MissingRPCData.html">MissingRPCData</a> - You did not supply all
2264 the needed parameters for the action <a
2265 href="../InvalidRPCData.html">InvalidRPCData</a> - The data you did supply
2266 did not pass validation <a
2267 href="../UnknownRPCError.html">UnknownRPCError</a> - Some other error
2268 prevented the agent from running
2271 During calls a progress indicator will be shown of how many results
2272 we’ve received against how many nodes were discovered, you can
2273 disable this by setting progress to false:
2276 rpc.progress = false
2279 This supports a 2nd mode where it will send the SimpleRPC request and never
2280 handle the responses. It’s a bit like UDP, it sends the request with
2281 the filter attached and you only get back the requestid, you have no
2282 indication about results.
2285 You can invoke this using:
2288 puts rpc.echo(:process_results => false)
2291 This will output just the request id.
2294 Batched processing is supported:
2297 printrpc rpc.ping(:batch_size => 5)
2300 This will do everything exactly as normal but communicate to only 5 agents
2306 <div class="method-source-code"
2307 id="method-missing-source">
2309 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 231</span>
2310 231: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">method_name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
2311 232: <span class="ruby-comment cmt"># set args to an empty hash if nothings given</span>
2312 233: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]
2313 234: <span class="ruby-identifier">args</span> = {} <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
2315 236: <span class="ruby-identifier">action</span> = <span class="ruby-identifier">method_name</span>.<span class="ruby-identifier">to_s</span>
2317 238: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">reset</span>
2319 240: <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2321 242: <span class="ruby-comment cmt"># if a global batch size is set just use that else set it</span>
2322 243: <span class="ruby-comment cmt"># in the case that it was passed as an argument</span>
2323 244: <span class="ruby-identifier">batch_mode</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">:batch_size</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@batch_mode</span>
2324 245: <span class="ruby-identifier">batch_size</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:batch_size</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@batch_size</span>
2325 246: <span class="ruby-identifier">batch_sleep_time</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">:batch_sleep_time</span>) <span class="ruby-operator">||</span> <span class="ruby-ivar">@batch_sleep_time</span>
2327 248: <span class="ruby-comment cmt"># if we were given a batch_size argument thats 0 and batch_mode was</span>
2328 249: <span class="ruby-comment cmt"># determined to be on via global options etc this will allow a batch_size</span>
2329 250: <span class="ruby-comment cmt"># of 0 to disable or batch_mode for this call only</span>
2330 251: <span class="ruby-identifier">batch_mode</span> = (<span class="ruby-identifier">batch_mode</span> <span class="ruby-operator">&&</span> <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">batch_size</span>) <span class="ruby-operator">></span> <span class="ruby-value">0</span>)
2332 253: <span class="ruby-comment cmt"># Handle single target requests by doing discovery and picking</span>
2333 254: <span class="ruby-comment cmt"># a random node. Then do a custom request specifying a filter</span>
2334 255: <span class="ruby-comment cmt"># that will only match the one node.</span>
2335 256: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_targets</span>
2336 257: <span class="ruby-identifier">target_nodes</span> = <span class="ruby-identifier">pick_nodes_from_discovered</span>(<span class="ruby-ivar">@limit_targets</span>)
2337 258: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Picked #{target_nodes.join(',')} as limited target(s)"</span>)
2339 260: <span class="ruby-identifier">custom_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">target_nodes</span>, {<span class="ruby-value str">"identity"</span> =<span class="ruby-operator">></span> <span class="ruby-node">/^(#{target_nodes.join('|')})$/</span>}, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
2340 261: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">batch_mode</span>
2341 262: <span class="ruby-identifier">call_agent_batched</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">batch_size</span>, <span class="ruby-identifier">batch_sleep_time</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
2342 263: <span class="ruby-keyword kw">else</span>
2343 264: <span class="ruby-identifier">call_agent</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>, <span class="ruby-identifier">options</span>, <span class="ruby-identifier">:auto</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
2344 265: <span class="ruby-keyword kw">end</span>
2345 266: <span class="ruby-keyword kw">end</span></pre>
2354 <div id="new-request-method" class="method-detail ">
2355 <a name="M000448"></a>
2357 <div class="method-heading">
2359 <span class="method-name">new_request</span><span
2360 class="method-args">(action, data)</span>
2361 <span class="method-click-advice">click to toggle source</span>
2365 <div class="method-description">
2368 Creates a suitable request hash for the SimpleRPC agent.
2371 You’d use this if you ever wanted to take care of sending requests on
2372 your own - perhaps via Client#sendreq if you didn’t care for
2376 In that case you can just do:
2379 msg = your_rpc.new_request("some_action", :foo => :bar)
2380 filter = your_rpc.filter
2382 your_rpc.client.sendreq(msg, msg[:agent], filter)
2385 This will send a SimpleRPC request to the action some_action with arguments
2386 :foo = :bar, it will return immediately and you will have no indication at
2387 all if the request was receieved or not
2390 Clearly the use of this technique should be limited and done only if your
2391 code requires such a thing
2396 <div class="method-source-code"
2397 id="new-request-source">
2399 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 149</span>
2400 149: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">new_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">data</span>)
2401 150: <span class="ruby-identifier">callerid</span> = <span class="ruby-constant">PluginManager</span>[<span class="ruby-value str">"security_plugin"</span>].<span class="ruby-identifier">callerid</span>
2403 152: <span class="ruby-identifier">raise</span> <span class="ruby-value str">'callerid received from security plugin is not valid'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">PluginManager</span>[<span class="ruby-value str">"security_plugin"</span>].<span class="ruby-identifier">valid_callerid?</span>(<span class="ruby-identifier">callerid</span>)
2405 154: {<span class="ruby-identifier">:agent</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@agent</span>,
2406 155: <span class="ruby-identifier">:action</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">action</span>,
2407 156: <span class="ruby-identifier">:caller</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">callerid</span>,
2408 157: <span class="ruby-identifier">:data</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">data</span>}
2409 158: <span class="ruby-keyword kw">end</span></pre>
2418 <div id="options-method" class="method-detail ">
2419 <a name="M000467"></a>
2421 <div class="method-heading">
2423 <span class="method-name">options</span><span
2424 class="method-args">()</span>
2425 <span class="method-click-advice">click to toggle source</span>
2429 <div class="method-description">
2432 Provides a normal options hash like you would get from <a
2433 href="../Optionparser.html">Optionparser</a>
2438 <div class="method-source-code"
2439 id="options-source">
2441 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 556</span>
2442 556: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options</span>
2443 557: {<span class="ruby-identifier">:disctimeout</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">discovery_timeout</span>,
2444 558: <span class="ruby-identifier">:timeout</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@timeout</span>,
2445 559: <span class="ruby-identifier">:verbose</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@verbose</span>,
2446 560: <span class="ruby-identifier">:filter</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@filter</span>,
2447 561: <span class="ruby-identifier">:collective</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@collective</span>,
2448 562: <span class="ruby-identifier">:output_format</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@output_format</span>,
2449 563: <span class="ruby-identifier">:ttl</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@ttl</span>,
2450 564: <span class="ruby-identifier">:discovery_method</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@discovery_method</span>,
2451 565: <span class="ruby-identifier">:discovery_options</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@discovery_options</span>,
2452 566: <span class="ruby-identifier">:force_display_mode</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@force_display_mode</span>,
2453 567: <span class="ruby-identifier">:config</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@config</span>,
2454 568: <span class="ruby-identifier">:publish_timeout</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@publish_timeout</span>,
2455 569: <span class="ruby-identifier">:threaded</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@threaded</span>}
2456 570: <span class="ruby-keyword kw">end</span></pre>
2465 <div id="pick-nodes-from-discovered-method" class="method-detail ">
2466 <a name="M000473"></a>
2468 <div class="method-heading">
2470 <span class="method-name">pick_nodes_from_discovered</span><span
2471 class="method-args">(count)</span>
2472 <span class="method-click-advice">click to toggle source</span>
2476 <div class="method-description">
2479 Pick a number of nodes from the discovered nodes
2482 The count should be a string that can be either just a number or a
2486 It will select nodes from the discovered list based on the rpclimitmethod
2487 configuration option which can be either :first or anything else
2490 - :first would be a simple way to do a distance based
2492 - anything else will just pick one at random
2493 - if random chosen, and batch-seed set, then set srand
2494 for the generator, and reset afterwards
2499 <div class="method-source-code"
2500 id="pick-nodes-from-discovered-source">
2502 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 635</span>
2503 635: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pick_nodes_from_discovered</span>(<span class="ruby-identifier">count</span>)
2504 636: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">count</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/%$/</span>
2505 637: <span class="ruby-identifier">pct</span> = <span class="ruby-constant">Integer</span>((<span class="ruby-identifier">discover</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">count</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">100</span>)))
2506 638: <span class="ruby-identifier">pct</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">count</span> = <span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">count</span> = <span class="ruby-identifier">pct</span>
2507 639: <span class="ruby-keyword kw">else</span>
2508 640: <span class="ruby-identifier">count</span> = <span class="ruby-constant">Integer</span>(<span class="ruby-identifier">count</span>)
2509 641: <span class="ruby-keyword kw">end</span>
2511 643: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">discover</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">discover</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">count</span>
2513 645: <span class="ruby-identifier">result</span> = []
2515 647: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_method</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:first</span>
2516 648: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">discover</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">count</span>]
2517 649: <span class="ruby-keyword kw">else</span>
2518 650: <span class="ruby-comment cmt"># we delete from the discovered list because we want</span>
2519 651: <span class="ruby-comment cmt"># to be sure there is no chance that the same node will</span>
2520 652: <span class="ruby-comment cmt"># be randomly picked twice. So we have to clone the</span>
2521 653: <span class="ruby-comment cmt"># discovered list else this method will only ever work</span>
2522 654: <span class="ruby-comment cmt"># once per discovery cycle and not actually return the</span>
2523 655: <span class="ruby-comment cmt"># right nodes.</span>
2524 656: <span class="ruby-identifier">haystack</span> = <span class="ruby-identifier">discover</span>.<span class="ruby-identifier">clone</span>
2526 658: <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_seed</span>
2527 659: <span class="ruby-identifier">haystack</span>.<span class="ruby-identifier">sort!</span>
2528 660: <span class="ruby-identifier">srand</span>(<span class="ruby-ivar">@limit_seed</span>)
2529 661: <span class="ruby-keyword kw">end</span>
2531 663: <span class="ruby-identifier">count</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span>
2532 664: <span class="ruby-identifier">rnd</span> = <span class="ruby-identifier">rand</span>(<span class="ruby-identifier">haystack</span>.<span class="ruby-identifier">size</span>)
2533 665: <span class="ruby-identifier">result</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">haystack</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">rnd</span>)
2534 666: <span class="ruby-keyword kw">end</span>
2536 668: <span class="ruby-comment cmt"># Reset random number generator to fresh seed</span>
2537 669: <span class="ruby-comment cmt"># As our seed from options is most likely short</span>
2538 670: <span class="ruby-identifier">srand</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@limit_seed</span>
2539 671: <span class="ruby-keyword kw">end</span>
2541 673: [<span class="ruby-identifier">result</span>].<span class="ruby-identifier">flatten</span>
2542 674: <span class="ruby-keyword kw">end</span></pre>
2551 <div id="process-results-with-block-method" class="method-detail ">
2552 <a name="M000485"></a>
2554 <div class="method-heading">
2556 <span class="method-name">process_results_with_block</span><span
2557 class="method-args">(action, resp, block, aggregate)</span>
2558 <span class="method-click-advice">click to toggle source</span>
2562 <div class="method-description">
2565 process client requests by calling a block on each result in this mode we
2566 do not do anything fancy with the result objects and we raise exceptions if
2567 there are problems with the data
2572 <div class="method-source-code"
2573 id="process-results-with-block-source">
2575 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 944</span>
2576 944: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_results_with_block</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>, <span class="ruby-identifier">block</span>, <span class="ruby-identifier">aggregate</span>)
2577 945: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">node_responded</span>(<span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:senderid</span>])
2579 947: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">rpc_result_from_reply</span>(<span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>)
2580 948: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">aggregate_reply</span>(<span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
2582 950: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
2583 951: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">ok</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
2584 952: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
2585 953: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_block_execution</span> <span class="ruby-identifier">:start</span>
2587 955: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">block</span>.<span class="ruby-identifier">arity</span>
2588 956: <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>
2589 957: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">resp</span>)
2590 958: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
2591 959: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">result</span>)
2592 960: <span class="ruby-keyword kw">end</span>
2594 962: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">time_block_execution</span> <span class="ruby-identifier">:end</span>
2595 963: <span class="ruby-keyword kw">else</span>
2596 964: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span>
2598 966: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>]
2599 967: <span class="ruby-keyword kw">when</span> <span class="ruby-value">2</span>
2600 968: <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownRPCAction</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
2601 969: <span class="ruby-keyword kw">when</span> <span class="ruby-value">3</span>
2602 970: <span class="ruby-identifier">raise</span> <span class="ruby-constant">MissingRPCData</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
2603 971: <span class="ruby-keyword kw">when</span> <span class="ruby-value">4</span>
2604 972: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidRPCData</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
2605 973: <span class="ruby-keyword kw">when</span> <span class="ruby-value">5</span>
2606 974: <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownRPCError</span>, <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>]
2607 975: <span class="ruby-keyword kw">end</span>
2608 976: <span class="ruby-keyword kw">end</span>
2610 978: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">aggregate</span>
2611 979: <span class="ruby-keyword kw">end</span></pre>
2620 <div id="process-results-without-block-method" class="method-detail ">
2621 <a name="M000481"></a>
2623 <div class="method-heading">
2625 <span class="method-name">process_results_without_block</span><span
2626 class="method-args">(resp, action, aggregate)</span>
2627 <span class="method-click-advice">click to toggle source</span>
2631 <div class="method-description">
2634 Handles result sets that has no block associated, sets fails and ok in the
2635 stats object and return a hash of the response to send to the caller
2640 <div class="method-source-code"
2641 id="process-results-without-block-source">
2643 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 924</span>
2644 924: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_results_without_block</span>(<span class="ruby-identifier">resp</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">aggregate</span>)
2645 925: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">node_responded</span>(<span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:senderid</span>])
2647 927: <span class="ruby-identifier">result</span> = <span class="ruby-identifier">rpc_result_from_reply</span>(<span class="ruby-ivar">@agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">resp</span>)
2648 928: <span class="ruby-identifier">aggregate</span> = <span class="ruby-identifier">aggregate_reply</span>(<span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">aggregate</span>
2650 930: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
2651 931: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">ok</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
2652 932: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resp</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>] <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
2653 933: <span class="ruby-keyword kw">else</span>
2654 934: <span class="ruby-ivar">@stats</span>.<span class="ruby-identifier">fail</span>
2655 935: <span class="ruby-keyword kw">end</span>
2657 937: [<span class="ruby-identifier">result</span>, <span class="ruby-identifier">aggregate</span>]
2658 938: <span class="ruby-keyword kw">end</span></pre>
2667 <div id="reset-method" class="method-detail ">
2668 <a name="M000464"></a>
2670 <div class="method-heading">
2672 <span class="method-name">reset</span><span
2673 class="method-args">()</span>
2674 <span class="method-click-advice">click to toggle source</span>
2678 <div class="method-description">
2681 Resets various internal parts of the class, most importantly it clears out
2682 the cached discovery
2687 <div class="method-source-code"
2690 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 443</span>
2691 443: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>
2692 444: <span class="ruby-ivar">@discovered_agents</span> = <span class="ruby-keyword kw">nil</span>
2693 445: <span class="ruby-keyword kw">end</span></pre>
2702 <div id="reset-filter-method" class="method-detail ">
2703 <a name="M000465"></a>
2705 <div class="method-heading">
2707 <span class="method-name">reset_filter</span><span
2708 class="method-args">()</span>
2709 <span class="method-click-advice">click to toggle source</span>
2713 <div class="method-description">
2716 Reet the filter to an empty one
2721 <div class="method-source-code"
2722 id="reset-filter-source">
2724 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 448</span>
2725 448: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset_filter</span>
2726 449: <span class="ruby-ivar">@filter</span> = <span class="ruby-constant">Util</span>.<span class="ruby-identifier">empty_filter</span>
2727 450: <span class="ruby-identifier">agent_filter</span> <span class="ruby-ivar">@agent</span>
2728 451: <span class="ruby-keyword kw">end</span></pre>
2737 <div id="rpc-result-from-reply-method" class="method-detail ">
2738 <a name="M000476"></a>
2740 <div class="method-heading">
2742 <span class="method-name">rpc_result_from_reply</span><span
2743 class="method-args">(agent, action, reply)</span>
2744 <span class="method-click-advice">click to toggle source</span>
2748 <div class="method-description">
2750 <p class="missing-docs">(Not documented)</p>
2754 <div class="method-source-code"
2755 id="rpc-result-from-reply-source">
2757 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 697</span>
2758 697: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rpc_result_from_reply</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">reply</span>)
2759 698: <span class="ruby-constant">Result</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">action</span>, {<span class="ruby-identifier">:sender</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:senderid</span>], <span class="ruby-identifier">:statuscode</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statuscode</span>],
2760 699: <span class="ruby-identifier">:statusmsg</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:statusmsg</span>], <span class="ruby-identifier">:data</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">reply</span>[<span class="ruby-identifier">:body</span>][<span class="ruby-identifier">:data</span>]})
2761 700: <span class="ruby-keyword kw">end</span></pre>
2770 <div id="validate-request-method" class="method-detail ">
2771 <a name="M000449"></a>
2773 <div class="method-heading">
2775 <span class="method-name">validate_request</span><span
2776 class="method-args">(action, args)</span>
2777 <span class="method-click-advice">click to toggle source</span>
2781 <div class="method-description">
2784 For the provided arguments and action the input arguments get modified by
2785 supplying any defaults provided in the <a href="../DDL.html">DDL</a> for
2786 arguments that were not supplied in the request
2789 We then pass the modified arguments to the <a href="../DDL.html">DDL</a>
2795 <div class="method-source-code"
2796 id="validate-request-source">
2798 <span class="ruby-comment cmt"># File lib/mcollective/rpc/client.rb, line 165</span>
2799 165: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">validate_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2800 166: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"No DDL found for agent %s cannot validate inputs"</span> <span class="ruby-operator">%</span> <span class="ruby-ivar">@agent</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@ddl</span>
2802 168: <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">set_default_input_arguments</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2803 169: <span class="ruby-ivar">@ddl</span>.<span class="ruby-identifier">validate_rpc_request</span>(<span class="ruby-identifier">action</span>, <span class="ruby-identifier">args</span>)
2804 170: <span class="ruby-keyword kw">end</span></pre>
2819 <div id="rdoc-debugging-section-dump" class="debugging-section">
2821 <p>Disabled; run with --debug to generate this.</p>
2825 <div id="validator-badges">
2826 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
2827 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
2828 Rdoc Generator</a> 1.1.6</small>.</p>