Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation][zos_gather_facts] Add and standarize docstrings on modules/zos_gather_facts.py #1351

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trivial:
- zos_gather_facts - Updated docstrings to numpy style for visual aid to developers.
(https://github.com/ansible-collections/ibm_zos_core/pull/1351).
67 changes: 50 additions & 17 deletions plugins/modules/zos_gather_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,18 @@
def zinfo_facts_list_builder(gather_subset):
"""Builds a list of strings to pass into 'zinfo' based off the
gather_subset list.
Arguments:
gather_subset {list} -- A list of subsets to pass in.
Returns:
[list[str]] -- A list of strings that contains sanitized subsets.
[None] -- An invalid value was received for the subsets.

Parameters
----------
gather_subset : list
A list of subsets to pass in.

Returns
-------
Union[str]
A list of strings that contains sanitized subsets.
None
An invalid value was received for the subsets.
"""
if gather_subset is None or 'all' in gather_subset:
return ["all"]
Expand All @@ -157,11 +164,17 @@ def zinfo_facts_list_builder(gather_subset):
def flatten_zinfo_json(zinfo_dict):
"""Removes one layer of mapping in the dictionary. Top-level keys
correspond to zinfo subsets and are removed.
Arguments:
zinfo_dict {dict} -- A dictionary that contains the parsed result from
the zinfo json string.
Returns:
[dict] -- A flattened dictionary.

Parameters
----------
zinfo_dict : dict
A dictionary that contains the parsed result from
the zinfo json string.

Returns
-------
dict
A flattened dictionary.
"""
d = {}
for subset in list(zinfo_dict):
Expand All @@ -172,13 +185,20 @@ def flatten_zinfo_json(zinfo_dict):
def apply_filter(zinfo_dict, filter_list):
"""Returns a dictionary that contains only the keys which fit the specified
filters.
Arguments:
zinfo_dict {dict} -- A flattened dictionary that contains results from
zinfo.
filter_list {list} -- A string list of shell wildcard patterns (i.e.
'filters') to apply to the zinfo_dict keys.
Returns:
[dict] -- A dictionary with keys that are filtered out.

Parameters
----------
zinfo_dict : dict
A flattened dictionary that contains results from
zinfo.
filter_list : list
A string list of shell wildcard patterns (i.e.
'filters') to apply to the zinfo_dict keys.

Returns
-------
dict
A dictionary with keys that are filtered out.
"""

if filter_list is None or filter_list == [] or '*' in filter_list:
Expand All @@ -193,6 +213,19 @@ def apply_filter(zinfo_dict, filter_list):


def run_module():
"""Initialize module.

Raises
------
fail_json
The zos_gather_facts module requires ZOAU >= 1.3.0.
fail_json
An invalid subset was passed to Ansible.
fail_json
An invalid subset was detected.
fail_json
An exception has occurred. Unable to gather facts.
"""
# define available arguments/parameters a user can pass to the module
module_args = dict(
gather_subset=dict(
Expand Down