Skip to content

Commit afa865c

Browse files
[Documentation][zos_operator] Add and standarize docstrings on modules/zos_operator.py (#1361)
* Add and standarize docstrings on modules/zos_operator.py * Create changelog fragment * Correct changelog fragment * Modified the google style to numpy * Modify google style to numpy --------- Co-authored-by: Fernando Flores <[email protected]>
1 parent f60dbb8 commit afa865c

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- zos_operator - Updated docstrings to numpy style for visual aid to developers.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1361).

plugins/modules/zos_operator.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,25 @@
178178

179179

180180
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+
"""
182200
# as of ZOAU v1.3.0, timeout is measured in centiseconds, therefore:
183201
timeout_c = 100 * timeout_s
184202

@@ -193,6 +211,19 @@ def execute_command(operator_cmd, timeout_s=1, *args, **kwargs):
193211

194212

195213
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+
"""
196227
module_args = dict(
197228
cmd=dict(type="str", required=True),
198229
verbose=dict(type="bool", required=False, default=False),
@@ -267,6 +298,18 @@ def run_module():
267298

268299

269300
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+
"""
270313
arg_defs = dict(
271314
cmd=dict(arg_type="str", required=True),
272315
verbose=dict(arg_type="bool", required=False),
@@ -278,6 +321,19 @@ def parse_params(params):
278321

279322

280323
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+
"""
281337
AnsibleModuleHelper(argument_spec={})
282338

283339
kwargs = {}
@@ -317,6 +373,22 @@ class Error(Exception):
317373

318374

319375
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+
"""
320392
def __init__(self, cmd, rc, message):
321393
self.msg = 'An error occurred executing the operator command "{0}", with RC={1} and response "{2}"'.format(
322394
cmd, str(rc), message

0 commit comments

Comments
 (0)