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::ActionRunner</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/actionrunner_rb.html?TB_iframe=true&height=550&width=785"
32 class="thickbox" title="lib/mcollective/rpc/actionrunner.rb">lib/mcollective/rpc/actionrunner.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="#M000372">::new</a></li>
64 <li><a href="#M000379">#canrun?</a></li>
66 <li><a href="#M000376">#load_json_results</a></li>
68 <li><a href="#M000375">#load_results</a></li>
70 <li><a href="#M000382">#path_to_command</a></li>
72 <li><a href="#M000373">#run</a></li>
74 <li><a href="#M000378">#save_json_request</a></li>
76 <li><a href="#M000377">#saverequest</a></li>
78 <li><a href="#M000374">#shell</a></li>
80 <li><a href="#M000381">#tempfile</a></li>
82 <li><a href="#M000380">#to_s</a></li>
88 <!-- Included Modules -->
92 <div id="project-metadata">
95 <div id="fileindex-section" class="section project-section">
96 <h3 class="section-header">Files</h3>
99 <li class="file"><a href="../../COPYING.html">COPYING</a></li>
101 <li class="file"><a href="../../Gemfile.html">Gemfile</a></li>
103 <li class="file"><a href="../../README.html">README</a></li>
105 <li class="file"><a href="../../Rakefile.html">Rakefile</a></li>
107 <li class="file"><a href="../../etc/client_cfg_dist.html">client.cfg.dist</a></li>
109 <li class="file"><a href="../../etc/data-help_erb.html">data-help.erb</a></li>
111 <li class="file"><a href="../../etc/discovery-help_erb.html">discovery-help.erb</a></li>
113 <li class="file"><a href="../../etc/facts_yaml_dist.html">facts.yaml.dist</a></li>
115 <li class="file"><a href="../../etc/metadata-help_erb.html">metadata-help.erb</a></li>
117 <li class="file"><a href="../../etc/msg-help_erb.html">msg-help.erb</a></li>
119 <li class="file"><a href="../../etc/rpc-help_erb.html">rpc-help.erb</a></li>
121 <li class="file"><a href="../../etc/server_cfg_dist.html">server.cfg.dist</a></li>
123 <li class="file"><a href="../../etc/ssl/PLACEHOLDER.html">PLACEHOLDER</a></li>
125 <li class="file"><a href="../../etc/ssl/clients/PLACEHOLDER.html">PLACEHOLDER</a></li>
127 <li class="file"><a href="../../lib/mcollective/generators/templates/action_snippet_erb.html">action_snippet.erb</a></li>
129 <li class="file"><a href="../../lib/mcollective/generators/templates/data_input_snippet_erb.html">data_input_snippet.erb</a></li>
131 <li class="file"><a href="../../lib/mcollective/generators/templates/ddl_erb.html">ddl.erb</a></li>
133 <li class="file"><a href="../../lib/mcollective/generators/templates/plugin_erb.html">plugin.erb</a></li>
135 <li class="file"><a href="../../lib/mcollective/locales/en_yml.html">en.yml</a></li>
137 <li class="file"><a href="../../mcollective_init.html">mcollective.init</a></li>
143 <div id="classindex-section" class="section project-section">
144 <h3 class="section-header">Class Index
145 <span class="search-toggle"><img src="../../images/find.png"
146 height="16" width="16" alt="[+]"
147 title="show/hide quicksearch" /></span></h3>
148 <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
150 <legend>Quicksearch</legend>
151 <input type="text" name="quicksearch" value=""
152 class="quicksearch-field" />
156 <ul class="link-list">
158 <li><a href="../../MCollective.html">MCollective</a></li>
160 <li><a href="../../MCollective/Agent.html">MCollective::Agent</a></li>
162 <li><a href="../../MCollective/Agents.html">MCollective::Agents</a></li>
164 <li><a href="../../MCollective/Aggregate.html">MCollective::Aggregate</a></li>
166 <li><a href="../../MCollective/Aggregate/Base.html">MCollective::Aggregate::Base</a></li>
168 <li><a href="../../MCollective/Aggregate/Result.html">MCollective::Aggregate::Result</a></li>
170 <li><a href="../../MCollective/Aggregate/Result/Base.html">MCollective::Aggregate::Result::Base</a></li>
172 <li><a href="../../MCollective/Aggregate/Result/CollectionResult.html">MCollective::Aggregate::Result::CollectionResult</a></li>
174 <li><a href="../../MCollective/Aggregate/Result/NumericResult.html">MCollective::Aggregate::Result::NumericResult</a></li>
176 <li><a href="../../MCollective/Application.html">MCollective::Application</a></li>
178 <li><a href="../../MCollective/Applications.html">MCollective::Applications</a></li>
180 <li><a href="../../MCollective/Cache.html">MCollective::Cache</a></li>
182 <li><a href="../../MCollective/Client.html">MCollective::Client</a></li>
184 <li><a href="../../MCollective/CodedError.html">MCollective::CodedError</a></li>
186 <li><a href="../../MCollective/Config.html">MCollective::Config</a></li>
188 <li><a href="../../MCollective/Connector.html">MCollective::Connector</a></li>
190 <li><a href="../../MCollective/Connector/Base.html">MCollective::Connector::Base</a></li>
192 <li><a href="../../MCollective/DDL.html">MCollective::DDL</a></li>
194 <li><a href="../../MCollective/DDL/AgentDDL.html">MCollective::DDL::AgentDDL</a></li>
196 <li><a href="../../MCollective/DDL/Base.html">MCollective::DDL::Base</a></li>
198 <li><a href="../../MCollective/DDL/DataDDL.html">MCollective::DDL::DataDDL</a></li>
200 <li><a href="../../MCollective/DDL/DiscoveryDDL.html">MCollective::DDL::DiscoveryDDL</a></li>
202 <li><a href="../../MCollective/DDL/ValidatorDDL.html">MCollective::DDL::ValidatorDDL</a></li>
204 <li><a href="../../MCollective/DDLValidationError.html">MCollective::DDLValidationError</a></li>
206 <li><a href="../../MCollective/Data.html">MCollective::Data</a></li>
208 <li><a href="../../MCollective/Data/Base.html">MCollective::Data::Base</a></li>
210 <li><a href="../../MCollective/Data/Result.html">MCollective::Data::Result</a></li>
212 <li><a href="../../MCollective/Discovery.html">MCollective::Discovery</a></li>
214 <li><a href="../../MCollective/Facts.html">MCollective::Facts</a></li>
216 <li><a href="../../MCollective/Facts/Base.html">MCollective::Facts::Base</a></li>
218 <li><a href="../../MCollective/Generators.html">MCollective::Generators</a></li>
220 <li><a href="../../MCollective/Generators/AgentGenerator.html">MCollective::Generators::AgentGenerator</a></li>
222 <li><a href="../../MCollective/Generators/Base.html">MCollective::Generators::Base</a></li>
224 <li><a href="../../MCollective/Generators/DataGenerator.html">MCollective::Generators::DataGenerator</a></li>
226 <li><a href="../../MCollective/InvalidRPCData.html">MCollective::InvalidRPCData</a></li>
228 <li><a href="../../MCollective/Log.html">MCollective::Log</a></li>
230 <li><a href="../../MCollective/Logger.html">MCollective::Logger</a></li>
232 <li><a href="../../MCollective/Logger/Base.html">MCollective::Logger::Base</a></li>
234 <li><a href="../../MCollective/Logger/Console_logger.html">MCollective::Logger::Console_logger</a></li>
236 <li><a href="../../MCollective/Logger/File_logger.html">MCollective::Logger::File_logger</a></li>
238 <li><a href="../../MCollective/Logger/Syslog_logger.html">MCollective::Logger::Syslog_logger</a></li>
240 <li><a href="../../MCollective/Matcher.html">MCollective::Matcher</a></li>
242 <li><a href="../../MCollective/Matcher/Parser.html">MCollective::Matcher::Parser</a></li>
244 <li><a href="../../MCollective/Matcher/Scanner.html">MCollective::Matcher::Scanner</a></li>
246 <li><a href="../../MCollective/Message.html">MCollective::Message</a></li>
248 <li><a href="../../MCollective/MissingRPCData.html">MCollective::MissingRPCData</a></li>
250 <li><a href="../../MCollective/MsgDoesNotMatchRequestID.html">MCollective::MsgDoesNotMatchRequestID</a></li>
252 <li><a href="../../MCollective/MsgTTLExpired.html">MCollective::MsgTTLExpired</a></li>
254 <li><a href="../../MCollective/NotTargettedAtUs.html">MCollective::NotTargettedAtUs</a></li>
256 <li><a href="../../MCollective/Optionparser.html">MCollective::Optionparser</a></li>
258 <li><a href="../../MCollective/PluginManager.html">MCollective::PluginManager</a></li>
260 <li><a href="../../MCollective/PluginPackager.html">MCollective::PluginPackager</a></li>
262 <li><a href="../../MCollective/PluginPackager/AgentDefinition.html">MCollective::PluginPackager::AgentDefinition</a></li>
264 <li><a href="../../MCollective/PluginPackager/StandardDefinition.html">MCollective::PluginPackager::StandardDefinition</a></li>
266 <li><a href="../../MCollective/RPC.html">MCollective::RPC</a></li>
268 <li><a href="../../MCollective/RPC/ActionRunner.html">MCollective::RPC::ActionRunner</a></li>
270 <li><a href="../../MCollective/RPC/Agent.html">MCollective::RPC::Agent</a></li>
272 <li><a href="../../MCollective/RPC/Audit.html">MCollective::RPC::Audit</a></li>
274 <li><a href="../../MCollective/RPC/Client.html">MCollective::RPC::Client</a></li>
276 <li><a href="../../MCollective/RPC/Helpers.html">MCollective::RPC::Helpers</a></li>
278 <li><a href="../../MCollective/RPC/Progress.html">MCollective::RPC::Progress</a></li>
280 <li><a href="../../MCollective/RPC/Reply.html">MCollective::RPC::Reply</a></li>
282 <li><a href="../../MCollective/RPC/Request.html">MCollective::RPC::Request</a></li>
284 <li><a href="../../MCollective/RPC/Result.html">MCollective::RPC::Result</a></li>
286 <li><a href="../../MCollective/RPC/Stats.html">MCollective::RPC::Stats</a></li>
288 <li><a href="../../MCollective/RPCAborted.html">MCollective::RPCAborted</a></li>
290 <li><a href="../../MCollective/RPCError.html">MCollective::RPCError</a></li>
292 <li><a href="../../MCollective/Registration.html">MCollective::Registration</a></li>
294 <li><a href="../../MCollective/Registration/Base.html">MCollective::Registration::Base</a></li>
296 <li><a href="../../MCollective/Runner.html">MCollective::Runner</a></li>
298 <li><a href="../../MCollective/RunnerStats.html">MCollective::RunnerStats</a></li>
300 <li><a href="../../MCollective/SSL.html">MCollective::SSL</a></li>
302 <li><a href="../../MCollective/Security.html">MCollective::Security</a></li>
304 <li><a href="../../MCollective/Security/Base.html">MCollective::Security::Base</a></li>
306 <li><a href="../../MCollective/SecurityValidationFailed.html">MCollective::SecurityValidationFailed</a></li>
308 <li><a href="../../MCollective/Shell.html">MCollective::Shell</a></li>
310 <li><a href="../../MCollective/Translatable.html">MCollective::Translatable</a></li>
312 <li><a href="../../MCollective/UnixDaemon.html">MCollective::UnixDaemon</a></li>
314 <li><a href="../../MCollective/UnknownRPCAction.html">MCollective::UnknownRPCAction</a></li>
316 <li><a href="../../MCollective/UnknownRPCError.html">MCollective::UnknownRPCError</a></li>
318 <li><a href="../../MCollective/Util.html">MCollective::Util</a></li>
320 <li><a href="../../MCollective/Validator.html">MCollective::Validator</a></li>
322 <li><a href="../../MCollective/ValidatorError.html">MCollective::ValidatorError</a></li>
324 <li><a href="../../MCollective/WindowsDaemon.html">MCollective::WindowsDaemon</a></li>
326 <li><a href="../../Array.html">Array</a></li>
328 <li><a href="../../Dir.html">Dir</a></li>
330 <li><a href="../../Object.html">Object</a></li>
332 <li><a href="../../String.html">String</a></li>
334 <li><a href="../../Symbol.html">Symbol</a></li>
337 <div id="no-class-search-results" style="display: none;">No matching classes.</div>
344 <div id="documentation">
345 <h1 class="class">MCollective::RPC::ActionRunner</h1>
347 <div id="description">
349 A helper used by <a href="Agent.html#M000415">RPC::Agent#implemented_by</a>
350 to delegate an action to an external script. At present only JSON based
351 serialization is supported in future ones based on key=val pairs etc will
355 It serializes the request object into an input file and creates an empty
356 output file. It then calls the external command reading the output file at
360 any STDERR gets logged at error level and any STDOUT gets logged at info
364 It will interpret the exit code from the application the same way <a
365 href="Reply.html#M000386">RPC::Reply#fail!</a> and fail handles their codes
366 creating a consistent interface, the message part of the fail message will
370 Generally externals should just exit with code 1 on failure and print to
371 STDERR, this is exactly what Perl die() does and translates perfectly to
375 It uses the <a href="../Shell.html">MCollective::Shell</a> wrapper to call
376 the external application
386 <div id="attribute-method-details" class="method-section section">
387 <h3 class="section-header">Attributes</h3>
390 <div id="command-attribute-method" class="method-detail">
391 <a name="command"></a>
393 <div class="method-heading attribute-method-heading">
394 <span class="method-name">command</span><span
395 class="attribute-access-type">[R]</span>
398 <div class="method-description">
400 <p class="missing-docs">(Not documented)</p>
405 <div id="agent-attribute-method" class="method-detail">
408 <div class="method-heading attribute-method-heading">
409 <span class="method-name">agent</span><span
410 class="attribute-access-type">[R]</span>
413 <div class="method-description">
415 <p class="missing-docs">(Not documented)</p>
420 <div id="action-attribute-method" class="method-detail">
421 <a name="action"></a>
423 <div class="method-heading attribute-method-heading">
424 <span class="method-name">action</span><span
425 class="attribute-access-type">[R]</span>
428 <div class="method-description">
430 <p class="missing-docs">(Not documented)</p>
435 <div id="format-attribute-method" class="method-detail">
436 <a name="format"></a>
438 <div class="method-heading attribute-method-heading">
439 <span class="method-name">format</span><span
440 class="attribute-access-type">[R]</span>
443 <div class="method-description">
445 <p class="missing-docs">(Not documented)</p>
450 <div id="stdout-attribute-method" class="method-detail">
451 <a name="stdout"></a>
453 <div class="method-heading attribute-method-heading">
454 <span class="method-name">stdout</span><span
455 class="attribute-access-type">[R]</span>
458 <div class="method-description">
460 <p class="missing-docs">(Not documented)</p>
465 <div id="stderr-attribute-method" class="method-detail">
466 <a name="stderr"></a>
468 <div class="method-heading attribute-method-heading">
469 <span class="method-name">stderr</span><span
470 class="attribute-access-type">[R]</span>
473 <div class="method-description">
475 <p class="missing-docs">(Not documented)</p>
480 <div id="request-attribute-method" class="method-detail">
481 <a name="request"></a>
483 <div class="method-heading attribute-method-heading">
484 <span class="method-name">request</span><span
485 class="attribute-access-type">[R]</span>
488 <div class="method-description">
490 <p class="missing-docs">(Not documented)</p>
500 <div id="public-class-method-details" class="method-section section">
501 <h3 class="section-header">Public Class Methods</h3>
504 <div id="new-method" class="method-detail ">
505 <a name="M000372"></a>
507 <div class="method-heading">
509 <span class="method-name">new</span><span
510 class="method-args">(command, request, format=:json)</span>
511 <span class="method-click-advice">click to toggle source</span>
515 <div class="method-description">
517 <p class="missing-docs">(Not documented)</p>
521 <div class="method-source-code"
524 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 26</span>
525 26: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">command</span>, <span class="ruby-identifier">request</span>, <span class="ruby-identifier">format</span>=<span class="ruby-identifier">:json</span>)
526 27: <span class="ruby-ivar">@agent</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">agent</span>
527 28: <span class="ruby-ivar">@action</span> = <span class="ruby-identifier">request</span>.<span class="ruby-identifier">action</span>
528 29: <span class="ruby-ivar">@format</span> = <span class="ruby-identifier">format</span>
529 30: <span class="ruby-ivar">@request</span> = <span class="ruby-identifier">request</span>
530 31: <span class="ruby-ivar">@command</span> = <span class="ruby-identifier">path_to_command</span>(<span class="ruby-identifier">command</span>)
531 32: <span class="ruby-ivar">@stdout</span> = <span class="ruby-value str">""</span>
532 33: <span class="ruby-ivar">@stderr</span> = <span class="ruby-value str">""</span>
533 34: <span class="ruby-keyword kw">end</span></pre>
544 <div id="public-instance-method-details" class="method-section section">
545 <h3 class="section-header">Public Instance Methods</h3>
548 <div id="canrun--method" class="method-detail ">
549 <a name="M000379"></a>
551 <div class="method-heading">
553 <span class="method-name">canrun?</span><span
554 class="method-args">(command)</span>
555 <span class="method-click-advice">click to toggle source</span>
559 <div class="method-description">
561 <p class="missing-docs">(Not documented)</p>
565 <div class="method-source-code"
568 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 117</span>
569 117: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">canrun?</span>(<span class="ruby-identifier">command</span>)
570 118: <span class="ruby-constant">File</span>.<span class="ruby-identifier">executable?</span>(<span class="ruby-identifier">command</span>)
571 119: <span class="ruby-keyword kw">end</span></pre>
580 <div id="load-json-results-method" class="method-detail ">
581 <a name="M000376"></a>
583 <div class="method-heading">
585 <span class="method-name">load_json_results</span><span
586 class="method-args">(file)</span>
587 <span class="method-click-advice">click to toggle source</span>
591 <div class="method-description">
593 <p class="missing-docs">(Not documented)</p>
597 <div class="method-source-code"
598 id="load-json-results-source">
600 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 91</span>
601 91: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_json_results</span>(<span class="ruby-identifier">file</span>)
602 92: <span class="ruby-keyword kw">return</span> {} <span class="ruby-keyword kw">unless</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">readable?</span>(<span class="ruby-identifier">file</span>)
604 94: <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">file</span>)) <span class="ruby-operator">||</span> {}
605 95: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">JSON</span><span class="ruby-operator">::</span><span class="ruby-constant">ParserError</span>
607 97: <span class="ruby-keyword kw">end</span></pre>
616 <div id="load-results-method" class="method-detail ">
617 <a name="M000375"></a>
619 <div class="method-heading">
621 <span class="method-name">load_results</span><span
622 class="method-args">(file)</span>
623 <span class="method-click-advice">click to toggle source</span>
627 <div class="method-description">
629 <p class="missing-docs">(Not documented)</p>
633 <div class="method-source-code"
634 id="load-results-source">
636 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 73</span>
637 73: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_results</span>(<span class="ruby-identifier">file</span>)
638 74: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Attempting to load results in #{format} format from #{file}"</span>)
640 76: <span class="ruby-identifier">data</span> = {}
642 78: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">"load_#{format}_results"</span>)
643 79: <span class="ruby-identifier">tempdata</span> = <span class="ruby-identifier">send</span>(<span class="ruby-node">"load_#{format}_results"</span>, <span class="ruby-identifier">file</span>)
645 81: <span class="ruby-identifier">tempdata</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
646 82: <span class="ruby-identifier">data</span>[<span class="ruby-identifier">k</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">v</span>
647 83: <span class="ruby-keyword kw">end</span>
648 84: <span class="ruby-keyword kw">end</span>
650 86: <span class="ruby-identifier">data</span>
651 87: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
653 89: <span class="ruby-keyword kw">end</span></pre>
662 <div id="path-to-command-method" class="method-detail ">
663 <a name="M000382"></a>
665 <div class="method-heading">
667 <span class="method-name">path_to_command</span><span
668 class="method-args">(command)</span>
669 <span class="method-click-advice">click to toggle source</span>
673 <div class="method-description">
675 <p class="missing-docs">(Not documented)</p>
679 <div class="method-source-code"
680 id="path-to-command-source">
682 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 129</span>
683 129: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">path_to_command</span>(<span class="ruby-identifier">command</span>)
684 130: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">command</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] <span class="ruby-operator">==</span> <span class="ruby-constant">File</span><span class="ruby-operator">::</span><span class="ruby-constant">SEPARATOR</span>
685 131: <span class="ruby-constant">Config</span>.<span class="ruby-identifier">instance</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>
686 132: <span class="ruby-identifier">command_file</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">libdir</span>, <span class="ruby-value str">"agent"</span>, <span class="ruby-identifier">agent</span>, <span class="ruby-identifier">command</span>)
688 134: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">command_file</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">command_file</span>)
689 135: <span class="ruby-keyword kw">end</span>
690 136: <span class="ruby-keyword kw">end</span>
692 138: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">command</span>
693 139: <span class="ruby-keyword kw">end</span></pre>
702 <div id="run-method" class="method-detail ">
703 <a name="M000373"></a>
705 <div class="method-heading">
707 <span class="method-name">run</span><span
708 class="method-args">()</span>
709 <span class="method-click-advice">click to toggle source</span>
713 <div class="method-description">
715 <p class="missing-docs">(Not documented)</p>
719 <div class="method-source-code"
722 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 36</span>
723 36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">run</span>
724 37: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">canrun?</span>(<span class="ruby-identifier">command</span>)
725 38: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-node">"Cannot run #{to_s}"</span>)
726 39: <span class="ruby-identifier">raise</span> <span class="ruby-constant">RPCAborted</span>, <span class="ruby-node">"Cannot execute #{to_s}"</span>
727 40: <span class="ruby-keyword kw">end</span>
729 42: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Running #{to_s}"</span>)
731 44: <span class="ruby-identifier">request_file</span> = <span class="ruby-identifier">saverequest</span>(<span class="ruby-identifier">request</span>)
732 45: <span class="ruby-identifier">reply_file</span> = <span class="ruby-identifier">tempfile</span>(<span class="ruby-value str">"reply"</span>)
733 46: <span class="ruby-identifier">reply_file</span>.<span class="ruby-identifier">close</span>
735 48: <span class="ruby-identifier">runner</span> = <span class="ruby-identifier">shell</span>(<span class="ruby-identifier">command</span>, <span class="ruby-identifier">request_file</span>.<span class="ruby-identifier">path</span>, <span class="ruby-identifier">reply_file</span>.<span class="ruby-identifier">path</span>)
737 50: <span class="ruby-identifier">runner</span>.<span class="ruby-identifier">runcommand</span>
739 52: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"#{command} exited with #{runner.status.exitstatus}"</span>)
741 54: <span class="ruby-identifier">stderr</span>.<span class="ruby-identifier">each_line</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-constant">Log</span>.<span class="ruby-identifier">error</span>(<span class="ruby-node">"#{to_s}: #{l.chomp}"</span>)} <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">stderr</span>.<span class="ruby-identifier">empty?</span>
742 55: <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">each_line</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">l</span><span class="ruby-operator">|</span> <span class="ruby-constant">Log</span>.<span class="ruby-identifier">info</span>(<span class="ruby-node">"#{to_s}: #{l.chomp}"</span>)} <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">stdout</span>.<span class="ruby-identifier">empty?</span>
744 57: {<span class="ruby-identifier">:exitstatus</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">runner</span>.<span class="ruby-identifier">status</span>.<span class="ruby-identifier">exitstatus</span>,
745 58: <span class="ruby-identifier">:stdout</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">runner</span>.<span class="ruby-identifier">stdout</span>,
746 59: <span class="ruby-identifier">:stderr</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">runner</span>.<span class="ruby-identifier">stderr</span>,
747 60: <span class="ruby-identifier">:data</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">load_results</span>(<span class="ruby-identifier">reply_file</span>.<span class="ruby-identifier">path</span>)}
748 61: <span class="ruby-keyword kw">ensure</span>
749 62: <span class="ruby-identifier">request_file</span>.<span class="ruby-identifier">close!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">request_file</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">"close!"</span>)
750 63: <span class="ruby-identifier">reply_file</span>.<span class="ruby-identifier">close!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">reply_file</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value str">"close"</span>)
751 64: <span class="ruby-keyword kw">end</span></pre>
760 <div id="save-json-request-method" class="method-detail ">
761 <a name="M000378"></a>
763 <div class="method-heading">
765 <span class="method-name">save_json_request</span><span
766 class="method-args">(req)</span>
767 <span class="method-click-advice">click to toggle source</span>
771 <div class="method-description">
773 <p class="missing-docs">(Not documented)</p>
777 <div class="method-source-code"
778 id="save-json-request-source">
780 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 113</span>
781 113: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_json_request</span>(<span class="ruby-identifier">req</span>)
782 114: <span class="ruby-identifier">req</span>.<span class="ruby-identifier">to_json</span>
783 115: <span class="ruby-keyword kw">end</span></pre>
792 <div id="saverequest-method" class="method-detail ">
793 <a name="M000377"></a>
795 <div class="method-heading">
797 <span class="method-name">saverequest</span><span
798 class="method-args">(req)</span>
799 <span class="method-click-advice">click to toggle source</span>
803 <div class="method-description">
805 <p class="missing-docs">(Not documented)</p>
809 <div class="method-source-code"
810 id="saverequest-source">
812 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 99</span>
813 99: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">saverequest</span>(<span class="ruby-identifier">req</span>)
814 100: <span class="ruby-constant">Log</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-node">"Attempting to save request in #{format} format"</span>)
816 102: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">respond_to?</span>(<span class="ruby-node">"save_#{format}_request"</span>)
817 103: <span class="ruby-identifier">data</span> = <span class="ruby-identifier">send</span>(<span class="ruby-node">"save_#{format}_request"</span>, <span class="ruby-identifier">req</span>)
819 105: <span class="ruby-identifier">request_file</span> = <span class="ruby-identifier">tempfile</span>(<span class="ruby-value str">"request"</span>)
820 106: <span class="ruby-identifier">request_file</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">data</span>
821 107: <span class="ruby-identifier">request_file</span>.<span class="ruby-identifier">close</span>
822 108: <span class="ruby-keyword kw">end</span>
824 110: <span class="ruby-identifier">request_file</span>
825 111: <span class="ruby-keyword kw">end</span></pre>
834 <div id="shell-method" class="method-detail ">
835 <a name="M000374"></a>
837 <div class="method-heading">
839 <span class="method-name">shell</span><span
840 class="method-args">(command, infile, outfile)</span>
841 <span class="method-click-advice">click to toggle source</span>
845 <div class="method-description">
847 <p class="missing-docs">(Not documented)</p>
851 <div class="method-source-code"
854 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 66</span>
855 66: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shell</span>(<span class="ruby-identifier">command</span>, <span class="ruby-identifier">infile</span>, <span class="ruby-identifier">outfile</span>)
856 67: <span class="ruby-identifier">env</span> = {<span class="ruby-value str">"MCOLLECTIVE_REQUEST_FILE"</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">infile</span>,
857 68: <span class="ruby-value str">"MCOLLECTIVE_REPLY_FILE"</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">outfile</span>}
859 70: <span class="ruby-constant">Shell</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"#{command} #{infile} #{outfile}"</span>, <span class="ruby-identifier">:cwd</span> =<span class="ruby-operator">></span> <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">tmpdir</span>, <span class="ruby-identifier">:stdout</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">stdout</span>, <span class="ruby-identifier">:stderr</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">stderr</span>, <span class="ruby-identifier">:environment</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">env</span>)
860 71: <span class="ruby-keyword kw">end</span></pre>
869 <div id="tempfile-method" class="method-detail ">
870 <a name="M000381"></a>
872 <div class="method-heading">
874 <span class="method-name">tempfile</span><span
875 class="method-args">(prefix)</span>
876 <span class="method-click-advice">click to toggle source</span>
880 <div class="method-description">
882 <p class="missing-docs">(Not documented)</p>
886 <div class="method-source-code"
887 id="tempfile-source">
889 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 125</span>
890 125: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">tempfile</span>(<span class="ruby-identifier">prefix</span>)
891 126: <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">"mcollective_#{prefix}"</span>, <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">tmpdir</span>)
892 127: <span class="ruby-keyword kw">end</span></pre>
901 <div id="to-s-method" class="method-detail ">
902 <a name="M000380"></a>
904 <div class="method-heading">
906 <span class="method-name">to_s</span><span
907 class="method-args">()</span>
908 <span class="method-click-advice">click to toggle source</span>
912 <div class="method-description">
914 <p class="missing-docs">(Not documented)</p>
918 <div class="method-source-code"
921 <span class="ruby-comment cmt"># File lib/mcollective/rpc/actionrunner.rb, line 121</span>
922 121: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_s</span>
923 122: <span class="ruby-value str">"%s#%s command: %s"</span> <span class="ruby-operator">%</span> [ <span class="ruby-identifier">agent</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">command</span> ]
924 123: <span class="ruby-keyword kw">end</span></pre>
939 <div id="rdoc-debugging-section-dump" class="debugging-section">
941 <p>Disabled; run with --debug to generate this.</p>
945 <div id="validator-badges">
946 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
947 <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
948 Rdoc Generator</a> 1.1.6</small>.</p>