Skip to content

Commit d9c8364

Browse files
Support CDW DBC and VW creation
Signed-off-by: Saravanan Raju <saravanan.footloose@gmail.com>
1 parent f4b7911 commit d9c8364

File tree

3 files changed

+547
-4
lines changed

3 files changed

+547
-4
lines changed

plugins/modules/dw_cluster.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@
4747
aliases:
4848
- environment
4949
- env_crn
50+
overlay:
51+
description: Set it to true to save IP addresses in the VPC by using a private IP address range for Pods in the cluster.
52+
type: bool
53+
required: False
54+
default: False
55+
private_load_balancer:
56+
description: Set up load balancer in private subnets.
57+
type: bool
58+
required: False
59+
default: False
5060
aws_public_subnets:
5161
description: List of zero or more Public AWS Subnet IDs to deploy to
5262
type: list
@@ -131,7 +141,7 @@
131141
elements: complex
132142
contains:
133143
cluster:
134-
tyoe: dict
144+
type: dict
135145
contains:
136146
name:
137147
description: The name of the cluster.
@@ -194,6 +204,7 @@ def __init__(self, module):
194204
self.name = self._get_param('name')
195205
self.env = self._get_param('env')
196206
self.overlay = self._get_param('overlay')
207+
self.private_load_balancer = self._get_param('private_load_balancer')
197208
self.az_subnet = self._get_param('az_subnet')
198209
self.az_enable_az = self._get_param('az_enable_az')
199210
self.aws_public_subnets = self._get_param('aws_public_subnets')
@@ -281,9 +292,9 @@ def process(self):
281292
self.module.fail_json(msg="Could not retrieve CRN for CDP Environment %s" % self.env)
282293
else:
283294
self.name = self.cdpy.dw.create_cluster(
284-
env_crn=env_crn, overlay=self.overlay, aws_public_subnets=self.aws_public_subnets,
285-
aws_private_subnets=self.aws_private_subnets, az_subnet=self.az_subnet,
286-
az_enable_az=self.az_enable_az
295+
env_crn=env_crn, overlay=self.overlay, private_load_balancer=self.private_load_balancer,
296+
aws_public_subnets=self.aws_public_subnets, aws_private_subnets=self.aws_private_subnets,
297+
az_subnet=self.az_subnet, az_enable_az=self.az_enable_az
287298
)
288299
if self.wait:
289300
self.target = self.cdpy.sdk.wait_for_state(
@@ -304,6 +315,7 @@ def main():
304315
name=dict(required=False, type='str', aliases=['id']),
305316
env=dict(required=False, type='str', aliases=['environment', 'env_crn']),
306317
overlay=dict(required=False, type='bool', default=False),
318+
private_load_balancer=dict(required=False, type='bool', default=False),
307319
az_subnet=dict(required=False, type='str', default=None),
308320
az_enable_az=dict(required=False, type='bool', default=None),
309321
aws_public_subnets=dict(required=False, type='list', default=None),

plugins/modules/dw_dbc.py

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# Copyright 2021 Cloudera, Inc. All Rights Reserved.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
from ansible.module_utils.basic import AnsibleModule
19+
from ansible_collections.cloudera.cloud.plugins.module_utils.cdp_common import CdpModule
20+
21+
ANSIBLE_METADATA = {'metadata_version': '1.1',
22+
'status': ['preview'],
23+
'supported_by': 'community'}
24+
25+
DOCUMENTATION = r'''
26+
---
27+
module: dw_dbc
28+
short_description: Create CDP Database Catalog
29+
description:
30+
- Create CDP Database Catalog
31+
author:
32+
- "Webster Mudge (@wmudge)"
33+
- "Dan Chaffelson (@chaffelson)"
34+
requirements:
35+
- cdpy
36+
options:
37+
cluster_id:
38+
description: ID of cluster where Database Catalog should be created.
39+
type: str
40+
required: True
41+
name:
42+
description: Name of the Database Catalog.
43+
type: str
44+
required: True
45+
load_demo_data:
46+
description: Set this to true if you demo data should be loaded into the Database Catalog.
47+
type: str
48+
required: False
49+
wait:
50+
description:
51+
- Flag to enable internal polling to wait for the Data Catalog to achieve the declared state.
52+
- If set to FALSE, the module will return immediately.
53+
type: bool
54+
required: False
55+
default: True
56+
delay:
57+
description:
58+
- The internal polling interval (in seconds) while the module waits for the Data Catalog to achieve the declared
59+
state.
60+
type: int
61+
required: False
62+
default: 15
63+
aliases:
64+
- polling_delay
65+
timeout:
66+
description:
67+
- The internal polling timeout (in seconds) while the module waits for the Data Catalog to achieve the declared
68+
state.
69+
type: int
70+
required: False
71+
default: 3600
72+
aliases:
73+
- polling_timeout
74+
extends_documentation_fragment:
75+
- cloudera.cloud.cdp_sdk_options
76+
- cloudera.cloud.cdp_auth_options
77+
'''
78+
79+
EXAMPLES = r'''
80+
# Note: These examples do not set authentication details.
81+
82+
# Create Database Catalog
83+
- cloudera.cloud.dw_dbc:
84+
name: example-database-catalog
85+
cluster_id: example-cluster-id
86+
'''
87+
88+
RETURN = r'''
89+
---
90+
dbcs:
91+
description: The information about the named Database Catalog.
92+
type: list
93+
returned: always
94+
elements: complex
95+
contains:
96+
id:
97+
description: The id of the Database Catalog.
98+
returned: always
99+
type: str
100+
name:
101+
description: The name of the Database Catalog.
102+
returned: always
103+
type: str
104+
status:
105+
description: The status of the Database Catalog.
106+
returned: always
107+
type: str
108+
sdk_out:
109+
description: Returns the captured CDP SDK log.
110+
returned: when supported
111+
type: str
112+
sdk_out_lines:
113+
description: Returns a list of each line of the captured CDP SDK log.
114+
returned: when supported
115+
type: list
116+
elements: str
117+
'''
118+
119+
120+
class DwDbc(CdpModule):
121+
def __init__(self, module):
122+
super(DwDbc, self).__init__(module)
123+
124+
# Set variables
125+
self.cluster_id = self._get_param('cluster_id')
126+
self.name = self._get_param('name')
127+
self.load_demo_data = self._get_param('load_demo_data')
128+
self.state = self._get_param('state')
129+
self.wait = self._get_param('wait')
130+
self.delay = self._get_param('delay')
131+
self.timeout = self._get_param('timeout')
132+
133+
# Initialize return values
134+
self.dbcs = []
135+
136+
# Execute logic process
137+
self.process()
138+
139+
@CdpModule._Decorators.process_debug
140+
def process(self):
141+
self.name = self.cdpy.dw.create_dbc(cluster_id=self.cluster_id, name=self.name,
142+
load_demo_data=self.load_demo_data)
143+
if self.wait:
144+
self.target = self.cdpy.sdk.wait_for_state(
145+
describe_func=self.cdpy.dw.describe_dbc,
146+
params=dict(cluster_id=self.cluster_id, dbc_id=self.name['dbcId']),
147+
state='Running', delay=self.delay, timeout=self.timeout
148+
)
149+
else:
150+
self.target = self.cdpy.dw.describe_dbc(cluster_id=self.cluster_id, dbc_id=self.name['dbcId'])
151+
self.dbcs.append(self.target)
152+
153+
154+
def main():
155+
module = AnsibleModule(
156+
argument_spec=CdpModule.argument_spec(
157+
cluster_id=dict(required=True, type='str', aliases=['cluster_id']),
158+
name = dict(required=True, type='str', aliases=['name']),
159+
load_demo_data=dict(required=False, type='bool', aliases=['load_demo_data']),
160+
state=dict(required=False, type='str', choices=['present', 'absent'], default='present'),
161+
wait = dict(required=False, type='bool', default=True),
162+
delay = dict(required=False, type='int', aliases=['polling_delay'], default=15),
163+
timeout = dict(required=False, type='int', aliases=['polling_timeout'], default=3600)
164+
),
165+
supports_check_mode=True
166+
)
167+
168+
result = DwDbc(module)
169+
output = dict(changed=False, dbcs=result.dbcs)
170+
171+
if result.debug:
172+
output.update(sdk_out=result.log_out, sdk_out_lines=result.log_lines)
173+
174+
module.exit_json(**output)
175+
176+
177+
if __name__ == '__main__':
178+
main()

0 commit comments

Comments
 (0)