Skip to content

Commit

Permalink
Add Requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: rsuplina <[email protected]>
  • Loading branch information
rsuplina committed Jul 29, 2024
1 parent 9a2f126 commit 81e4bc1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
6 changes: 1 addition & 5 deletions plugins/module_utils/data_context_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,5 @@ def _parse_output(data: dict, keys: list) -> dict:
return {key: data[key] for key in keys if key in data}


def _remove_unwanted_fields(data: dict) -> dict:
return _parse_output(data, DATA_CONTEXT_OUTPUT)


def parse_data_context_result(data_contexts: ApiDataContextList) -> list:
return [_remove_unwanted_fields(item) for item in data_contexts.items]
return [_parse_output(item, DATA_CONTEXT_OUTPUT) for item in data_contexts.items]
15 changes: 13 additions & 2 deletions plugins/modules/data_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@
- The name of the data context.
type: str
required: yes
aliases:
- context_name
- data_context_name
cluster:
description:
- The name of the Cloudera Manager cluster.
type: str
required: no
aliases:
- cluster_name
services:
description:
- A list of services that the data context will include.
Expand Down Expand Up @@ -186,10 +191,12 @@ def __init__(self, module):
self.cluster_name = self.get_param("cluster")
self.services = self.get_param("services")
self.state = self.get_param("state")

# Initialize the return value
self.data_context_output = []
self.changed = False
self.diff = {}

# Execute the logic
self.process()

Expand All @@ -212,7 +219,9 @@ def process(self):
data_context_name=self.data_contex_name
).to_dict()
except ApiException as ex:
if ex.status == 500:
if (
ex.status == 500
): # Future change: Expected server response code will be 404
pass
else:
raise ex
Expand Down Expand Up @@ -274,7 +283,9 @@ def process(self):
def main():
module = ClouderaManagerMutableModule.ansible_module(
argument_spec=dict(
name=dict(required=True, type="str"),
name=dict(
required=True, type="str", aliases=["context_name", "data_context_name"]
),
cluster=dict(required=False, type="str", aliases=["cluster_name"]),
services=dict(required=False, type="list"),
state=dict(
Expand Down
15 changes: 9 additions & 6 deletions plugins/modules/data_context_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
- The name of the data context.
type: str
required: no
aliases:
- context_name
- data_context_name
"""

EXAMPLES = r"""
Expand Down Expand Up @@ -154,11 +157,7 @@ def process(self):
ApiDataContextList(items=[data_contex])
)
except ApiException as ex:
if ex.status == 500:
self.module.fail_json(
msg="Data Context does not exist: " + self.data_context_name
)
else:
if ex.status != 500:
raise ex
else:
data_contexts_info = data_context_api.read_data_contexts().to_dict()
Expand All @@ -171,7 +170,11 @@ def process(self):
def main():
module = ClouderaManagerMutableModule.ansible_module(
argument_spec=dict(
name=dict(required=False, type="str"),
name=dict(
required=False,
type="str",
aliases=["context_name", "data_context_name"],
),
),
supports_check_mode=False,
)
Expand Down

0 comments on commit 81e4bc1

Please sign in to comment.