Skip to content

Commit c4ddd4f

Browse files
committed
Add dw_virtual_warehouse_info module
Signed-off-by: Webster Mudge <wmudge@cloudera.com>
1 parent 389bb79 commit c4ddd4f

File tree

3 files changed

+241
-0
lines changed

3 files changed

+241
-0
lines changed

docsrc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ cloudera.cloud Ansible Collection
2222
dw_database_catalog <dw_database_catalog>
2323
dw_database_catalog_info <dw_database_catalog_info>
2424
dw_virtual_warehouse <dw_virtual_warehouse>
25+
dw_virtual_warehouse_info <dw_virtual_warehouse_info>
2526
env <env>
2627
env_auth <env_auth>
2728
env_auth_info <env_auth_info>

plugins/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ modules employ the underlying SDK contained within the `cdpy` Python package.
2323
| [dw_database_catalog](./modules/dw_database_catalog.py) | Create, manage, and destroy CDP Data Warehouse Data Catalogs |
2424
| [dw_database_catalog_info](./modules/dw_database_catalog_info.py) | Gather information about CDP Data Warehouse Data Catalogs |
2525
| [dw_virtual_warehouse](./modules/dw_virtual_warehouse.py) | Create, manage, and destroy CDP Data Warehouse Virtual Warehouses |
26+
| [dw_virtual_warehouse_info](./modules/dw_virtual_warehouse_info.py) | Gather information about CDP Data Warehouse Virtual Warehouses |
2627
| [env](./modules/env.py) | Create, manage, and destroy CDP Environments |
2728
| [env_auth](./modules/env_auth.py) | Set authentication details for CDP Environments |
2829
| [env_auth_info](./modules/env_auth_info.py) | Gather information about CDP Environment authentication details |
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
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_virtual_warehouse_info
28+
short_description: Gather information about CDP Data Warehouse Virtual Warehouses
29+
description:
30+
- Gather information about CDP Virtual Warehouses
31+
author:
32+
- "Webster Mudge (@wmudge)"
33+
- "Dan Chaffelson (@chaffelson)"
34+
- "Saravanan Raju (@raju-saravanan)"
35+
requirements:
36+
- cdpy
37+
options:
38+
id:
39+
description:
40+
- The identifier of the Virtual Warehouse.
41+
- Requires I(cluster_id).
42+
- Mutually exclusive with I(name) and I(dbc_id).
43+
type: str
44+
aliases:
45+
- vw_id
46+
cluster_id:
47+
description:
48+
- The identifier of the parent Data Warehouse Cluster of the Virtual Warehouse(s).
49+
type: str
50+
dbc_id:
51+
description:
52+
- The identifier of the parent Database Catalog attached to the Virtual Warehouse(s).
53+
- Requires I(cluster_id).
54+
- Mutally exclusive with I(id) and I(name).
55+
type: str
56+
name:
57+
description:
58+
- The name of the Virtual Warehouse.
59+
- Requires I(cluster_id).
60+
- Mutually exclusive with I(id) and I(dbc_id).
61+
type: str
62+
delay:
63+
description:
64+
- The internal polling interval (in seconds) while the module waits for the Virtual Warehouse to achieve the declared
65+
state.
66+
type: int
67+
default: 15
68+
aliases:
69+
- polling_delay
70+
timeout:
71+
description:
72+
- The internal polling timeout (in seconds) while the module waits for the Virtual Warehouse to achieve the declared
73+
state.
74+
type: int
75+
default: 3600
76+
aliases:
77+
- polling_timeout
78+
extends_documentation_fragment:
79+
- cloudera.cloud.cdp_sdk_options
80+
- cloudera.cloud.cdp_auth_options
81+
'''
82+
83+
EXAMPLES = r'''
84+
# Note: These examples do not set authentication details.
85+
86+
# List all Virtual Warehouses in a Cluster
87+
- cloudera.cloud.dw_virtual_warehouse_info:
88+
cluster_id: example-cluster-id
89+
90+
# List all Virtual Warehouses associated with a Data Catalog
91+
- cloudera.cloud.dw_virtual_warehouse_info:
92+
cluster_id: example-cluster-id
93+
dbc_id: example-data-catalog-id
94+
95+
# Describe a Virtual Warehouse by ID
96+
- cloudera.cloud.dw_virtual_warehouse_info:
97+
cluster_id: example-cluster-id
98+
id: example-virtual-warehouse-id
99+
100+
# Describe a Virtual Warehouse by name
101+
- cloudera.cloud.dw_virtual_warehouse_info:
102+
cluster_id: example-cluster-id
103+
name: example-virtual-warehouse
104+
'''
105+
106+
RETURN = r'''
107+
---
108+
virtual_warehouses:
109+
description: The details about the CDP Data Warehouse Virtual Warehouse(s).
110+
type: list
111+
elements: dict
112+
contains:
113+
id:
114+
description: The identifier of the Virtual Warehouse.
115+
returned: always
116+
type: str
117+
name:
118+
description: The name of the Virtual Warehouse.
119+
returned: always
120+
type: str
121+
vwType:
122+
description: The Virtual Warehouse type.
123+
returned: always
124+
type: str
125+
dbcId:
126+
description: The Database Catalog ID associated with the Virtual Warehouse.
127+
returned: always
128+
type: str
129+
creationDate:
130+
description: The creation time of the Virtual Warehouse in UTC.
131+
returned: always
132+
type: str
133+
status:
134+
description: The status of the Virtual Warehouse.
135+
returned: always
136+
type: str
137+
creator:
138+
description: Details about the Virtual Warehouse creator.
139+
returned: always
140+
type: dict
141+
suboptions:
142+
crn:
143+
description: The creator's Actor CRN.
144+
type: str
145+
returned: always
146+
email:
147+
description: Email address (for users).
148+
type: str
149+
returned: when supported
150+
workloadUsername:
151+
description: Username (for users).
152+
type: str
153+
returned: when supported
154+
machineUsername:
155+
description: Username (for machine users).
156+
type: str
157+
returned: when supported
158+
tags:
159+
description: Custom tags applied to the Virtual Warehouse.
160+
returned: always
161+
type: dict
162+
sdk_out:
163+
description: Returns the captured CDP SDK log.
164+
returned: when supported
165+
type: str
166+
sdk_out_lines:
167+
description: Returns a list of each line of the captured CDP SDK log.
168+
returned: when supported
169+
type: list
170+
elements: str
171+
'''
172+
173+
174+
class DwVwInfo(CdpModule):
175+
def __init__(self, module):
176+
super(DwVwInfo, self).__init__(module)
177+
178+
# Set variables
179+
self.id = self._get_param('id')
180+
self.cluster_id = self._get_param('cluster_id')
181+
self.dbc_id = self._get_param('dbc_id')
182+
self.type = self._get_param('type')
183+
self.name = self._get_param('name')
184+
self.delay = self._get_param('delay')
185+
self.timeout = self._get_param('timeout')
186+
187+
# Initialize return values
188+
self.virtual_warehouses = []
189+
190+
# Execute logic process
191+
self.process()
192+
193+
@CdpModule._Decorators.process_debug
194+
def process(self):
195+
if self.id is not None:
196+
target = self.cdpy.dw.describe_vw(cluster_id=self.cluster_id, vw_id=self.id)
197+
if target is not None:
198+
self.virtual_warehouses.append(target)
199+
else:
200+
vws = self.cdpy.dw.list_vws(cluster_id=self.cluster_id)
201+
if self.name is not None:
202+
for vw in vws:
203+
if vw['name'] == self.name:
204+
self.virtual_warehouses.append(
205+
self.cdpy.dw.describe_vw(cluster_id=self.cluster_id, vw_id=vw['id'])
206+
)
207+
elif self.dbc_id is not None:
208+
self.virtual_warehouses =[v for v in vws if v['dbcId'] == self.dbc_id]
209+
else:
210+
self.virtual_warehouses = vws
211+
212+
213+
def main():
214+
module = AnsibleModule(
215+
argument_spec=CdpModule.argument_spec(
216+
id=dict(type='str', aliases=['vw_id']),
217+
cluster_id=dict(required=True, type='str'),
218+
dbc_id=dict(type='str'),
219+
name=dict(type='str'),
220+
delay=dict(type='int', aliases=['polling_delay'], default=15),
221+
timeout=dict(type='int', aliases=['polling_timeout'], default=3600)
222+
),
223+
mutually_exclusive=[
224+
['id', 'name', 'dbc_id']
225+
],
226+
supports_check_mode=True
227+
)
228+
229+
result = DwVwInfo(module)
230+
output = dict(changed=False, virtual_warehouses=result.virtual_warehouses)
231+
232+
if result.debug:
233+
output.update(sdk_out=result.log_out, sdk_out_lines=result.log_lines)
234+
235+
module.exit_json(**output)
236+
237+
238+
if __name__ == '__main__':
239+
main()

0 commit comments

Comments
 (0)