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::Agents</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/agents_rb.html?TB_iframe=true&height=550&width=785"
32 class="thickbox" title="lib/mcollective/agents.rb">lib/mcollective/agents.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="#M000112">::agentlist</a></li>
64 <li><a href="#M000101">::new</a></li>
66 <li><a href="#M000106">#activate_agent?</a></li>
68 <li><a href="#M000105">#class_for_agent</a></li>
70 <li><a href="#M000102">#clear!</a></li>
72 <li><a href="#M000109">#dispatch</a></li>
74 <li><a href="#M000107">#findagentfile</a></li>
76 <li><a href="#M000108">#include?</a></li>
78 <li><a href="#M000104">#loadagent</a></li>
80 <li><a href="#M000103">#loadagents</a></li>
86 <!-- Included Modules -->
90 <div id="project-metadata">
93 <div id="fileindex-section" class="section project-section">
94 <h3 class="section-header">Files</h3>
97 <li class="file"><a href="../COPYING.html">COPYING</a></li>
99 <li class="file"><a href="../Gemfile.html">Gemfile</a></li>
101 <li class="file"><a href="../README.html">README</a></li>
103 <li class="file"><a href="../Rakefile.html">Rakefile</a></li>
105 <li class="file"><a href="../etc/client_cfg_dist.html">client.cfg.dist</a></li>
107 <li class="file"><a href="../etc/data-help_erb.html">data-help.erb</a></li>
109 <li class="file"><a href="../etc/discovery-help_erb.html">discovery-help.erb</a></li>
111 <li class="file"><a href="../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
113 <li class="file"><a href="../etc/metadata-help_erb.html">metadata-help.erb</a></li>
115 <li class="file"><a href="../etc/msg-help_erb.html">msg-help.erb</a></li>
117 <li class="file"><a href="../etc/rpc-help_erb.html">rpc-help.erb</a></li>
119 <li class="file"><a href="../etc/server_cfg_dist.html">server.cfg.dist</a></li>
121 <li class="file"><a href="../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
123 <li class="file"><a href="../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
125 <li class="file"><a href="../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
127 <li class="file"><a href="../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
129 <li class="file"><a href="../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
131 <li class="file"><a href="../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
133 <li class="file"><a href="../lib/mcollective/locales/en_yml.html">en.yml</a></li>
135 <li class="file"><a href="../mcollective_init.html">mcollective.init</a></li>
141 <div id="classindex-section" class="section project-section">
142 <h3 class="section-header">Class Index
143 <span class="search-toggle"><img src="../images/find.png"
144 height="16" width="16" alt="[+]"
145 title="show/hide quicksearch" /></span></h3>
146 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
148 <legend>Quicksearch</legend>
149 <input type="text" name="quicksearch" value=""
150 class="quicksearch-field" />
154 <ul class="link-list">
156 <li><a href="../MCollective.html">MCollective</a></li>
158 <li><a href="../MCollective/Agent.html">MCollective::Agent</a></li>
160 <li><a href="../MCollective/Agents.html">MCollective::Agents</a></li>
162 <li><a href="../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
164 <li><a href="../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
166 <li><a href="../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
168 <li><a href="../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
170 <li><a href="../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
172 <li><a href="../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
174 <li><a href="../MCollective/Application.html">MCollective::Application</a></li>
176 <li><a href="../MCollective/Applications.html">MCollective::Applications</a></li>
178 <li><a href="../MCollective/Cache.html">MCollective::Cache</a></li>
180 <li><a href="../MCollective/Client.html">MCollective::Client</a></li>
182 <li><a href="../MCollective/CodedError.html">MCollective::CodedError</a></li>
184 <li><a href="../MCollective/Config.html">MCollective::Config</a></li>
186 <li><a href="../MCollective/Connector.html">MCollective::Connector</a></li>
188 <li><a href="../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
190 <li><a href="../MCollective/DDL.html">MCollective::DDL</a></li>
192 <li><a href="../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
194 <li><a href="../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
196 <li><a href="../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
198 <li><a href="../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
200 <li><a href="../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
202 <li><a href="../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
204 <li><a href="../MCollective/Data.html">MCollective::Data</a></li>
206 <li><a href="../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
208 <li><a href="../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
210 <li><a href="../MCollective/Discovery.html">MCollective::Discovery</a></li>
212 <li><a href="../MCollective/Facts.html">MCollective::Facts</a></li>
214 <li><a href="../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
216 <li><a href="../MCollective/Generators.html">MCollective::Generators</a></li>
218 <li><a href="../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
220 <li><a href="../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
222 <li><a href="../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
224 <li><a href="../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
226 <li><a href="../MCollective/Log.html">MCollective::Log</a></li>
228 <li><a href="../MCollective/Logger.html">MCollective::Logger</a></li>
230 <li><a href="../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
232 <li><a href="../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
234 <li><a href="../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
236 <li><a href="../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
238 <li><a href="../MCollective/Matcher.html">MCollective::Matcher</a></li>
240 <li><a href="../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
242 <li><a href="../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
244 <li><a href="../MCollective/Message.html">MCollective::Message</a></li>
246 <li><a href="../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
248 <li><a href="../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
250 <li><a href="../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
252 <li><a href="../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
254 <li><a href="../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
256 <li><a href="../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
258 <li><a href="../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
260 <li><a href="../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
262 <li><a href="../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
264 <li><a href="../MCollective/RPC.html">MCollective::RPC</a></li>
266 <li><a href="../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
268 <li><a href="../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
270 <li><a href="../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
272 <li><a href="../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
274 <li><a href="../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
276 <li><a href="../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
278 <li><a href="../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
280 <li><a href="../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
282 <li><a href="../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
284 <li><a href="../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
286 <li><a href="../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
288 <li><a href="../MCollective/RPCError.html">MCollective::RPCError</a></li>
290 <li><a href="../MCollective/Registration.html">MCollective::Registration</a></li>
292 <li><a href="../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
294 <li><a href="../MCollective/Runner.html">MCollective::Runner</a></li>
296 <li><a href="../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
298 <li><a href="../MCollective/SSL.html">MCollective::SSL</a></li>
300 <li><a href="../MCollective/Security.html">MCollective::Security</a></li>
302 <li><a href="../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
304 <li><a href="../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
306 <li><a href="../MCollective/Shell.html">MCollective::Shell</a></li>
308 <li><a href="../MCollective/Translatable.html">MCollective::Translatable</a></li>
310 <li><a href="../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
312 <li><a href="../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
314 <li><a href="../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
316 <li><a href="../MCollective/Util.html">MCollective::Util</a></li>
318 <li><a href="../MCollective/Validator.html">MCollective::Validator</a></li>
320 <li><a href="../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
322 <li><a href="../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
324 <li><a href="../Array.html">Array</a></li>
326 <li><a href="../Dir.html">Dir</a></li>
328 <li><a href="../Object.html">Object</a></li>
330 <li><a href="../String.html">String</a></li>
332 <li><a href="../Symbol.html">Symbol</a></li>
335 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
342 <div id="documentation">
343 <h1 class="class">MCollective::Agents</h1>
345 <div id="description">
347 A collection of agents, loads them, reloads them and dispatches messages to
348 them. It uses the <a href="PluginManager.html">PluginManager</a> to store,
349 load and manage instances of plugins.
362 <div id="public-class-method-details" class="method-section section">
363 <h3 class="section-header">Public Class Methods</h3>
366 <div id="agentlist-method" class="method-detail ">
367 <a name="M000112"></a>
369 <div class="method-heading">
371 <span class="method-name">agentlist</span><span
372 class="method-args">()</span>
373 <span class="method-click-advice">click to toggle source</span>
377 <div class="method-description">
380 Get a list of agents that we have
385 <div class="method-source-code"
386 id="agentlist-source">
388 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 145</span>
389 145: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">agentlist</span>
390 146: <span class="ruby-ivar">@@agents</span>.<span class="ruby-identifier">keys</span>
391 147: <span class="ruby-keyword kw">end</span></pre>
400 <div id="new-method" class="method-detail ">
401 <a name="M000101"></a>
403 <div class="method-heading">
405 <span class="method-name">new</span><span
406 class="method-args">(agents = {})</span>
407 <span class="method-click-advice">click to toggle source</span>
411 <div class="method-description">
413 <p class="missing-docs">(Not documented)</p>
417 <div class="method-source-code"
420 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 5</span>
421 5: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">agents</span> = {})
422 6: <span class="ruby-ivar">@config</span> = <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</span>
423 7: <span class="ruby-identifier">raise</span> (<span class="ruby-value str">"Configuration has not been loaded, can't load agents"</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">configured</span>
425 9: <span class="ruby-ivar">@@agents</span> = <span class="ruby-identifier">agents</span>
427 11: <span class="ruby-identifier">loadagents</span>
428 12: <span class="ruby-keyword kw">end</span></pre>
439 <div id="public-instance-method-details" class="method-section section">
440 <h3 class="section-header">Public Instance Methods</h3>
443 <div id="activate-agent--method" class="method-detail ">
444 <a name="M000106"></a>
446 <div class="method-heading">
448 <span class="method-name">activate_agent?</span><span
449 class="method-args">(agent)</span>
450 <span class="method-click-advice">click to toggle source</span>
454 <div class="method-description">
457 Checks if a plugin should be activated by calling activate? on it if it
458 responds to that method else always activate it
463 <div class="method-source-code"
464 id="activate-agent--source">
466 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 85</span>
467 85: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">activate_agent?</span>(<span class="ruby-identifier">agent</span>)
468 86: <span class="ruby-identifier">klass</span> = <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">"MCollective"</span>).<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">"Agent"</span>).<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">agent</span>.<span class="ruby-identifier">capitalize</span>)
470 88: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">"activate?"</span>)
471 89: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">activate?</span>
472 90: <span class="ruby-keyword kw">else</span>
473 91: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"#{klass} does not have an activate? method, activating as default"</span>)
474 92: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
475 93: <span class="ruby-keyword kw">end</span>
476 94: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
477 95: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">"Agent activation check for #{agent} failed: #{e.class}: #{e}"</span>)
478 96: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
479 97: <span class="ruby-keyword kw">end</span></pre>
488 <div id="class-for-agent-method" class="method-detail ">
489 <a name="M000105"></a>
491 <div class="method-heading">
493 <span class="method-name">class_for_agent</span><span
494 class="method-args">(agent)</span>
495 <span class="method-click-advice">click to toggle source</span>
499 <div class="method-description">
502 Builds a class name string given a <a href="Agent.html">Agent</a> name
507 <div class="method-source-code"
508 id="class-for-agent-source">
510 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 78</span>
511 78: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">class_for_agent</span>(<span class="ruby-identifier">agent</span>)
512 79: <span class="ruby-node">"MCollective::Agent::#{agent.capitalize}"</span>
513 80: <span class="ruby-keyword kw">end</span></pre>
522 <div id="clear--method" class="method-detail ">
523 <a name="M000102"></a>
525 <div class="method-heading">
527 <span class="method-name">clear!</span><span
528 class="method-args">()</span>
529 <span class="method-click-advice">click to toggle source</span>
533 <div class="method-description">
541 <div class="method-source-code"
544 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 15</span>
545 15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear!</span>
546 16: <span class="ruby-ivar">@@agents</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">agent</span><span class="ruby-operator">|</span>
547 17: <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">delete</span> <span class="ruby-node">"#{agent}_agent"</span>
548 18: <span class="ruby-constant">Util</span>.<span class="ruby-identifier">unsubscribe</span>(<span class="ruby-constant">Util</span>.<span class="ruby-identifier">make_subscriptions</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-identifier">:broadcast</span>))
549 19: <span class="ruby-keyword kw">end</span>
551 21: <span class="ruby-ivar">@@agents</span> = {}
552 22: <span class="ruby-keyword kw">end</span></pre>
561 <div id="dispatch-method" class="method-detail ">
562 <a name="M000109"></a>
564 <div class="method-heading">
566 <span class="method-name">dispatch</span><span
567 class="method-args">(request, connection)</span>
568 <span class="method-click-advice">click to toggle source</span>
572 <div class="method-description">
575 Dispatches a message to an agent, accepts a block that will get run if
576 there are any replies to process from the agent
581 <div class="method-source-code"
582 id="dispatch-source">
584 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 118</span>
585 118: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dispatch</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">connection</span>)
586 119: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Dispatching a message to agent #{request.agent}"</span>)
588 121: <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span>
589 122: <span class="ruby-keyword kw">begin</span>
590 123: <span class="ruby-identifier">agent</span> = <span class="ruby-constant">PluginManager</span>[<span class="ruby-node">"#{request.agent}_agent"</span>]
592 125: <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-identifier">timeout</span>(<span class="ruby-identifier">agent</span>.<span class="ruby-identifier">timeout</span>) <span class="ruby-keyword kw">do</span>
593 126: <span class="ruby-identifier">replies</span> = <span class="ruby-identifier">agent</span>.<span class="ruby-identifier">handlemsg</span>(<span class="ruby-identifier">request</span>.<span class="ruby-identifier">payload</span>, <span class="ruby-identifier">connection</span>)
595 128: <span class="ruby-comment cmt"># Agents can decide if they wish to reply or not,</span>
596 129: <span class="ruby-comment cmt"># returning nil will mean nothing goes back to the</span>
597 130: <span class="ruby-comment cmt"># requestor</span>
598 131: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">replies</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span>
599 132: <span class="ruby-keyword kw">yield</span>(<span class="ruby-identifier">replies</span>)
600 133: <span class="ruby-keyword kw">end</span>
601 134: <span class="ruby-keyword kw">end</span>
602 135: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
603 136: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">"Timeout while handling message for #{request.agent}"</span>)
604 137: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
605 138: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">"Execution of #{request.agent} failed: #{e}"</span>)
606 139: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">"\n\t\t"</span>))
607 140: <span class="ruby-keyword kw">end</span>
608 141: <span class="ruby-keyword kw">end</span>
609 142: <span class="ruby-keyword kw">end</span></pre>
618 <div id="findagentfile-method" class="method-detail ">
619 <a name="M000107"></a>
621 <div class="method-heading">
623 <span class="method-name">findagentfile</span><span
624 class="method-args">(agentname)</span>
625 <span class="method-click-advice">click to toggle source</span>
629 <div class="method-description">
632 searches the libdirs for agents
637 <div class="method-source-code"
638 id="findagentfile-source">
640 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 100</span>
641 100: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">findagentfile</span>(<span class="ruby-identifier">agentname</span>)
642 101: <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">libdir</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">libdir</span><span class="ruby-operator">|</span>
643 102: <span class="ruby-identifier">agentfile</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>([<span class="ruby-identifier">libdir</span>, <span class="ruby-value str">"mcollective"</span>, <span class="ruby-value str">"agent"</span>, <span class="ruby-node">"#{agentname}.rb"</span>])
644 103: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">agentfile</span>)
645 104: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Found #{agentname} at #{agentfile}"</span>)
646 105: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">agentfile</span>
647 106: <span class="ruby-keyword kw">end</span>
648 107: <span class="ruby-keyword kw">end</span>
649 108: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
650 109: <span class="ruby-keyword kw">end</span></pre>
659 <div id="include--method" class="method-detail ">
660 <a name="M000108"></a>
662 <div class="method-heading">
664 <span class="method-name">include?</span><span
665 class="method-args">(agentname)</span>
666 <span class="method-click-advice">click to toggle source</span>
670 <div class="method-description">
673 Determines if we have an agent with a certain name
678 <div class="method-source-code"
679 id="include--source">
681 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 112</span>
682 112: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">include?</span>(<span class="ruby-identifier">agentname</span>)
683 113: <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-node">"#{agentname}_agent"</span>)
684 114: <span class="ruby-keyword kw">end</span></pre>
693 <div id="loadagent-method" class="method-detail ">
694 <a name="M000104"></a>
696 <div class="method-heading">
698 <span class="method-name">loadagent</span><span
699 class="method-args">(agentname)</span>
700 <span class="method-click-advice">click to toggle source</span>
704 <div class="method-description">
707 Loads a specified agent from disk if available
712 <div class="method-source-code"
713 id="loadagent-source">
715 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 42</span>
716 42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">loadagent</span>(<span class="ruby-identifier">agentname</span>)
717 43: <span class="ruby-identifier">agentfile</span> = <span class="ruby-identifier">findagentfile</span>(<span class="ruby-identifier">agentname</span>)
718 44: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">agentfile</span>
719 45: <span class="ruby-identifier">classname</span> = <span class="ruby-identifier">class_for_agent</span>(<span class="ruby-identifier">agentname</span>)
721 47: <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-node">"#{agentname}_agent"</span>)
723 49: <span class="ruby-keyword kw">begin</span>
724 50: <span class="ruby-identifier">single_instance</span> = [<span class="ruby-value str">"registration"</span>, <span class="ruby-value str">"discovery"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">agentname</span>)
726 52: <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">loadclass</span>(<span class="ruby-identifier">classname</span>)
728 54: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">activate_agent?</span>(<span class="ruby-identifier">agentname</span>)
729 55: <span class="ruby-constant">PluginManager</span> <span class="ruby-operator"><<</span> {<span class="ruby-identifier">:type</span> =<span class="ruby-operator">></span> <span class="ruby-node">"#{agentname}_agent"</span>, <span class="ruby-identifier">:class</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">classname</span>, <span class="ruby-identifier">:single_instance</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">single_instance</span>}
731 57: <span class="ruby-comment cmt"># Attempt to instantiate the agent once so any validation and hooks get run</span>
732 58: <span class="ruby-comment cmt"># this does a basic sanity check on the agent as a whole, if this fails it</span>
733 59: <span class="ruby-comment cmt"># will be removed from the plugin list</span>
734 60: <span class="ruby-constant">PluginManager</span>[<span class="ruby-node">"#{agentname}_agent"</span>]
736 62: <span class="ruby-constant">Util</span>.<span class="ruby-identifier">subscribe</span>(<span class="ruby-constant">Util</span>.<span class="ruby-identifier">make_subscriptions</span>(<span class="ruby-identifier">agentname</span>, <span class="ruby-identifier">:broadcast</span>)) <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@@agents</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">agentname</span>)
738 64: <span class="ruby-ivar">@@agents</span>[<span class="ruby-identifier">agentname</span>] = {<span class="ruby-identifier">:file</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">agentfile</span>}
739 65: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
740 66: <span class="ruby-keyword kw">else</span>
741 67: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Not activating agent #{agentname} due to agent policy in activate? method"</span>)
742 68: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
743 69: <span class="ruby-keyword kw">end</span>
744 70: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
745 71: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">"Loading agent #{agentname} failed: #{e}"</span>)
746 72: <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-node">"#{agentname}_agent"</span>)
747 73: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
748 74: <span class="ruby-keyword kw">end</span>
749 75: <span class="ruby-keyword kw">end</span></pre>
758 <div id="loadagents-method" class="method-detail ">
759 <a name="M000103"></a>
761 <div class="method-heading">
763 <span class="method-name">loadagents</span><span
764 class="method-args">()</span>
765 <span class="method-click-advice">click to toggle source</span>
769 <div class="method-description">
772 Loads all agents from disk
777 <div class="method-source-code"
778 id="loadagents-source">
780 <span class="ruby-comment cmt"># File lib/mcollective/agents.rb, line 25</span>
781 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">loadagents</span>
782 26: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">"Reloading all agents from disk"</span>)
784 28: <span class="ruby-identifier">clear!</span>
786 30: <span class="ruby-ivar">@config</span>.<span class="ruby-identifier">libdir</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">libdir</span><span class="ruby-operator">|</span>
787 31: <span class="ruby-identifier">agentdir</span> = <span class="ruby-node">"#{libdir}/mcollective/agent"</span>
788 32: <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">agentdir</span>)
790 34: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">agentdir</span>).<span class="ruby-identifier">grep</span>(<span class="ruby-regexp re">/\.rb$/</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">agent</span><span class="ruby-operator">|</span>
791 35: <span class="ruby-identifier">agentname</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">agent</span>, <span class="ruby-value str">".rb"</span>)
792 36: <span class="ruby-identifier">loadagent</span>(<span class="ruby-identifier">agentname</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">PluginManager</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-node">"#{agentname}_agent"</span>)
793 37: <span class="ruby-keyword kw">end</span>
794 38: <span class="ruby-keyword kw">end</span>
795 39: <span class="ruby-keyword kw">end</span></pre>
810 <div id="rdoc-debugging-section-dump" class="debugging-section">
812 <p>Disabled; run with --debug to generate this.</p>
816 <div id="validator-badges">
817 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
818 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
819 Rdoc Generator</a> 1.1.6</small>.</p>