Skip to content

Commit

Permalink
Add add_repositories Parametar
Browse files Browse the repository at this point in the history
Signed-off-by: rsuplina <[email protected]>
  • Loading branch information
rsuplina committed Jan 23, 2024
1 parent c92c313 commit 5ad8f74
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
31 changes: 29 additions & 2 deletions plugins/modules/cm_import_cluster_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
- This module ensures that the cluster is created according to the specified template.
author:
- "Ronald Suplina (@rsuplina)"
options:
template:
description:
- Path to template file which defines the cluster
type: path
elements: str
required: True
add_repositories:
description:
- Install parcel repositories in parcel directory
type: bool
required: False
default: False
requirements:
- cm_client
"""
Expand All @@ -50,6 +63,15 @@
password: "S&peR4Ec*re"
port: "7180"
template: "./files/cluster-template.json"
- name: Create a cluster and install the repositories defined in template
cloudera.cluster.cm_import_cluster_template:
host: example.cloudera.com
username: "jane_smith"
password: "S&peR4Ec*re"
port: "7180"
template: "./files/cluster-template.json"
add_repositories: "True"
"""

RETURN = r"""
Expand Down Expand Up @@ -99,7 +121,7 @@
type: list
returned: optional
uuid:
description: Unique ID of created cluster.
description: Unique ID of created cluster
type: bool
returned: optional
"""
Expand All @@ -109,6 +131,7 @@ class ClusterTemplate(ClouderaManagerModule):
def __init__(self, module):
super(ClusterTemplate, self).__init__(module)
self.template = self.get_param("template")
self.add_repositories = self.get_param("add_repositories")
self.process()

@ClouderaManagerModule.handle_process
Expand All @@ -120,8 +143,11 @@ def process(self):

with open(self.template, 'r') as file:
template_json = json.load(file)
if self.add_repositories:
import_template_request = api_instance.import_cluster_template(add_repositories=True,body=template_json).to_dict()
else:
import_template_request = api_instance.import_cluster_template(body=template_json).to_dict()

import_template_request = api_instance.import_cluster_template(body=template_json).to_dict()
command_id = import_template_request['id']

self.wait_for_command_state(command_id=command_id,polling_interval=60)
Expand All @@ -144,6 +170,7 @@ def main():

argument_spec=dict(
template=dict(required=True, type="path"),
add_repositories=dict(required=False, type="bool", default=False),
),
supports_check_mode=False
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2023 Cloudera, Inc. All Rights Reserved.
# Copyright 2024 Cloudera, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,6 +36,7 @@ def test_pytest_cm_import_cluster_template(module_args):
"verify_tls": "no",
"debug": "no",
"template": "./files/cluster-template.json",
"add_repositories": "True"
}
)

Expand Down

0 comments on commit 5ad8f74

Please sign in to comment.