178
178
179
179
180
180
def execute_command (operator_cmd , timeout_s = 1 , * args , ** kwargs ):
181
-
181
+ """
182
+ Executes an operator command.
183
+
184
+ Parameters
185
+ ----------
186
+ operator_cmd : str
187
+ Command to execute.
188
+ timeout : int
189
+ Time until it stops whether it finished or not.
190
+ *args : dict
191
+ Some arguments to pass on.
192
+ **kwargs : dict
193
+ Some other arguments to pass on.
194
+
195
+ Returns
196
+ -------
197
+ tuple(int, str, str, int)
198
+ Return code, standard output, standard error and time elapsed from start to finish.
199
+ """
182
200
# as of ZOAU v1.3.0, timeout is measured in centiseconds, therefore:
183
201
timeout_c = 100 * timeout_s
184
202
@@ -193,6 +211,19 @@ def execute_command(operator_cmd, timeout_s=1, *args, **kwargs):
193
211
194
212
195
213
def run_module ():
214
+ """Initialize the module.
215
+
216
+ Raises
217
+ ------
218
+ fail_json
219
+ An error ocurred while importing ZOAU.
220
+ fail_json
221
+ Expected response to be more than 2 lines.
222
+ fail_json
223
+ A non-zero return code was received.
224
+ fail_json
225
+ An unexpected error occurred.
226
+ """
196
227
module_args = dict (
197
228
cmd = dict (type = "str" , required = True ),
198
229
verbose = dict (type = "bool" , required = False , default = False ),
@@ -267,6 +298,18 @@ def run_module():
267
298
268
299
269
300
def parse_params (params ):
301
+ """Use BetterArgParser to parse the module parameters.
302
+
303
+ Parameters
304
+ ----------
305
+ params : dict
306
+ Parameters to parse.
307
+
308
+ Returns
309
+ -------
310
+ dict
311
+ New parameters.
312
+ """
270
313
arg_defs = dict (
271
314
cmd = dict (arg_type = "str" , required = True ),
272
315
verbose = dict (arg_type = "bool" , required = False ),
@@ -278,6 +321,19 @@ def parse_params(params):
278
321
279
322
280
323
def run_operator_command (params ):
324
+ """Runs operator command based on a given parameters in a dictionary.
325
+
326
+ Parameters
327
+ ----------
328
+ params : dict
329
+ Operator command parameters to pass into the function.
330
+
331
+ Returns
332
+ -------
333
+ dict
334
+ Return code, standard output, standard error, the cmd call
335
+ and time elapsed from beginning to end.
336
+ """
281
337
AnsibleModuleHelper (argument_spec = {})
282
338
283
339
kwargs = {}
@@ -317,6 +373,22 @@ class Error(Exception):
317
373
318
374
319
375
class OperatorCmdError (Error ):
376
+ """Exception raised when an error occurred executing the operator command.
377
+
378
+ Parameters
379
+ ----------
380
+ cmd : str
381
+ Command that failed.
382
+ rc : int
383
+ Return code.
384
+ message : str
385
+ Human readable string describing the exception.
386
+
387
+ Attributes
388
+ ----------
389
+ msg : str
390
+ Human readable string describing the exception.
391
+ """
320
392
def __init__ (self , cmd , rc , message ):
321
393
self .msg = 'An error occurred executing the operator command "{0}", with RC={1} and response "{2}"' .format (
322
394
cmd , str (rc ), message
0 commit comments