1 <?xml version="1.0" encoding="iso-8859-1"?>
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
8 <title>Module: MCollective::DDL</title>
9 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10 <meta http-equiv="Content-Script-Type" content="text/javascript" />
11 <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12 <script type="text/javascript">
15 function popupCode( url ) {
16 window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
19 function toggleCode( id ) {
20 if ( document.getElementById )
21 elem = document.getElementById( id );
22 else if ( document.all )
23 elem = eval( "document.all." + id );
27 elemStyle = elem.style;
29 if ( elemStyle.display != "block" ) {
30 elemStyle.display = "block"
32 elemStyle.display = "none"
38 // Make codeblocks hidden by default
39 document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
49 <div id="classHeader">
50 <table class="header-table">
51 <tr class="top-aligned-row">
52 <td><strong>Module</strong></td>
53 <td class="class-name-in-header">MCollective::DDL</td>
55 <tr class="top-aligned-row">
56 <td><strong>In:</strong></td>
58 <a href="../../files/lib/mcollective/ddl/discoveryddl_rb.html">
59 lib/mcollective/ddl/discoveryddl.rb
62 <a href="../../files/lib/mcollective/ddl/agentddl_rb.html">
63 lib/mcollective/ddl/agentddl.rb
66 <a href="../../files/lib/mcollective/ddl/validatorddl_rb.html">
67 lib/mcollective/ddl/validatorddl.rb
70 <a href="../../files/lib/mcollective/ddl/base_rb.html">
71 lib/mcollective/ddl/base.rb
74 <a href="../../files/lib/mcollective/ddl/dataddl_rb.html">
75 lib/mcollective/ddl/dataddl.rb
78 <a href="../../files/lib/mcollective/ddl_rb.html">
79 lib/mcollective/ddl.rb
87 <!-- banner header -->
89 <div id="bodyContent">
93 <div id="contextContent">
95 <div id="description">
97 A set of classes that helps create data description language files for
98 plugins. You can define meta data, actions, input and output describing the
99 behavior of your agent or other plugins
102 <a href="DDL.html">DDL</a> files are used for input validation,
103 constructing outputs, producing online help, informing the various display
104 routines and so forth.
107 A sample <a href="DDL.html">DDL</a> for an agent be seen below, you‘d
108 put this in your agent dir as <agent name>.ddl
111 metadata :name => "SimpleRPC Service Agent",
112 :description => "Agent to manage services using the Puppet service provider",
113 :author => "R.I.Pienaar",
114 :license => "GPLv2",
115 :version => "1.1",
116 :url => "http://mcollective-plugins.googlecode.com/",
119 action "status", :description => "Gets the status of a service" do
123 :prompt => "Service Name",
124 :description => "The service to get the status for",
126 :validation => '^[a-zA-Z\-_\d]+$',
127 :optional => true,
131 :description => "The status of service",
132 :display_as => "Service Status"
136 There are now many types of <a href="DDL.html">DDL</a> and ultimately all
137 pugins should have <a href="DDL.html">DDL</a> files. The code is organized
138 so that any plugin type will magically just work - they will be an instane
139 of <a href="DDL/Base.html">Base</a> which has metadata and a few common
143 For plugin types that require more specific behaviors they can just add a
144 class here that inherits from <a href="DDL/Base.html">Base</a> and add
145 their specific behavior.
148 <a href="DDL/Base.html">Base</a> defines a specific behavior for input,
149 output and metadata which we‘d like to keep standard across plugin
150 types so do not completely override the behavior of input. The methods are
151 written that they will gladly store extra content though so you add, do not
152 remove. See the <a href="DDL/AgentDDL.html">AgentDDL</a> class for an
153 example where agents want a :required argument to be always set.
161 <div id="method-list">
162 <h3 class="section-bar">Methods</h3>
164 <div class="name-list">
165 <a href="#M000156">load_and_cache</a>
166 <a href="#M000155">new</a>
167 <a href="#M000157">string_to_boolean</a>
168 <a href="#M000158">string_to_number</a>
169 <a href="#M000159">validation_fail!</a>
180 <div id="class-list">
181 <h3 class="section-bar">Classes and Modules</h3>
183 Class <a href="DDL/AgentDDL.html" class="link">MCollective::DDL::AgentDDL</a><br />
184 Class <a href="DDL/Base.html" class="link">MCollective::DDL::Base</a><br />
185 Class <a href="DDL/DataDDL.html" class="link">MCollective::DDL::DataDDL</a><br />
186 Class <a href="DDL/DiscoveryDDL.html" class="link">MCollective::DDL::DiscoveryDDL</a><br />
187 Class <a href="DDL/ValidatorDDL.html" class="link">MCollective::DDL::ValidatorDDL</a><br />
197 <!-- if method_list -->
199 <h3 class="section-bar">Public Class methods</h3>
201 <div id="method-M000156" class="method-detail">
202 <a name="M000156"></a>
204 <div class="method-heading">
205 <a href="#M000156" class="method-signature">
206 <span class="method-name">load_and_cache</span><span class="method-args">(*args)</span>
210 <div class="method-description">
211 <p><a class="source-toggle" href="#"
212 onclick="toggleCode('M000156-source');return false;">[Source]</a></p>
213 <div class="method-source-code" id="M000156-source">
215 <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 71</span>
216 71: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">load_and_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
217 72: <span class="ruby-constant">Cache</span>.<span class="ruby-identifier">setup</span>(<span class="ruby-identifier">:ddl</span>, <span class="ruby-value">300</span>)
219 74: <span class="ruby-identifier">plugin</span> = <span class="ruby-identifier">args</span>.<span class="ruby-identifier">first</span>
220 75: <span class="ruby-identifier">args</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">></span> <span class="ruby-value">1</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">type</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">1</span>].<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">type</span> = <span class="ruby-value str">"agent"</span>
221 76: <span class="ruby-identifier">path</span> = <span class="ruby-value str">"%s/%s"</span> <span class="ruby-operator">%</span> [<span class="ruby-identifier">type</span>, <span class="ruby-identifier">plugin</span>]
223 78: <span class="ruby-keyword kw">begin</span>
224 79: <span class="ruby-identifier">ddl</span> = <span class="ruby-constant">Cache</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">:ddl</span>, <span class="ruby-identifier">path</span>)
225 80: <span class="ruby-keyword kw">rescue</span>
226 81: <span class="ruby-keyword kw">begin</span>
227 82: <span class="ruby-identifier">klass</span> = <span class="ruby-constant">DDL</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-value str">"%sDDL"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">type</span>.<span class="ruby-identifier">capitalize</span>)
228 83: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span>
229 84: <span class="ruby-identifier">klass</span> = <span class="ruby-constant">Base</span>
230 85: <span class="ruby-keyword kw">end</span>
232 87: <span class="ruby-identifier">ddl</span> = <span class="ruby-constant">Cache</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">:ddl</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>))
233 88: <span class="ruby-keyword kw">end</span>
235 90: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">ddl</span>
236 91: <span class="ruby-keyword kw">end</span>
242 <div id="method-M000155" class="method-detail">
243 <a name="M000155"></a>
245 <div class="method-heading">
246 <a href="#M000155" class="method-signature">
247 <span class="method-name">new</span><span class="method-args">(*args, &blk)</span>
251 <div class="method-description">
253 There used to be only one big nasty <a href="DDL.html">DDL</a> class with a
254 bunch of mashed together behaviors. It‘s been around for ages and we
255 would rather not ask all the users to change their <a
256 href="DDL.html#M000155">DDL.new</a> calls to some other factory method that
257 would have this exact same behavior.
260 So we override the behavior of <a href="DDL.html#M000155">new</a> which is
261 a hugely sucky thing to do but ultimately it‘s what would be least
262 disrupting to code out there today. We did though change <a
263 href="DDL.html">DDL</a> to a module to make it possibly a little less
266 <p><a class="source-toggle" href="#"
267 onclick="toggleCode('M000155-source');return false;">[Source]</a></p>
268 <div class="method-source-code" id="M000155-source">
270 <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 67</span>
271 67: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">&</span><span class="ruby-identifier">blk</span>)
272 68: <span class="ruby-identifier">load_and_cache</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
273 69: <span class="ruby-keyword kw">end</span>
279 <div id="method-M000157" class="method-detail">
280 <a name="M000157"></a>
282 <div class="method-heading">
283 <a href="#M000157" class="method-signature">
284 <span class="method-name">string_to_boolean</span><span class="method-args">(val)</span>
288 <div class="method-description">
290 As we‘re taking arguments on the command line we need a way to input
291 booleans, true on the cli is a string so this method will take the ddl,
292 find all arguments that are supposed to be boolean and if they are the
293 strings "true"/"yes" or
294 "false"/"no" turn them into the matching boolean
296 <p><a class="source-toggle" href="#"
297 onclick="toggleCode('M000157-source');return false;">[Source]</a></p>
298 <div class="method-source-code" id="M000157-source">
300 <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 98</span>
301 98: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">string_to_boolean</span>(<span class="ruby-identifier">val</span>)
302 99: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">if</span> [<span class="ruby-value str">"true"</span>, <span class="ruby-value str">"t"</span>, <span class="ruby-value str">"yes"</span>, <span class="ruby-value str">"y"</span>, <span class="ruby-value str">"1"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">val</span>.<span class="ruby-identifier">downcase</span>)
303 100: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span> <span class="ruby-keyword kw">if</span> [<span class="ruby-value str">"false"</span>, <span class="ruby-value str">"f"</span>, <span class="ruby-value str">"no"</span>, <span class="ruby-value str">"n"</span>, <span class="ruby-value str">"0"</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">val</span>.<span class="ruby-identifier">downcase</span>)
305 102: <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC17</span>, <span class="ruby-value str">"%{value} does not look like a boolean argument"</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:value</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">val</span>)
306 103: <span class="ruby-keyword kw">end</span>
312 <div id="method-M000158" class="method-detail">
313 <a name="M000158"></a>
315 <div class="method-heading">
316 <a href="#M000158" class="method-signature">
317 <span class="method-name">string_to_number</span><span class="method-args">(val)</span>
321 <div class="method-description">
323 a generic string to number function, if a number looks like a float it
324 turns it into a float else an int. This is naive but should be sufficient
325 for numbers typed on the cli in most cases
327 <p><a class="source-toggle" href="#"
328 onclick="toggleCode('M000158-source');return false;">[Source]</a></p>
329 <div class="method-source-code" id="M000158-source">
331 <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 108</span>
332 108: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">string_to_number</span>(<span class="ruby-identifier">val</span>)
333 109: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+\.\d+$/</span>
334 110: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\d+$/</span>
336 112: <span class="ruby-identifier">raise_code</span>(<span class="ruby-identifier">:PLMC16</span>, <span class="ruby-value str">"%{value} does not look like a numeric value"</span>, <span class="ruby-identifier">:debug</span>, <span class="ruby-identifier">:value</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">val</span>)
337 113: <span class="ruby-keyword kw">end</span>
343 <div id="method-M000159" class="method-detail">
344 <a name="M000159"></a>
346 <div class="method-heading">
347 <a href="#M000159" class="method-signature">
348 <span class="method-name">validation_fail!</span><span class="method-args">(code, default, level, args={})</span>
352 <div class="method-description">
354 Various <a href="DDL.html">DDL</a> implementations will validate and raise
355 on error, this is a utility method to correctly setup a <a
356 href="DDLValidationError.html">DDLValidationError</a> exceptions and raise
359 <p><a class="source-toggle" href="#"
360 onclick="toggleCode('M000159-source');return false;">[Source]</a></p>
361 <div class="method-source-code" id="M000159-source">
363 <span class="ruby-comment cmt"># File lib/mcollective/ddl.rb, line 117</span>
364 117: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">validation_fail!</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">level</span>, <span class="ruby-identifier">args</span>={})
365 118: <span class="ruby-identifier">exception</span> = <span class="ruby-constant">DDLValidationError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">code</span>, <span class="ruby-identifier">default</span>, <span class="ruby-identifier">level</span>, <span class="ruby-identifier">args</span>)
366 119: <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">set_backtrace</span> <span class="ruby-identifier">caller</span>
368 121: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">exception</span>
369 122: <span class="ruby-keyword kw">end</span>
382 <div id="validator-badges">
383 <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>