Skip to content
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
53 changes: 32 additions & 21 deletions plugins/module_utils/host_template_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,37 @@
A common functions for Cloudera Manager host templates
"""

HOST_TEMPLATE_OUTPUT = ["name", "cluster_ref", "role_config_group_refs"]


def _parse_host_template_output(host_template: dict) -> dict:
result = _parse_output(host_template, HOST_TEMPLATE_OUTPUT)
result["cluster_name"] = result["cluster_ref"]["cluster_name"]
result["role_groups"] = [
role["role_config_group_name"] for role in result["role_config_group_refs"]
]
del result["cluster_ref"]
del result["role_config_group_refs"]
return result


def _parse_host_templates_output(host_templates: list) -> list:
parsed_templates = [template.to_dict() for template in host_templates]
return [
_parse_host_template_output(template_dict) for template_dict in parsed_templates
from cm_client import (
ApiClusterRef,
ApiHostTemplate,
ApiRoleConfigGroup,
ApiRoleConfigGroupRef,
)


def parse_host_template(host_template: ApiHostTemplate) -> dict:
return dict(
name=host_template.name,
cluster_name=host_template.cluster_ref.cluster_name,
role_config_groups=[
rcg_ref.role_config_group_name
for rcg_ref in host_template.role_config_group_refs
],
)


def create_host_template_model(
cluster_name: str,
name: str,
role_config_groups: list[ApiRoleConfigGroup],
) -> ApiHostTemplate:

rcg_refs = [
ApiRoleConfigGroupRef(role_config_group_name=r.name) for r in role_config_groups
]


def _parse_output(host_template: dict, keys: list) -> dict:
return {key: host_template[key] for key in keys if key in host_template}
return ApiHostTemplate(
name=name,
cluster_ref=ApiClusterRef(cluster_name=cluster_name),
role_config_group_refs=rcg_refs,
)
7 changes: 4 additions & 3 deletions plugins/module_utils/role_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.common.text.converters import to_native
"""
A common functions for Cloudera Manager roles
"""

from ansible_collections.cloudera.cluster.plugins.module_utils.cm_utils import (
normalize_output,
Expand All @@ -29,6 +30,7 @@
ApiConfig,
ApiConfigList,
ApiEntityTag,
ApiRole,
ApiRoleList,
ApiRoleConfigGroupRef,
ApiRoleNameList,
Expand All @@ -39,7 +41,6 @@
RolesResourceApi,
MgmtRolesResourceApi,
)
from cm_client import ApiRole


class RoleException(Exception):
Expand Down
Loading
Loading